commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r905281 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/ test/java/org/apache/commons/lang/
Date Mon, 01 Feb 2010 13:43:14 GMT
Author: niallp
Date: Mon Feb  1 13:43:13 2010
New Revision: 905281

URL: http://svn.apache.org/viewvc?rev=905281&view=rev
Log:
Port LANG-514 to 2.x branch - add more readable static builder methods to CharRange

Modified:
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharRange.java
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharSet.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharRangeTest.java
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharSetTest.java

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharRange.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharRange.java?rev=905281&r1=905280&r2=905281&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharRange.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharRange.java
Mon Feb  1 13:43:13 2010
@@ -48,6 +48,54 @@
     /** Cached toString. */
     private transient String iToString;
 
+    // Static
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Constructs a <code>CharRange</code> over a single character.</p>
+     *
+     * @param ch  only character in this range
+     * @return the new CharRange object
+     * @see CharRange#CharRange(char, 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
+     * @return the new CharRange object
+     * @see CharRange#CharRange(char, 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
+     * @return the new CharRange object
+     * @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
+     * @return the new CharRange object
+     * @see CharRange#CharRange(char, char, boolean)
+     */
+    public static CharRange isNotIn(char start, char end) {
+        return new CharRange(start, end, true);
+    }
+
     //-----------------------------------------------------------------------
     /**
      * <p>Constructs a <code>CharRange</code> over a single character.</p>

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharSet.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharSet.java?rev=905281&r1=905280&r2=905281&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharSet.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/CharSet.java
Mon Feb  1 13:43:13 2010
@@ -205,19 +205,19 @@
             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;
             }
         }

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharRangeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharRangeTest.java?rev=905281&r1=905280&r2=905281&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharRangeTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharRangeTest.java
Mon Feb  1 13:43:13 2010
@@ -60,7 +60,72 @@
         assertEquals(true, Modifier.isPublic(CharRange.class.getModifiers()));
         assertEquals(true, Modifier.isFinal(CharRange.class.getModifiers()));
     }
+
+    //-----------------------------------------------------------------------
+    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_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_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_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_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_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_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_isNotIn_Reversed() {
+        CharRange rangea = CharRange.isNotIn('e', 'a');
+        assertEquals('a', rangea.getStart());
+        assertEquals('e', rangea.getEnd());
+        assertEquals(true, rangea.isNegated());
+        assertEquals("^a-e", rangea.toString());
+    }
+
     //-----------------------------------------------------------------------
     public void testConstructorAccessors_Char() {
         CharRange rangea = new CharRange('a');
@@ -160,18 +225,18 @@
 
     //-----------------------------------------------------------------------    
     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));
@@ -182,16 +247,16 @@
     }
             
     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());
@@ -203,31 +268,31 @@
     
     //-----------------------------------------------------------------------    
     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);
+        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('c', 'd', true);
+        range = CharRange.isNotIn('c', 'd');
         assertEquals(true, range.contains('b'));
         assertEquals(false, range.contains('c'));
         assertEquals(false, range.contains('d'));
@@ -238,19 +303,19 @@
     
     //-----------------------------------------------------------------------    
     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));
@@ -276,17 +341,17 @@
         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));
@@ -352,7 +417,7 @@
     }
     
     public void testContainsNullArg() {
-        CharRange range = new CharRange('a');
+        CharRange range = CharRange.is('a');
         try {
             boolean contains = range.contains(null);
         } catch(IllegalArgumentException e) {
@@ -362,11 +427,11 @@
     
     //-----------------------------------------------------------------------    
     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)); 
     }
     

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharSetTest.java?rev=905281&r1=905280&r2=905281&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharSetTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/CharSetTest.java
Mon Feb  1 13:43:13 2010
@@ -128,35 +128,35 @@
         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() {
@@ -166,39 +166,39 @@
         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() {
         CharSet set;
         CharRange[] array;
@@ -206,44 +206,44 @@
         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() {
@@ -252,57 +252,57 @@
         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() {
@@ -311,8 +311,8 @@
         
         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
@@ -320,16 +320,16 @@
         
         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'));
@@ -338,7 +338,7 @@
         
         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'));
@@ -346,7 +346,7 @@
         
         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
@@ -458,20 +458,20 @@
         
         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')));
     }
     
 }



Mime
View raw message