1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jvm
.suite
;
12 import cc
.squirreljme
.runtime
.cldc
.util
.StringUtils
;
13 import java
.lang
.ref
.Reference
;
14 import java
.lang
.ref
.WeakReference
;
15 import java
.util
.Objects
;
18 * This represents a configuration such as CLDC which specifies which base
19 * classes are available. Configurations may optionally be "compact" in which
20 * they are a lighter version.
24 public final class Configuration
25 implements Comparable
<Configuration
>, MarkedDependency
, MarkedProvided
28 protected final APIName name
;
31 protected final SuiteVersion version
;
33 /** Is this configuration compact? */
34 protected final boolean compact
;
36 /** String representation. */
37 private Reference
<String
> _string
;
40 * Initializes the configuration using the given API name and version.
42 * @param __n The name to use.
43 * @param __v The version of the suite.
44 * @param __c If {@code true} then the configuration is compact.
45 * @throws NullPointerException On null arguments.
48 public Configuration(APIName __n
, SuiteVersion __v
, boolean __c
)
49 throws NullPointerException
51 if (__n
== null || __v
== null)
52 throw new NullPointerException("NARG");
61 * Initializes the configuration by parsing the given string.
63 * @param __n The string to parse.
64 * @throws NullPointerException On null arguments.
67 public Configuration(String __n
)
68 throws NullPointerException
71 throw new NullPointerException("NARG");
73 // {@squirreljme.error DG02 Expected two or three fields for the
74 // configuration. (The input string)}
75 String
[] fields
= StringUtils
.fieldSplit('-', __n
);
76 int fn
= fields
.length
;
77 if (fn
!= 2 && fn
!= 3)
78 throw new InvalidSuiteException(String
.format("AR02 %s", __n
));
80 // Potentially compact?
81 this.compact
= (fn
> 2 &&
82 0 == fields
[2].compareToIgnoreCase("compact"));
84 // Parse name and version
85 this.name
= new APIName(fields
[0]);
86 this.version
= new SuiteVersion(fields
[1]);
94 public int compareTo(Configuration __o
)
96 int rv
= this.name
.compareTo(__o
.name
);
100 rv
= this.version
.compareTo(__o
.version
);
104 // Compact is before non-compact
105 boolean a
= this.compact
,
117 public boolean equals(Object __o
)
122 if (!(__o
instanceof Configuration
))
125 Configuration o
= (Configuration
)__o
;
126 return this.name
.equals(o
.name
) &&
127 this.version
.equals(o
.version
) &&
128 this.compact
== o
.compact
;
136 public int hashCode()
138 return this.name
.hashCode() ^
139 Objects
.hashCode(this.version
) ^
140 (this.compact ?
0xFFFFFFFF : 0);
148 public boolean isOptional()
158 public boolean matchesProvided(MarkedProvided __mp
)
159 throws NullPointerException
162 throw new NullPointerException("NARG");
164 return this.equals(__mp
);
172 public String
toString()
174 Reference
<String
> ref
= this._string
;
177 if (ref
== null || null == (rv
= ref
.get()))
178 this._string
= new WeakReference
<>((rv
= "Configuration " +
179 this.name
+ ":" + this.version
+
180 (this.compact ?
"-compact" : "")));
186 * Returns the version of this configuration.
188 * @return The configuration version.
191 public SuiteVersion
version()