Applying patch from Vincent Ricard in LANG-514. CharRange constructors removed and replaced with readable static builder methods

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@829282 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-10-23 23:59:02 +00:00
parent ba0205c202
commit 51a130b544
4 changed files with 175 additions and 204 deletions

View File

@ -48,39 +48,6 @@ public final class CharRange implements Serializable {
/** Cached toString. */
private transient String iToString;
//-----------------------------------------------------------------------
/**
* <p>Constructs a <code>CharRange</code> over a single character.</p>
*
* @param ch only character in this range
*/
public CharRange(char ch) {
this(ch, ch, false);
}
/**
* <p>Constructs a <code>CharRange</code> over a single character,
* optionally negating the range.</p>
*
* <p>A negated range includes everything except the specified char.</p>
*
* @param ch only character in this range
* @param negated true to express everything except the range
*/
public CharRange(char ch, boolean negated) {
this(ch, ch, negated);
}
/**
* <p>Constructs a <code>CharRange</code> over a set of characters.</p>
*
* @param start first character, inclusive, in this range
* @param end last character, inclusive, in this range
*/
public CharRange(char start, char end) {
this(start, end, false);
}
/**
* <p>Constructs a <code>CharRange</code> over a set of characters,
* optionally negating the range.</p>
@ -95,7 +62,7 @@ public final class CharRange implements Serializable {
* @param end last character, inclusive, in this range
* @param negated true to express everything except the range
*/
public CharRange(char start, char end, boolean negated) {
private CharRange(char start, char end, boolean negated) {
super();
if (start > end) {
char temp = start;
@ -108,6 +75,48 @@ public final class CharRange implements Serializable {
this.negated = negated;
}
/**
* <p>Constructs a <code>CharRange</code> over a single character.</p>
*
* @param ch only character in this range
* @see CharRange#CharRange(char, boolean)
*/
public static CharRange is(char ch) {
return new CharRange(ch, ch, false);
}
/**
* <p>Constructs a negated <code>CharRange</code> over a single character.</p>
*
* @param ch only character in this range
* @see CharRange#CharRange(char, boolean)
*/
public static CharRange isNot(char ch) {
return new CharRange(ch, ch, true);
}
/**
* <p>Constructs a <code>CharRange</code> over a set of characters.</p>
*
* @param start first character, inclusive, in this range
* @param end last character, inclusive, in this range
* @see CharRange#CharRange(char, char, boolean)
*/
public static CharRange isIn(char start, char end) {
return new CharRange(start, end, false);
}
/**
* <p>Constructs a negated <code>CharRange</code> over a set of characters.</p>
*
* @param start first character, inclusive, in this range
* @param end last character, inclusive, in this range
* @see CharRange#CharRange(char, char, boolean)
*/
public static CharRange isNotIn(char start, char end) {
return new CharRange(start, end, true);
}
// Accessors
//-----------------------------------------------------------------------
/**

View File

@ -204,19 +204,19 @@ public class CharSet implements Serializable {
int remainder = (len - pos);
if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') {
// negated range
set.add(new CharRange(str.charAt(pos + 1), str.charAt(pos + 3), true));
set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3)));
pos += 4;
} else if (remainder >= 3 && str.charAt(pos + 1) == '-') {
// range
set.add(new CharRange(str.charAt(pos), str.charAt(pos + 2)));
set.add(CharRange.isIn(str.charAt(pos), str.charAt(pos + 2)));
pos += 3;
} else if (remainder >= 2 && str.charAt(pos) == '^') {
// negated char
set.add(new CharRange(str.charAt(pos + 1), true));
set.add(CharRange.isNot(str.charAt(pos + 1)));
pos += 2;
} else {
// char
set.add(new CharRange(str.charAt(pos)));
set.add(CharRange.is(str.charAt(pos)));
pos += 1;
}
}

View File

@ -64,96 +64,64 @@ public class CharRangeTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testConstructorAccessors_Char() {
CharRange rangea = new CharRange('a');
public void testConstructorAccessors_is() {
CharRange rangea = CharRange.is('a');
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a", rangea.toString());
}
public void testConstructorAccessors_CharBoolean_Normal() {
CharRange rangea = new CharRange('a');
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a", rangea.toString());
}
public void testConstructorAccessors_CharBoolean_Negated() {
CharRange rangea = new CharRange('a', true);
public void testConstructorAccessors_isNot() {
CharRange rangea = CharRange.isNot('a');
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(true, rangea.isNegated());
assertEquals("^a", rangea.toString());
}
public void testConstructorAccessors_CharChar_Same() {
CharRange rangea = new CharRange('a', 'a');
public void testConstructorAccessors_isIn_Same() {
CharRange rangea = CharRange.isIn('a', 'a');
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a", rangea.toString());
}
public void testConstructorAccessors_CharChar_Normal() {
CharRange rangea = new CharRange('a', 'e');
public void testConstructorAccessors_isIn_Normal() {
CharRange rangea = CharRange.isIn('a', 'e');
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a-e", rangea.toString());
}
public void testConstructorAccessors_CharChar_Reversed() {
CharRange rangea = new CharRange('e', 'a');
public void testConstructorAccessors_isIn_Reversed() {
CharRange rangea = CharRange.isIn('e', 'a');
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a-e", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_Same() {
CharRange rangea = new CharRange('a', 'a', false);
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_Normal() {
CharRange rangea = new CharRange('a', 'e', false);
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a-e", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_Reversed() {
CharRange rangea = new CharRange('e', 'a', false);
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(false, rangea.isNegated());
assertEquals("a-e", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_SameNegated() {
CharRange rangea = new CharRange('a', 'a', true);
public void testConstructorAccessors_isNotIn_Same() {
CharRange rangea = CharRange.isNotIn('a', 'a');
assertEquals('a', rangea.getStart());
assertEquals('a', rangea.getEnd());
assertEquals(true, rangea.isNegated());
assertEquals("^a", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_NormalNegated() {
CharRange rangea = new CharRange('a', 'e', true);
public void testConstructorAccessors_isNotIn_Normal() {
CharRange rangea = CharRange.isNotIn('a', 'e');
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(true, rangea.isNegated());
assertEquals("^a-e", rangea.toString());
}
public void testConstructorAccessors_CharCharBoolean_ReversedNegated() {
CharRange rangea = new CharRange('e', 'a', true);
public void testConstructorAccessors_isNotIn_Reversed() {
CharRange rangea = CharRange.isNotIn('e', 'a');
assertEquals('a', rangea.getStart());
assertEquals('e', rangea.getEnd());
assertEquals(true, rangea.isNegated());
@ -162,18 +130,18 @@ public class CharRangeTest extends TestCase {
//-----------------------------------------------------------------------
public void testEquals_Object() {
CharRange rangea = new CharRange('a');
CharRange rangeae = new CharRange('a', 'e');
CharRange rangenotbf = new CharRange('b', 'f', false);
CharRange rangea = CharRange.is('a');
CharRange rangeae = CharRange.isIn('a', 'e');
CharRange rangenotbf = CharRange.isIn('b', 'f');
assertEquals(false, rangea.equals(null));
assertEquals(true, rangea.equals(rangea));
assertEquals(true, rangea.equals(new CharRange('a')));
assertEquals(true, rangea.equals(CharRange.is('a')));
assertEquals(true, rangeae.equals(rangeae));
assertEquals(true, rangeae.equals(new CharRange('a', 'e')));
assertEquals(true, rangeae.equals(CharRange.isIn('a', 'e')));
assertEquals(true, rangenotbf.equals(rangenotbf));
assertEquals(true, rangenotbf.equals(new CharRange('b', 'f', false)));
assertEquals(true, rangenotbf.equals(CharRange.isIn('b', 'f')));
assertEquals(false, rangea.equals(rangeae));
assertEquals(false, rangea.equals(rangenotbf));
@ -184,16 +152,16 @@ public class CharRangeTest extends TestCase {
}
public void testHashCode() {
CharRange rangea = new CharRange('a');
CharRange rangeae = new CharRange('a', 'e');
CharRange rangenotbf = new CharRange('b', 'f', false);
CharRange rangea = CharRange.is('a');
CharRange rangeae = CharRange.isIn('a', 'e');
CharRange rangenotbf = CharRange.isIn('b', 'f');
assertEquals(true, rangea.hashCode() == rangea.hashCode());
assertEquals(true, rangea.hashCode() == new CharRange('a').hashCode());
assertEquals(true, rangea.hashCode() == CharRange.is('a').hashCode());
assertEquals(true, rangeae.hashCode() == rangeae.hashCode());
assertEquals(true, rangeae.hashCode() == new CharRange('a', 'e').hashCode());
assertEquals(true, rangeae.hashCode() == CharRange.isIn('a', 'e').hashCode());
assertEquals(true, rangenotbf.hashCode() == rangenotbf.hashCode());
assertEquals(true, rangenotbf.hashCode() == new CharRange('b', 'f', false).hashCode());
assertEquals(true, rangenotbf.hashCode() == CharRange.isIn('b', 'f').hashCode());
assertEquals(false, rangea.hashCode() == rangeae.hashCode());
assertEquals(false, rangea.hashCode() == rangenotbf.hashCode());
@ -205,31 +173,25 @@ public class CharRangeTest extends TestCase {
//-----------------------------------------------------------------------
public void testContains_Char() {
CharRange range = new CharRange('c');
CharRange range = CharRange.is('c');
assertEquals(false, range.contains('b'));
assertEquals(true, range.contains('c'));
assertEquals(false, range.contains('d'));
assertEquals(false, range.contains('e'));
range = new CharRange('c', 'd');
range = CharRange.isIn('c', 'd');
assertEquals(false, range.contains('b'));
assertEquals(true, range.contains('c'));
assertEquals(true, range.contains('d'));
assertEquals(false, range.contains('e'));
range = new CharRange('d', 'c');
range = CharRange.isIn('d', 'c');
assertEquals(false, range.contains('b'));
assertEquals(true, range.contains('c'));
assertEquals(true, range.contains('d'));
assertEquals(false, range.contains('e'));
range = new CharRange('c', 'd', false);
assertEquals(false, range.contains('b'));
assertEquals(true, range.contains('c'));
assertEquals(true, range.contains('d'));
assertEquals(false, range.contains('e'));
range = new CharRange('c', 'd', true);
range = CharRange.isNotIn('c', 'd');
assertEquals(true, range.contains('b'));
assertEquals(false, range.contains('c'));
assertEquals(false, range.contains('d'));
@ -240,19 +202,19 @@ public class CharRangeTest extends TestCase {
//-----------------------------------------------------------------------
public void testContains_Charrange() {
CharRange a = new CharRange('a');
CharRange b = new CharRange('b');
CharRange c = new CharRange('c');
CharRange c2 = new CharRange('c');
CharRange d = new CharRange('d');
CharRange e = new CharRange('e');
CharRange cd = new CharRange('c', 'd');
CharRange bd = new CharRange('b', 'd');
CharRange bc = new CharRange('b', 'c');
CharRange ab = new CharRange('a', 'b');
CharRange de = new CharRange('d', 'e');
CharRange ef = new CharRange('e', 'f');
CharRange ae = new CharRange('a', 'e');
CharRange a = CharRange.is('a');
CharRange b = CharRange.is('b');
CharRange c = CharRange.is('c');
CharRange c2 = CharRange.is('c');
CharRange d = CharRange.is('d');
CharRange e = CharRange.is('e');
CharRange cd = CharRange.isIn('c', 'd');
CharRange bd = CharRange.isIn('b', 'd');
CharRange bc = CharRange.isIn('b', 'c');
CharRange ab = CharRange.isIn('a', 'b');
CharRange de = CharRange.isIn('d', 'e');
CharRange ef = CharRange.isIn('e', 'f');
CharRange ae = CharRange.isIn('a', 'e');
// normal/normal
assertEquals(false, c.contains(b));
@ -278,17 +240,17 @@ public class CharRangeTest extends TestCase {
assertEquals(true, ae.contains(cd));
assertEquals(true, ae.contains(de));
CharRange notb = new CharRange('b', 'b', true);
CharRange notc = new CharRange('c', 'c', true);
CharRange notd = new CharRange('d', 'd', true);
CharRange notab = new CharRange('a', 'b', true);
CharRange notbc = new CharRange('b', 'c', true);
CharRange notbd = new CharRange('b', 'd', true);
CharRange notcd = new CharRange('c', 'd', true);
CharRange notde = new CharRange('d', 'e', true);
CharRange notae = new CharRange('a', 'e', true);
CharRange all = new CharRange((char) 0, Character.MAX_VALUE);
CharRange allbutfirst = new CharRange((char) 1, Character.MAX_VALUE);
CharRange notb = CharRange.isNot('b');
CharRange notc = CharRange.isNot('c');
CharRange notd = CharRange.isNot('d');
CharRange notab = CharRange.isNotIn('a', 'b');
CharRange notbc = CharRange.isNotIn('b', 'c');
CharRange notbd = CharRange.isNotIn('b', 'd');
CharRange notcd = CharRange.isNotIn('c', 'd');
CharRange notde = CharRange.isNotIn('d', 'e');
CharRange notae = CharRange.isNotIn('a', 'e');
CharRange all = CharRange.isIn((char) 0, Character.MAX_VALUE);
CharRange allbutfirst = CharRange.isIn((char) 1, Character.MAX_VALUE);
// normal/negated
assertEquals(false, c.contains(notc));
@ -354,7 +316,7 @@ public class CharRangeTest extends TestCase {
}
public void testContainsNullArg() {
CharRange range = new CharRange('a');
CharRange range = CharRange.is('a');
try {
@SuppressWarnings("unused")
boolean contains = range.contains(null);
@ -365,11 +327,11 @@ public class CharRangeTest extends TestCase {
//-----------------------------------------------------------------------
public void testSerialization() {
CharRange range = new CharRange('a');
CharRange range = CharRange.is('a');
assertEquals(range, SerializationUtils.clone(range));
range = new CharRange('a', 'e');
range = CharRange.isIn('a', 'e');
assertEquals(range, SerializationUtils.clone(range));
range = new CharRange('a', 'e', true);
range = CharRange.isNotIn('a', 'e');
assertEquals(range, SerializationUtils.clone(range));
}

View File

@ -130,35 +130,35 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("abc");
array = set.getCharRanges();
assertEquals(3, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('b')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c')));
set = CharSet.getInstance("a-ce-f");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'c')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('e', 'f')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', 'c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('e', 'f')));
set = CharSet.getInstance("ae-f");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('e', 'f')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('e', 'f')));
set = CharSet.getInstance("e-fa");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('e', 'f')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('e', 'f')));
set = CharSet.getInstance("ae-fm-pz");
array = set.getCharRanges();
assertEquals(4, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('e', 'f')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('m', 'p')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('e', 'f')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('m', 'p')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('z')));
}
public void testConstructor_String_comboNegated() {
@ -168,37 +168,37 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("^abc");
array = set.getCharRanges();
assertEquals(3, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'a', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('b')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c')));
set = CharSet.getInstance("b^ac");
array = set.getCharRanges();
assertEquals(3, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('b')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'a', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c')));
set = CharSet.getInstance("db^ac");
array = set.getCharRanges();
assertEquals(4, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('d')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('b')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'a', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('d')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c')));
set = CharSet.getInstance("^b^a");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('b', 'b', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'a', true)));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('a')));
set = CharSet.getInstance("b^a-c^z");
array = set.getCharRanges();
assertEquals(3, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'c', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('z', 'z', true)));
assertEquals(true, ArrayUtils.contains(array, new CharRange('b')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('a', 'c')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('b')));
}
public void testConstructor_String_oddDash() {
@ -208,44 +208,44 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("-");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
set = CharSet.getInstance("--");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
set = CharSet.getInstance("---");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
set = CharSet.getInstance("----");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
set = CharSet.getInstance("-a");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
set = CharSet.getInstance("a-");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-')));
set = CharSet.getInstance("a--");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', '-')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', '-')));
set = CharSet.getInstance("--a");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('-', 'a')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('-', 'a')));
}
public void testConstructor_String_oddNegate() {
@ -254,57 +254,57 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("^");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^'))); // "^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('^'))); // "^"
set = CharSet.getInstance("^^");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', '^', true))); // "^^"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('^'))); // "^^"
set = CharSet.getInstance("^^^");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', '^', true))); // "^^"
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', '^'))); // "^"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('^'))); // "^^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('^'))); // "^"
set = CharSet.getInstance("^^^^");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', '^', true))); // "^^" x2
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('^'))); // "^^" x2
set = CharSet.getInstance("a^");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a'))); // "a"
assertEquals(true, ArrayUtils.contains(array, new CharRange('^'))); // "^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('a'))); // "a"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('^'))); // "^"
set = CharSet.getInstance("^a-");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'a', true))); // "^a"
assertEquals(true, ArrayUtils.contains(array, new CharRange('-'))); // "-"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('a'))); // "^a"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-'))); // "-"
set = CharSet.getInstance("^^-c");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', 'c', true))); // "^^-c"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('^', 'c'))); // "^^-c"
set = CharSet.getInstance("^c-^");
array = set.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('c', '^', true))); // "^c-^"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('c', '^'))); // "^c-^"
set = CharSet.getInstance("^c-^d");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('c', '^', true))); // "^c-^"
assertEquals(true, ArrayUtils.contains(array, new CharRange('d'))); // "d"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('c', '^'))); // "^c-^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('d'))); // "d"
set = CharSet.getInstance("^^-");
array = set.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('^', '^', true))); // "^^"
assertEquals(true, ArrayUtils.contains(array, new CharRange('-'))); // "-"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNot('^'))); // "^^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('-'))); // "-"
}
public void testConstructor_String_oddCombinations() {
@ -313,8 +313,8 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("a-^c");
array = set.getCharRanges();
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', '^'))); // "a-^"
assertEquals(true, ArrayUtils.contains(array, new CharRange('c'))); // "c"
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', '^'))); // "a-^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c'))); // "c"
assertEquals(false, set.contains('b'));
assertEquals(true, set.contains('^'));
assertEquals(true, set.contains('_')); // between ^ and a
@ -322,16 +322,16 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("^a-^c");
array = set.getCharRanges();
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', '^', true))); // "^a-^"
assertEquals(true, ArrayUtils.contains(array, new CharRange('c'))); // "c"
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('a', '^'))); // "^a-^"
assertEquals(true, ArrayUtils.contains(array, CharRange.is('c'))); // "c"
assertEquals(true, set.contains('b'));
assertEquals(false, set.contains('^'));
assertEquals(false, set.contains('_')); // between ^ and a
set = CharSet.getInstance("a- ^-- "); //contains everything
array = set.getCharRanges();
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', ' '))); // "a- "
assertEquals(true, ArrayUtils.contains(array, new CharRange('-', ' ', true))); // "^-- "
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', ' '))); // "a- "
assertEquals(true, ArrayUtils.contains(array, CharRange.isNotIn('-', ' '))); // "^-- "
assertEquals(true, set.contains('#'));
assertEquals(true, set.contains('^'));
assertEquals(true, set.contains('a'));
@ -340,7 +340,7 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("^-b");
array = set.getCharRanges();
assertEquals(true, ArrayUtils.contains(array, new CharRange('^','b'))); // "^-b"
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('^','b'))); // "^-b"
assertEquals(true, set.contains('b'));
assertEquals(true, set.contains('_')); // between ^ and a
assertEquals(false, set.contains('A'));
@ -348,7 +348,7 @@ public class CharSetTest extends TestCase {
set = CharSet.getInstance("b-^");
array = set.getCharRanges();
assertEquals(true, ArrayUtils.contains(array, new CharRange('^','b'))); // "b-^"
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('^','b'))); // "b-^"
assertEquals(true, set.contains('b'));
assertEquals(true, set.contains('^'));
assertEquals(true, set.contains('a')); // between ^ and b
@ -460,20 +460,20 @@ public class CharSetTest extends TestCase {
array = CharSet.ASCII_ALPHA.getCharRanges();
assertEquals(2, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'z')));
assertEquals(true, ArrayUtils.contains(array, new CharRange('A', 'Z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', 'z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('A', 'Z')));
array = CharSet.ASCII_ALPHA_LOWER.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('a', 'z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('a', 'z')));
array = CharSet.ASCII_ALPHA_UPPER.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('A', 'Z')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('A', 'Z')));
array = CharSet.ASCII_NUMERIC.getCharRanges();
assertEquals(1, array.length);
assertEquals(true, ArrayUtils.contains(array, new CharRange('0', '9')));
assertEquals(true, ArrayUtils.contains(array, CharRange.isIn('0', '9')));
}
}