@@ -13,20 +13,27 @@ public class IsEqualCompressingWhiteSpace extends TypeSafeMatcher<String> {
1313 // TODO: Replace String with CharSequence to allow for easy interoperability between
1414 // String, StringBuffer, StringBuilder, CharBuffer, etc (joe).
1515
16+ /**
17+ * enum the whitespace type where SPACE is '\s', TAB is '\t', LINE_FEED is '\n',
18+ * FORM_FEED is '\f', CARRIAGE_RETURN is '\r', MIX is combined type above.
19+ * @author Koko
20+ * @version 0.0.1
21+ * @date 2021/04/26
22+ */
1623 enum whiteSpaceType
1724 {
18- SPACE , // \s
19- TAB ,// \t
20- LINEFEED , // \n
21- FORMFEED , // \f
22- CARRIAGERETURN , // \r
23- MIX ;
25+ SPACE ,
26+ TAB ,
27+ LINE_FEED ,
28+ FORM_FEED ,
29+ CARRIAGE_RETURN ,
30+ MIX
2431 }
2532
2633 private final String string ;
2734 private final whiteSpaceType type ;
2835
29- public IsEqualCompressingWhiteSpace (String string , whiteSpaceType type ) {
36+ private IsEqualCompressingWhiteSpace (String string , whiteSpaceType type ) {
3037 if (string == null ) {
3138 throw new IllegalArgumentException ("Non-null value required" );
3239 }
@@ -51,17 +58,27 @@ public void describeTo(Description description) {
5158 .appendText (" compressing white space" );
5259 }
5360
54- public String stripSpaces (String toBeStripped ) {
61+ /**
62+ * strip space on the head and tail of the string;
63+ * besides that replace all whitespace specified by this.type with " "
64+ * strip redundant space between words
65+ * @author Koko
66+ * @version 0.0.1
67+ * @date 2021/04/26
68+ * @Param string to be stripped
69+ * @return: string after stripped
70+ */
71+ private String stripSpaces (String toBeStripped ) {
5572 if (this .type == whiteSpaceType .TAB ){
5673 return toBeStripped .replaceAll ("[\\ p{Z}\\ t]+" , " " ).trim ();
5774 }
58- else if (this .type == whiteSpaceType .LINEFEED ){
75+ else if (this .type == whiteSpaceType .LINE_FEED ){
5976 return toBeStripped .replaceAll ("[\\ p{Z}\\ n]+" , " " ).trim ();
6077 }
61- else if (this .type == whiteSpaceType .FORMFEED ){
78+ else if (this .type == whiteSpaceType .FORM_FEED ){
6279 return toBeStripped .replaceAll ("[\\ p{Z}\\ f]+" , " " ).trim ();
6380 }
64- else if (this .type == whiteSpaceType .CARRIAGERETURN ){
81+ else if (this .type == whiteSpaceType .CARRIAGE_RETURN ){
6582 return toBeStripped .replaceAll ("[\\ p{Z}\\ r]+" , " " ).trim ();
6683 }
6784 else if (this .type == whiteSpaceType .SPACE ){
@@ -99,6 +116,14 @@ public static Matcher<String> equalToCompressingWhiteSpace(String expectedString
99116 return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .MIX );
100117 }
101118
119+ /**
120+ * different types of generate string matcher according to whitespace type
121+ * @author Koko
122+ * @version 0.0.1
123+ * @date 2021/04/26
124+ * @Param string to generate matcher
125+ * @return: string matcher
126+ */
102127 public static Matcher <String > equalToCompressingSpace (String expectedString ) {
103128 return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .SPACE );
104129 }
@@ -108,15 +133,15 @@ public static Matcher<String> equalToCompressingTab(String expectedString) {
108133 }
109134
110135 public static Matcher <String > equalToCompressingLineFeed (String expectedString ) {
111- return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .LINEFEED );
136+ return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .LINE_FEED );
112137 }
113138
114139 public static Matcher <String > equalToCompressingFormFeed (String expectedString ) {
115- return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .FORMFEED );
140+ return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .FORM_FEED );
116141 }
117142
118143 public static Matcher <String > equalToCompressingCarriageReturn (String expectedString ) {
119- return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .CARRIAGERETURN );
144+ return new IsEqualCompressingWhiteSpace (expectedString , whiteSpaceType .CARRIAGE_RETURN );
120145 }
121146
122147 public static Matcher <String > equalToCompressingMix (String expectedString ) {
0 commit comments