1919import java .io .Serializable ;
2020import java .util .Collections ;
2121import java .util .HashMap ;
22- import java .util .HashSet ;
22+ import java .util .LinkedHashSet ;
2323import java .util .Map ;
2424import java .util .Set ;
2525import java .util .stream .Stream ;
@@ -79,7 +79,9 @@ public class CharSet implements Serializable {
7979
8080 /**
8181 * A Map of the common cases used in the factory.
82- * Subclasses can add more common patterns if desired
82+ * <p>
83+ * Subclasses can add more common patterns if desired.
84+ * </p>
8385 *
8486 * @since 2.0
8587 */
@@ -152,8 +154,8 @@ public class CharSet implements Serializable {
152154 *
153155 * <p>All CharSet objects returned by this method will be immutable.</p>
154156 *
155- * @param setStrs Strings to merge into the set, may be null
156- * @return a CharSet instance
157+ * @param setStrs Strings to merge into the set, may be null.
158+ * @return a CharSet instance.
157159 * @since 2.4
158160 */
159161 public static CharSet getInstance (final String ... setStrs ) {
@@ -170,14 +172,14 @@ public static CharSet getInstance(final String... setStrs) {
170172 }
171173
172174 /** The set of CharRange objects. */
173- private final Set <CharRange > set = Collections .synchronizedSet (new HashSet <>());
175+ private final Set <CharRange > set = Collections .synchronizedSet (new LinkedHashSet <>());
174176
175177 /**
176178 * Constructs a new CharSet using the set syntax.
177179 * Each string is merged in with the set.
178180 *
179- * @param set Strings to merge into the initial set
180- * @throws NullPointerException if set is {@code null}
181+ * @param set Strings to merge into the initial set.
182+ * @throws NullPointerException if set is {@code null}.
181183 */
182184 protected CharSet (final String ... set ) {
183185 Stream .of (set ).forEach (this ::add );
@@ -192,7 +194,6 @@ protected void add(final String str) {
192194 if (str == null ) {
193195 return ;
194196 }
195-
196197 final int len = str .length ();
197198 int pos = 0 ;
198199 while (pos < len ) {
@@ -218,10 +219,10 @@ protected void add(final String str) {
218219 }
219220
220221 /**
221- * Does the {@link CharSet} contain the specified
222- * character {@code ch}.
223- *
224- * <p>Examples using the negation character:< /p>
222+ * Tests whether this {@link CharSet} contain the specified character {@code ch}.
223+ * <p>
224+ * Examples using the negation character:
225+ * </p>
225226 * <pre>
226227 * CharSet.getInstance("^a-c").contains('a') = false
227228 * CharSet.getInstance("^a-c").contains('d') = true
@@ -232,8 +233,8 @@ protected void add(final String str) {
232233 * CharSet.getInstance("^", "a-c").contains('^') = true
233234 * </pre>
234235 *
235- * @param ch the character to check for
236- * @return {@code true} if the set contains the characters
236+ * @param ch the character to check.
237+ * @return {@code true} if the set contains the characters.
237238 */
238239 public boolean contains (final char ch ) {
239240 synchronized (set ) {
@@ -248,8 +249,8 @@ public boolean contains(final char ch) {
248249 * <p>The two sets {@code abc} and {@code a-c} are <em>not</em>
249250 * equal according to this method.</p>
250251 *
251- * @param obj the object to compare to
252- * @return true if equal
252+ * @param obj the object to compare.
253+ * @return true if equal.
253254 * @since 2.0
254255 */
255256 @ Override
@@ -265,21 +266,21 @@ public boolean equals(final Object obj) {
265266 }
266267
267268 /**
268- * Gets the internal set as an array of CharRange objects.
269+ * Gets the set of character ranges.
270+ * <p>
271+ * Package private for testing.
272+ * </p>
269273 *
270- * @return an array of immutable CharRange objects
271- * @since 2.0
274+ * @return the set of character ranges.
272275 */
273- // NOTE: This is no longer public as CharRange is no longer a public class.
274- // It may be replaced when CharSet moves to Range.
275- /*public*/ CharRange [] getCharRanges () {
276- return set .toArray (CharRange .EMPTY_ARRAY );
276+ Set <CharRange > getCharRanges () {
277+ return set ;
277278 }
278279
279280 /**
280281 * Gets a hash code compatible with the equals method.
281282 *
282- * @return a suitable hash code
283+ * @return a suitable hash code.
283284 * @since 2.0
284285 */
285286 @ Override
@@ -290,7 +291,7 @@ public int hashCode() {
290291 /**
291292 * Gets a string representation of the set.
292293 *
293- * @return string representation of the set
294+ * @return string representation of the set.
294295 */
295296 @ Override
296297 public String toString () {
0 commit comments