Make Exported just be SquirrelJMEVendorApi.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / manifest / JavaManifestKey.java
blob122a131ce9ebb14f07a502e38f0297b617753806
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.manifest;
12 /**
13 * This represents a key which is used in a manifest, it is case insensitive
14 * when it comes to ASCII values.
16 * @since 2016/05/29
18 public final class JavaManifestKey
20 /** The used string. */
21 protected final String string;
23 /** The actual input string. */
24 protected final String inputString;
26 /**
27 * Initializes the manifest key using the given string.
29 * @param __s The string to use for the manifest key.
30 * @throws NullPointerException On null arguments.
31 * @since 2016/05/29
33 public JavaManifestKey(String __s)
34 throws NullPointerException
36 // Check
37 if (__s == null)
38 throw new NullPointerException("NARG");
40 // Lower-case all letters
41 StringBuilder sb = new StringBuilder();
42 for (int i = 0, n = __s.length(); i < n; i++)
43 sb.append(JavaManifestKey.__toLower(__s.charAt(i)));
44 this.string = sb.toString();
46 // Remember input string for case purposes
47 this.inputString = __s;
50 /**
51 * {@inheritDoc}
52 * @since 2016/05/29
54 @Override
55 public boolean equals(Object __o)
57 // Is another key?
58 if (__o instanceof JavaManifestKey)
59 return this.__equals(((JavaManifestKey)__o).string);
60 return false;
63 /**
64 * {@inheritDoc}
65 * @since 2016/05/29
67 @Override
68 public int hashCode()
70 return this.string.hashCode();
73 /**
74 * Returns the input string which was passed to this key, this string
75 * cannot be used for comparative purposes and it intended to be used
76 * for case matching in the output manifest.
78 * @return The input string.
79 * @since 2017/11/26
81 public String inputString()
83 return this.inputString;
86 /**
87 * {@inheritDoc}
88 * @since 2016/05/29
90 @Override
91 public String toString()
93 return this.string;
96 /**
97 * Compares two strings checking for case insensitivity in the basic
98 * ASCII range.
100 * @param __b The other string to compare against.
101 * @return {@code true} if the strings are equal.
102 * @throws NullPointerException On null arguments.
103 * @since 2016/05/29
105 private boolean __equals(String __b)
106 throws NullPointerException
108 // Check
109 if (__b == null)
110 throw new NullPointerException("NARG");
112 // Cache
113 String a = this.string;
115 // Get their lengths
116 int na = a.length(),
117 nb = __b.length();
119 // Would not be equal
120 if (na != nb)
121 return false;
123 // Check characters
124 for (int i = 0; i < na; i++)
125 if (JavaManifestKey.__toLower(a.charAt(i)) != JavaManifestKey
126 .__toLower(__b.charAt(i)))
127 return false;
129 // Matches
130 return true;
134 * Converts the specified character to lower case.
136 * @param __c The character to lower case.
137 * @return The lowercased character or {@code __c} if it cannot be
138 * lowercased.
139 * @since 2016/05/29
141 private static char __toLower(char __c)
143 if (__c >= 'A' && __c <= 'Z')
144 return (char)('a' + (__c - 'A'));
145 return __c;