Update for LANG-1069: CharSet.getInstance documentation does not clearly explain how to include negation character in set. Javadoc expanded and unit tests added to match examples. Based on patch by Arno Noordover.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1672833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9bebec9cf9
commit
71f6746f81
|
@ -22,6 +22,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.5" date="tba" description="tba">
|
<release version="3.5" date="tba" description="tba">
|
||||||
|
<action issue="LANG-1069" type="update" dev="djones" due-to="Arno Noordover">CharSet.getInstance documentation does not clearly explain how to include negation character in set</action>
|
||||||
<action issue="LANG-1050" type="add" dev="djones" due-to="James Sawle">Change nullToEmpty methods to generics</action>
|
<action issue="LANG-1050" type="add" dev="djones" due-to="James Sawle">Change nullToEmpty methods to generics</action>
|
||||||
<action issue="LANG-1111" type="fix" dev="chas">Fix FindBugs warnings in DurationFormatUtils</action>
|
<action issue="LANG-1111" type="fix" dev="chas">Fix FindBugs warnings in DurationFormatUtils</action>
|
||||||
<action issue="LANG-1074" type="add" dev="djones" due-to="Haiyang Li">Add a method to ArrayUtils for removing all occurrences of a given element</action>
|
<action issue="LANG-1074" type="add" dev="djones" due-to="Haiyang Li">Add a method to ArrayUtils for removing all occurrences of a given element</action>
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class CharSet implements Serializable {
|
||||||
* <li>Negated single character, such as "^a"
|
* <li>Negated single character, such as "^a"
|
||||||
* <li>Ordinary single character, such as "a"
|
* <li>Ordinary single character, such as "a"
|
||||||
* </ol>
|
* </ol>
|
||||||
|
*
|
||||||
* <p>Matching works left to right. Once a match is found the
|
* <p>Matching works left to right. Once a match is found the
|
||||||
* search starts again from the next character.</p>
|
* search starts again from the next character.</p>
|
||||||
*
|
*
|
||||||
|
@ -129,6 +130,23 @@ public class CharSet implements Serializable {
|
||||||
*
|
*
|
||||||
* <p>The set of characters represented is the union of the specified ranges.</p>
|
* <p>The set of characters represented is the union of the specified ranges.</p>
|
||||||
*
|
*
|
||||||
|
* <p>There are two ways to add a literal negation character ({@code ^}):</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>As the last character in a string, e.g. {@code CharSet.getInstance("a-z^")}</li>
|
||||||
|
* <li>As a separate element, e.g. {@code CharSet.getInstance("^","a-z")}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Examples using the negation character:</p>
|
||||||
|
* <pre>
|
||||||
|
* CharSet.getInstance("^a-c").contains('a') = false
|
||||||
|
* CharSet.getInstance("^a-c").contains('d') = true
|
||||||
|
* CharSet.getInstance("^^a-c").contains('a') = true // (only '^' is negated)
|
||||||
|
* CharSet.getInstance("^^a-c").contains('^') = false
|
||||||
|
* CharSet.getInstance("^a-cd-f").contains('d') = true
|
||||||
|
* CharSet.getInstance("a-c^").contains('^') = true
|
||||||
|
* CharSet.getInstance("^", "a-c").contains('^') = true
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
* <p>All CharSet objects returned by this method will be immutable.</p>
|
* <p>All CharSet objects returned by this method will be immutable.</p>
|
||||||
*
|
*
|
||||||
* @param setStrs Strings to merge into the set, may be null
|
* @param setStrs Strings to merge into the set, may be null
|
||||||
|
|
|
@ -18,10 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
@ -466,4 +463,14 @@ public class CharSetTest {
|
||||||
assertTrue(ArrayUtils.contains(array, CharRange.isIn('0', '9')));
|
assertTrue(ArrayUtils.contains(array, CharRange.isIn('0', '9')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJavadocExamples() throws Exception {
|
||||||
|
assertFalse(CharSet.getInstance("^a-c").contains('a'));
|
||||||
|
assertTrue(CharSet.getInstance("^a-c").contains('d'));
|
||||||
|
assertTrue(CharSet.getInstance("^^a-c").contains('a'));
|
||||||
|
assertFalse(CharSet.getInstance("^^a-c").contains('^'));
|
||||||
|
assertTrue(CharSet.getInstance("^a-cd-f").contains('d'));
|
||||||
|
assertTrue(CharSet.getInstance("a-c^").contains('^'));
|
||||||
|
assertTrue(CharSet.getInstance("^", "a-c").contains('^'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue