Offload int[] to byte[].
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / EntryPoints.java
blob7d86e34aa1e62125a0d6d1eb72c47322718157e1
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 cc.squirreljme.jvm.manifest.JavaManifest;
13 import cc.squirreljme.jvm.manifest.JavaManifestAttributes;
14 import cc.squirreljme.jvm.manifest.JavaManifestKey;
15 import java.util.AbstractList;
16 import java.util.ArrayList;
17 import java.util.List;
19 /**
20 * This parses the entry points which are available for usage.
22 * @since 2017/08/20
24 public class EntryPoints
25 extends AbstractList<EntryPoint>
27 /** Available entry points. */
28 private final EntryPoint[] _entrypoints;
30 /**
31 * Initializes the entry points the hosted launcher can find.
33 * @param __man The manifest to parse.
34 * @throws NullPointerException On null arguments.
35 * @since 2018/03/24
37 public EntryPoints(JavaManifest __man)
38 throws NullPointerException
40 this(__man.getMainAttributes());
43 /**
44 * Initializes the entry points the hosted launcher can find.
46 * @param __attr The attributes to parse.
47 * @throws NullPointerException On null arguments.
48 * @since 2017/08/20
50 public EntryPoints(JavaManifestAttributes __attr)
51 throws NullPointerException
53 // Check
54 if (__attr == null)
55 throw new NullPointerException("NARG");
57 // Target list
58 List<EntryPoint> target = new ArrayList<>();
60 // Parse main class first
61 String oldClass = __attr.get(new JavaManifestKey("Main-Class"));
62 if (oldClass != null)
63 target.add(new EntryPoint("Command Line", oldClass,
64 null, false));
66 // Parse MIDlet identifiers next
67 for (int i = 1; i >= 1; i++)
69 // These are always in sequence
70 String midletval = __attr.get(new JavaManifestKey(
71 String.format("MIDlet-%d", i)));
72 if (midletval == null)
73 break;
75 // The MIDlet field is in 3 fields: name, icon, class
76 /* {@squirreljme.error DG03 Expected two commas in the MIDlet
77 field.} */
78 int pc = midletval.indexOf(','),
79 sc = midletval.indexOf(',', Math.max(pc + 1, 0));
80 if (pc < 0 || sc < 0)
81 throw new RuntimeException("DG03");
83 // Split fields
84 String iconRc = midletval.substring(pc + 1, sc).trim();
85 target.add(new EntryPoint(midletval.substring(0, pc).trim(),
86 midletval.substring(sc + 1).trim(),
87 (iconRc.isEmpty() ? null : iconRc), true));
90 // Finalize
91 this._entrypoints = target.<EntryPoint>toArray(
92 new EntryPoint[target.size()]);
95 /**
96 * {@inheritDoc}
97 * @since 2017/08/20
99 @Override
100 public EntryPoint get(int __i)
102 return this._entrypoints[__i];
106 * {@inheritDoc}
107 * @since 2017/08/20
109 @Override
110 public int size()
112 return this._entrypoints.length;