Offload int[] to byte[].
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / EntryPoint.java
blobabfd0b32e1bc7903e978534d6a3b780474370f9d
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 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;
16 /**
17 * This represents an entry point of a JAR.
19 * @since 2017/08/20
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;
39 /**
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.
47 * @since 2017/08/20
49 public EntryPoint(String __name, String __entry, String __imgRc,
50 boolean __mid)
51 throws NullPointerException
53 // Check
54 if (__name == null || __entry == null)
55 throw new NullPointerException("NARG");
57 // Set
58 this.name = __name;
59 this.entry = __entry;
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) :
65 __imgRc));
68 /**
69 * {@inheritDoc}
70 * @since 2017/08/20
72 @Override
73 public int compareTo(EntryPoint __o)
75 // Do non-midlets first
76 boolean ma = this.isMidlet,
77 mb = __o.isMidlet;
78 if (ma != mb)
79 if (!ma)
80 return -1;
81 else
82 return 1;
84 // Then the rest
85 int rv = this.name.compareTo(__o.name);
86 if (rv != 0)
87 return rv;
88 return this.entry.compareTo(__o.entry);
91 /**
92 * Returns the entry point class of the entry point.
94 * @return The entry point class.
95 * @since 2017/08/20
97 public String entryPoint()
99 return this.entry;
103 * {@inheritDoc}
104 * @since 2017/08/20
106 @Override
107 public boolean equals(Object __o)
109 // Check
110 if (!(__o instanceof EntryPoint))
111 return false;
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;
121 * {@inheritDoc}
122 * @since 2017/08/20
124 @Override
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.
137 * @since 2020/10/31
139 public String imageResource()
141 return this.imageResource;
145 * Is this a MIDlet?
147 * @return If this is a MIDlet or not.
148 * @since 2017/08/20
150 public boolean isMidlet()
152 return this.isMidlet;
156 * Returns the name of the entry point.
158 * @return The entry point name.
159 * @since 2017/08/20
161 public String name()
163 return this.name;
167 * {@inheritDoc}
168 * @since 2017/08/20
170 @Override
171 public String toString()
173 Reference<String> ref = this._string;
174 String rv;
176 // Cache?
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)));
182 return rv;