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 an entry point of a JAR.
21 public final class EntryPoint
22 implements Comparable
<EntryPoint
>
24 /** The name of the entry point. */
25 protected final String name
;
27 /** The entry point class. */
28 protected final String entry
;
30 /** The image used. */
31 protected final String imageResource
;
33 /** Is this a midlet? */
34 protected final boolean isMidlet
;
36 /** String representation. */
37 private Reference
<String
> _string
;
40 * Initializes the entry point.
42 * @param __name The name of the entry point.
43 * @param __entry The class used for entry.
44 * @param __imgRc The image resource to use, may be {@code null}.
45 * @param __mid Is this a midlet launch?
46 * @throws NullPointerException On null arguments.
49 public EntryPoint(String __name
, String __entry
, String __imgRc
,
51 throws NullPointerException
54 if (__name
== null || __entry
== null)
55 throw new NullPointerException("NARG");
60 this.isMidlet
= __mid
;
62 // This may include an absolute path, however that can be stripped off
63 this.imageResource
= (__imgRc
== null ?
null :
64 (__imgRc
.startsWith("/") ? __imgRc
.substring(1) :
73 public int compareTo(EntryPoint __o
)
75 // Do non-midlets first
76 boolean ma
= this.isMidlet
,
85 int rv
= this.name
.compareTo(__o
.name
);
88 return this.entry
.compareTo(__o
.entry
);
92 * Returns the entry point class of the entry point.
94 * @return The entry point class.
97 public String
entryPoint()
107 public boolean equals(Object __o
)
110 if (!(__o
instanceof EntryPoint
))
113 EntryPoint o
= (EntryPoint
)__o
;
114 return this.name
.equals(o
.name
) &&
115 this.entry
.equals(o
.entry
) &&
116 Objects
.equals(this.imageResource
, o
.imageResource
) &&
117 this.isMidlet
== o
.isMidlet
;
125 public int hashCode()
127 String imageResource
= this.imageResource
;
128 return this.name
.hashCode() ^
this.entry
.hashCode() ^
129 (this.isMidlet ?
1 : 0) ^
130 (imageResource
== null ?
0 : imageResource
.hashCode());
134 * Returns the image to use.
136 * @return The image resource or {@code null} if there is none.
139 public String
imageResource()
141 return this.imageResource
;
147 * @return If this is a MIDlet or not.
150 public boolean isMidlet()
152 return this.isMidlet
;
156 * Returns the name of the entry point.
158 * @return The entry point name.
171 public String
toString()
173 Reference
<String
> ref
= this._string
;
177 if (ref
== null || null == (rv
= ref
.get()))
178 this._string
= new WeakReference
<>((rv
= String
.format(
179 "%s (%s: %s)", this.name
, (this.isMidlet ?
"MIDlet" :
180 "Classic"), this.entry
)));