Make it so mapping files are used and then reapplied.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / EntryPoint.java
blobc9612f3d6cb4273b3d81b40e0969df7270b9f041
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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;
17 /**
18 * This represents an entry point of a JAR.
20 * @since 2017/08/20
22 @Exported
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;
41 /**
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.
49 * @since 2017/08/20
51 @Exported
52 public EntryPoint(String __name, String __entry, String __imgRc,
53 boolean __mid)
54 throws NullPointerException
56 // Check
57 if (__name == null || __entry == null)
58 throw new NullPointerException("NARG");
60 // Set
61 this.name = __name;
62 this.entry = __entry;
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));
70 /**
71 * {@inheritDoc}
72 * @since 2017/08/20
74 @Override
75 public int compareTo(EntryPoint __o)
77 // Do non-midlets first
78 boolean ma = this.isMidlet,
79 mb = __o.isMidlet;
80 if (ma != mb)
81 if (!ma)
82 return -1;
83 else
84 return 1;
86 // Then the rest
87 int rv = this.name.compareTo(__o.name);
88 if (rv != 0)
89 return rv;
90 return this.entry.compareTo(__o.entry);
93 /**
94 * Returns the entry point class of the entry point.
96 * @return The entry point class.
97 * @since 2017/08/20
99 @Exported
100 public String entryPoint()
102 return this.entry;
106 * {@inheritDoc}
107 * @since 2017/08/20
109 @Override
110 public boolean equals(Object __o)
112 // Check
113 if (!(__o instanceof EntryPoint))
114 return false;
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;
124 * {@inheritDoc}
125 * @since 2017/08/20
127 @Override
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.
140 * @since 2020/10/31
142 @Exported
143 public String imageResource()
145 return this.imageResource;
149 * Is this a MIDlet?
151 * @return If this is a MIDlet or not.
152 * @since 2017/08/20
154 @Exported
155 public boolean isMidlet()
157 return this.isMidlet;
161 * Returns the name of the entry point.
163 * @return The entry point name.
164 * @since 2017/08/20
166 @Exported
167 public String name()
169 return this.name;
173 * {@inheritDoc}
174 * @since 2017/08/20
176 @Override
177 public String toString()
179 Reference<String> ref = this._string;
180 String rv;
182 // Cache?
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)));
188 return rv;