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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jvm
.suite
;
12 import java
.lang
.ref
.Reference
;
13 import java
.lang
.ref
.WeakReference
;
14 import java
.util
.Objects
;
17 * This represents a profile that may be implemented, such as MIDP.
21 public final class Profile
22 implements Comparable
<Profile
>, MarkedDependency
, MarkedProvided
25 protected final APIName name
;
28 protected final SuiteVersion version
;
30 /** String representation. */
31 private Reference
<String
> _string
;
34 * Initializes the profile using the given API name and version.
36 * @param __n The name to use.
37 * @param __v The version of the suite, this is optional.
38 * @throws NullPointerException If no name was specified.
41 public Profile(APIName __n
, SuiteVersion __v
)
42 throws NullPointerException
45 throw new NullPointerException("NARG");
52 * Initializes the profile by parsing the given string.
54 * @param __n The string to parse.
55 * @throws NullPointerException On null arguments.
58 public Profile(String __n
)
59 throws NullPointerException
62 throw new NullPointerException("NARG");
64 // No version specified
66 dx
= __n
.lastIndexOf('-');
68 if (dx
< 0 || dx
+ 1 >= n
|| (c
= __n
.charAt(dx
+ 1)) < '0' || c
> '9')
70 this.name
= new APIName(__n
);
77 this.name
= new APIName(__n
.substring(0, dx
));
78 this.version
= new SuiteVersion(__n
.substring(dx
+ 1));
83 * Returns the API name.
85 * @return The API name.
88 public APIName
apiName()
98 public int compareTo(Profile __o
)
100 int rv
= this.name
.compareTo(__o
.name
);
104 SuiteVersion a
= this.version
,
106 if ((a
== null) != (b
== null))
107 return (a
== null ?
-1 : 1);
109 return a
.compareTo(b
);
118 public boolean equals(Object __o
)
123 if (!(__o
instanceof Profile
))
126 Profile o
= (Profile
)__o
;
127 return this.name
.equals(o
.name
) &&
128 Objects
.equals(this.version
, o
.version
);
136 public int hashCode()
138 return this.name
.hashCode() ^
139 Objects
.hashCode(this.version
);
147 public boolean isOptional()
157 public boolean matchesProvided(MarkedProvided __mp
)
158 throws NullPointerException
161 throw new NullPointerException("NARG");
163 return this.equals(__mp
);
171 public String
toString()
174 Reference
<String
> ref
= this._string
;
177 if (ref
== null || null == (rv
= ref
.get()))
178 this._string
= new WeakReference
<>((rv
= "Profile " +
179 this.name
+ ":" + this.version
));
185 * Returns the version of this profile.
187 * @return The profile version.
190 public SuiteVersion
version()