Add additional constructor to complete the set

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-08-04 00:46:47 +00:00
parent a3ae0e2804
commit 34f6fa8a78
2 changed files with 31 additions and 3 deletions

View File

@ -64,7 +64,7 @@ import java.io.Serializable;
* @author Stephen Colebourne
* @author Chris Feldhacker
* @since 1.0
* @version $Id: CharRange.java,v 1.10 2003/08/02 18:18:33 scolebourne Exp $
* @version $Id: CharRange.java,v 1.11 2003/08/04 00:46:24 scolebourne Exp $
*/
public final class CharRange implements Serializable {
@ -91,6 +91,19 @@ public final class CharRange implements Serializable {
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>
*

View File

@ -64,7 +64,7 @@ import junit.textui.TestRunner;
* Unit tests {@link org.apache.commons.lang.CharRange}.
*
* @author Stephen Colebourne
* @version $Id: CharRangeTest.java,v 1.1 2003/08/02 18:18:33 scolebourne Exp $
* @version $Id: CharRangeTest.java,v 1.2 2003/08/04 00:46:47 scolebourne Exp $
*/
public class CharRangeTest extends TestCase {
@ -99,13 +99,28 @@ public class CharRangeTest extends TestCase {
//-----------------------------------------------------------------------
public void testConstructorAccessors_Char() {
CharRange rangea = new CharRange('a');
CharRange rangeb = new CharRange('b');
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);
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');
assertEquals('a', rangea.getStart());