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
.annotation
.Exported
;
13 import java
.lang
.ref
.Reference
;
14 import java
.lang
.ref
.WeakReference
;
15 import java
.util
.Objects
;
18 * This represents an entry point of a JAR.
23 public final class EntryPoint
24 implements Comparable
<EntryPoint
>
26 /** The name of the entry point. */
27 protected final String name
;
29 /** The entry point class. */
30 protected final String entry
;
32 /** The image used. */
33 protected final String imageResource
;
35 /** Is this a midlet? */
36 protected final boolean isMidlet
;
38 /** String representation. */
39 private Reference
<String
> _string
;
42 * Initializes the entry point.
44 * @param __name The name of the entry point.
45 * @param __entry The class used for entry.
46 * @param __imgRc The image resource to use, may be {@code null}.
47 * @param __mid Is this a midlet launch?
48 * @throws NullPointerException On null arguments.
52 public EntryPoint(String __name
, String __entry
, String __imgRc
,
54 throws NullPointerException
57 if (__name
== null || __entry
== null)
58 throw new NullPointerException("NARG");
63 this.isMidlet
= __mid
;
65 // This may include an absolute path, however that can be stripped off
66 this.imageResource
= (__imgRc
== null ?
null :
67 (__imgRc
.startsWith("/") ? __imgRc
.substring(1) : __imgRc
));
75 public int compareTo(EntryPoint __o
)
77 // Do non-midlets first
78 boolean ma
= this.isMidlet
,
87 int rv
= this.name
.compareTo(__o
.name
);
90 return this.entry
.compareTo(__o
.entry
);
94 * Returns the entry point class of the entry point.
96 * @return The entry point class.
100 public String
entryPoint()
110 public boolean equals(Object __o
)
113 if (!(__o
instanceof EntryPoint
))
116 EntryPoint o
= (EntryPoint
)__o
;
117 return this.name
.equals(o
.name
) &&
118 this.entry
.equals(o
.entry
) &&
119 Objects
.equals(this.imageResource
, o
.imageResource
) &&
120 this.isMidlet
== o
.isMidlet
;
128 public int hashCode()
130 String imageResource
= this.imageResource
;
131 return this.name
.hashCode() ^
this.entry
.hashCode() ^
132 (this.isMidlet ?
1 : 0) ^
133 (imageResource
== null ?
0 : imageResource
.hashCode());
137 * Returns the image to use.
139 * @return The image resource or {@code null} if there is none.
143 public String
imageResource()
145 return this.imageResource
;
151 * @return If this is a MIDlet or not.
155 public boolean isMidlet()
157 return this.isMidlet
;
161 * Returns the name of the entry point.
163 * @return The entry point name.
177 public String
toString()
179 Reference
<String
> ref
= this._string
;
183 if (ref
== null || null == (rv
= ref
.get()))
184 this._string
= new WeakReference
<>((rv
= String
.format(
185 "%s (%s: %s)", this.name
, (this.isMidlet ?
"MIDlet" :
186 "Classic"), this.entry
)));