Make it so mapping files are used and then reapplied.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / manifest / JavaManifestKey.java
blob330edcafa8b6ede98258cc577f78e68a31282ae7
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 import cc.squirreljme.runtime.cldc.annotation.Exported;
14 /**
15 * This represents a key which is used in a manifest, it is case insensitive
16 * when it comes to ASCII values.
18 * @since 2016/05/29
20 @Exported
21 public final class JavaManifestKey
23 /** The used string. */
24 @Exported
25 protected final String string;
27 /** The actual input string. */
28 @Exported
29 protected final String inputString;
31 /**
32 * Initializes the manifest key using the given string.
34 * @param __s The string to use for the manifest key.
35 * @throws NullPointerException On null arguments.
36 * @since 2016/05/29
38 @Exported
39 public JavaManifestKey(String __s)
40 throws NullPointerException
42 // Check
43 if (__s == null)
44 throw new NullPointerException("NARG");
46 // Lower-case all letters
47 StringBuilder sb = new StringBuilder();
48 for (int i = 0, n = __s.length(); i < n; i++)
49 sb.append(JavaManifestKey.__toLower(__s.charAt(i)));
50 this.string = sb.toString();
52 // Remember input string for case purposes
53 this.inputString = __s;
56 /**
57 * {@inheritDoc}
58 * @since 2016/05/29
60 @Override
61 public boolean equals(Object __o)
63 // Is another key?
64 if (__o instanceof JavaManifestKey)
65 return this.__equals(((JavaManifestKey)__o).string);
66 return false;
69 /**
70 * {@inheritDoc}
71 * @since 2016/05/29
73 @Override
74 public int hashCode()
76 return this.string.hashCode();
79 /**
80 * Returns the input string which was passed to this key, this string
81 * cannot be used for comparative purposes and it intended to be used
82 * for case matching in the output manifest.
84 * @return The input string.
85 * @since 2017/11/26
87 @Exported
88 public String inputString()
90 return this.inputString;
93 /**
94 * {@inheritDoc}
95 * @since 2016/05/29
97 @Override
98 public String toString()
100 return this.string;
104 * Compares two strings checking for case insensitivity in the basic
105 * ASCII range.
107 * @param __b The other string to compare against.
108 * @return {@code true} if the strings are equal.
109 * @throws NullPointerException On null arguments.
110 * @since 2016/05/29
112 private boolean __equals(String __b)
113 throws NullPointerException
115 // Check
116 if (__b == null)
117 throw new NullPointerException("NARG");
119 // Cache
120 String a = this.string;
122 // Get their lengths
123 int na = a.length(),
124 nb = __b.length();
126 // Would not be equal
127 if (na != nb)
128 return false;
130 // Check characters
131 for (int i = 0; i < na; i++)
132 if (JavaManifestKey.__toLower(a.charAt(i)) != JavaManifestKey
133 .__toLower(__b.charAt(i)))
134 return false;
136 // Matches
137 return true;
141 * Converts the specified character to lower case.
143 * @param __c The character to lower case.
144 * @return The lowercased character or {@code __c} if it cannot be
145 * lowercased.
146 * @since 2016/05/29
148 private static char __toLower(char __c)
150 if (__c >= 'A' && __c <= 'Z')
151 return (char)('a' + (__c - 'A'));
152 return __c;