11/*
2- * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4242 * @author Kevin Bourrillion
4343 */
4444@ SuppressWarnings ({"checkstyle:VisibilityModifier" , "checkstyle:RedundantModifier" })
45- abstract class CharMatcher {
45+ public abstract class CharMatcher {
4646
4747 /**
4848 * Constructor for use by subclasses. When subclassing, you may want to override
@@ -54,16 +54,22 @@ protected CharMatcher() {
5454 /**
5555 * Determines whether a character is ASCII, meaning that its code point is less than 128.
5656 *
57- * @since 19.0 (since 1.0 as constant {@code ASCII})
57+ * @return a CharMatcher instance that matches ASCII characters
5858 */
5959 public static CharMatcher ascii () {
6060 return Ascii .INSTANCE ;
6161 }
6262
6363 /**
64- * Returns a {@code char} matcher that matches any character except the one specified.
64+ * Returns a {@code char} matcher that matches any character except the one
65+ * specified.
6566 *
66- * <p>To negate another {@code CharMatcher}, use {@link #negate()}.
67+ * <p>
68+ * To negate another {@code CharMatcher}, use {@link #negate()}.
69+ *
70+ * @param match the character that should not match
71+ * @return a CharMatcher instance that matches any character except the one
72+ * specified
6773 */
6874 public static CharMatcher isNot (final char match ) {
6975 return new IsNot (match );
@@ -72,16 +78,16 @@ public static CharMatcher isNot(final char match) {
7278 /**
7379 * Matches any character.
7480 *
75- * @since 19.0 (since 1.0 as constant {@code ANY})
81+ * @return a CharMatcher that matches any character
7682 */
7783 public static CharMatcher any () {
7884 return Any .INSTANCE ;
7985 }
8086
8187 /**
82- * Matches no characters .
88+ * Matches no character .
8389 *
84- * @since 19.0 (since 1.0 as constant {@code NONE})
90+ * @return a CharMatcher that matches no character
8591 */
8692 public static CharMatcher none () {
8793 return None .INSTANCE ;
@@ -91,14 +97,16 @@ public static CharMatcher none() {
9197 * Determines whether a character is an ISO control character as specified by
9298 * {@link Character#isISOControl(char)}.
9399 *
94- * @since 19.0 (since 1.0 as constant {@code JAVA_ISO_CONTROL})
100+ * @return a CharMatcher that matches ISO control character
95101 */
96102 public static CharMatcher javaIsoControl () {
97103 return JavaIsoControl .INSTANCE ;
98104 }
99105
100106 /**
101107 * Returns a {@code char} matcher that matches only one specified character.
108+ * @param match the character that should match
109+ * @return a CharMatcher that matches the one specified character
102110 */
103111 public static CharMatcher is (final char match ) {
104112 return new Is (match );
@@ -111,6 +119,8 @@ private static CharMatcher.IsEither isEither(char c1, char c2) {
111119 /**
112120 * Returns a {@code char} matcher that matches any character not present in the given character
113121 * sequence.
122+ * @param sequence all the characters that should not be matched
123+ * @return a CharMatcher that matches any character not present in the given sequence
114124 */
115125 public static CharMatcher noneOf (CharSequence sequence ) {
116126 return anyOf (sequence ).negate ();
@@ -119,6 +129,8 @@ public static CharMatcher noneOf(CharSequence sequence) {
119129 /**
120130 * Returns a {@code char} matcher that matches any character present in the given character
121131 * sequence.
132+ * @param sequence all the characters that should be matched
133+ * @return a CharMatcher that matches any character present in the given sequence
122134 */
123135 public static CharMatcher anyOf (final CharSequence sequence ) {
124136 switch (sequence .length ()) {
@@ -151,25 +163,38 @@ private static String showCharacter(char c) {
151163
152164 /**
153165 * Determines a true or false value for the given character.
166+ *
167+ * @param c the character to match
168+ * @return {@code true} if this {@code CharMatcher} instance matches the
169+ * given character, {@code false} otherwise
154170 */
155171 public abstract boolean matches (char c );
156172
157173 /**
158174 * Returns a matcher that matches any character not matched by this matcher.
175+ *
176+ * @return new {@code CharMatcher} instance representing the logical
177+ * negation of this instance
159178 */
160179 public CharMatcher negate () {
161180 return new Negated (this );
162181 }
163182
164183 /**
165184 * Returns a matcher that matches any character matched by both this matcher and {@code other}.
185+ * @param other the other instance
186+ * @return new {@code CharMatcher} instance representing the logical
187+ * and of this instance and the {@code other} instance
166188 */
167189 public CharMatcher and (CharMatcher other ) {
168190 return new And (this , other );
169191 }
170192
171193 /**
172194 * Returns a matcher that matches any character matched by either this matcher or {@code other}.
195+ * @param other the other instance
196+ * @return new {@code CharMatcher} instance representing the logical
197+ * and of this instance and the {@code other} instance
173198 */
174199 public CharMatcher or (CharMatcher other ) {
175200 return new Or (this , other );
@@ -281,6 +306,8 @@ public int indexIn(CharSequence sequence, int start) {
281306
282307 /**
283308 * Returns the number of matching characters found in a character sequence.
309+ * @param sequence sequence to count the number of matching characters
310+ * @return count of matching characters
284311 */
285312 public int countIn (CharSequence sequence ) {
286313 int count = 0 ;
@@ -327,15 +354,10 @@ public final String toString() {
327354 }
328355
329356 /**
330- * A matcher for which precomputation will not yield any significant benefit.
357+ * A matcher for which pre-computation will not yield any significant benefit.
331358 */
332359 abstract static class FastMatcher extends CharMatcher {
333360
334- // @Override
335- // public final CharMatcher precomputed() {
336- // return this;
337- // }
338-
339361 @ Override
340362 public CharMatcher negate () {
341363 return new NegatedFastMatcher (this );
@@ -350,11 +372,6 @@ static class NegatedFastMatcher extends Negated {
350372 NegatedFastMatcher (CharMatcher original ) {
351373 super (original );
352374 }
353-
354- // @Override
355- // public final CharMatcher precomputed() {
356- // return this;
357- // }
358375 }
359376
360377 /**
@@ -584,11 +601,6 @@ public boolean matches(char c) {
584601 return c == match ;
585602 }
586603
587- // @Override
588- // public String replaceFrom(CharSequence sequence, char replacement) {
589- // return sequence.toString().replace(match, replacement);
590- // }
591-
592604 @ Override
593605 public CharMatcher and (CharMatcher other ) {
594606 return other .matches (match ) ? this : none ();
@@ -643,11 +655,6 @@ public int indexIn(CharSequence sequence, int start) {
643655 return (start == length ) ? -1 : start ;
644656 }
645657
646- // @Override
647- // public int lastIndexIn(CharSequence sequence) {
648- // return sequence.length() - 1;
649- // }
650-
651658 @ Override
652659 public boolean matchesAllOf (CharSequence sequence ) {
653660 Objects .requireNonNull (sequence );
@@ -659,39 +666,6 @@ public boolean matchesNoneOf(CharSequence sequence) {
659666 return sequence .length () == 0 ;
660667 }
661668
662- // @Override
663- // public String removeFrom(CharSequence sequence) {
664- // Objects.requireNonNull(sequence);
665- // return "";
666- // }
667- //
668- // @Override
669- // public String replaceFrom(CharSequence sequence, char replacement) {
670- // char[] array = new char[sequence.length()];
671- // Arrays.fill(array, replacement);
672- // return new String(array);
673- // }
674- //
675- // @Override
676- // public String replaceFrom(CharSequence sequence, CharSequence replacement) {
677- // StringBuilder result = new StringBuilder(sequence.length() * replacement.length());
678- // for (int i = 0; i < sequence.length(); i++) {
679- // result.append(replacement);
680- // }
681- // return result.toString();
682- // }
683- //
684- // @Override
685- // public String collapseFrom(CharSequence sequence, char replacement) {
686- // return (sequence.length() == 0) ? "" : String.valueOf(replacement);
687- // }
688- //
689- // @Override
690- // public String trimFrom(CharSequence sequence) {
691- // Objects.requireNonNull(sequence);
692- // return "";
693- // }
694-
695669 @ Override
696670 public int countIn (CharSequence sequence ) {
697671 return sequence .length ();
@@ -743,12 +717,6 @@ public int indexIn(CharSequence sequence, int start) {
743717 return -1 ;
744718 }
745719
746- // @Override
747- // public int lastIndexIn(CharSequence sequence) {
748- // Objects.requireNonNull(sequence);
749- // return -1;
750- // }
751-
752720 @ Override
753721 public boolean matchesAllOf (CharSequence sequence ) {
754722 return sequence .length () == 0 ;
@@ -760,42 +728,6 @@ public boolean matchesNoneOf(CharSequence sequence) {
760728 return true ;
761729 }
762730
763- // @Override
764- // public String removeFrom(CharSequence sequence) {
765- // return sequence.toString();
766- // }
767- //
768- // @Override
769- // public String replaceFrom(CharSequence sequence, char replacement) {
770- // return sequence.toString();
771- // }
772- //
773- // @Override
774- // public String replaceFrom(CharSequence sequence, CharSequence replacement) {
775- // Objects.requireNonNull(replacement);
776- // return sequence.toString();
777- // }
778- //
779- // @Override
780- // public String collapseFrom(CharSequence sequence, char replacement) {
781- // return sequence.toString();
782- // }
783- //
784- // @Override
785- // public String trimFrom(CharSequence sequence) {
786- // return sequence.toString();
787- // }
788- //
789- // @Override
790- // public String trimLeadingFrom(CharSequence sequence) {
791- // return sequence.toString();
792- // }
793- //
794- // @Override
795- // public String trimTrailingFrom(CharSequence sequence) {
796- // return sequence.toString();
797- // }
798-
799731 @ Override
800732 public int countIn (CharSequence sequence ) {
801733 Objects .requireNonNull (sequence );
0 commit comments