Example usage for org.apache.commons.lang3 CharSet getInstance

List of usage examples for org.apache.commons.lang3 CharSet getInstance

Introduction

In this page you can find the example usage for org.apache.commons.lang3 CharSet getInstance.

Prototype

public static CharSet getInstance(final String... setStrs) 

Source Link

Document

Factory method to create a new CharSet using a special syntax.

  • null or empty string ("") - set containing no characters
  • Single character, such as "a" - set containing just that character
  • Multi character, such as "a-e" - set containing characters from one character to the other
  • Negated, such as "^a" or "^a-e" - set containing all characters except those defined
  • Combinations, such as "abe-g" - set containing all the characters from the individual sets

The matching order is:

  1. Negated multi character range, such as "^a-e"
  2. Ordinary multi character range, such as "a-e"
  3. Negated single character, such as "^a"
  4. Ordinary single character, such as "a"

Matching works left to right.

Usage

From source file:org.apache.asterix.runtime.evaluators.functions.utils.StringTrimmer.java

/**
 * @param resultBuilder/*from  w ww  . j  a v  a2 s . c  o m*/
 *            , the builder for result strings.
 * @param resultArray
 *            , the byte array to hold results.
 * @param pattern
 *            , the string that is used to construct the charset for trimming.
 */
public StringTrimmer(UTF8StringBuilder resultBuilder, GrowableArray resultArray, String pattern) {
    this.resultBuilder = resultBuilder;
    this.resultArray = resultArray;
    if (pattern != null) {
        charSet = CharSet.getInstance(pattern);
    }
}

From source file:org.apache.asterix.runtime.evaluators.functions.utils.StringTrimmer.java

/**
 * Builds the charset from a pattern string.
 *
 * @param patternPtr/*from  w  ww  . java  2  s.c o  m*/
 *            , a pattern string.
 */
public void build(UTF8StringPointable patternPtr) {
    final boolean newPattern = charSet == null || lastPatternPtr.compareTo(patternPtr) != 0;
    if (newPattern) {
        StringEvaluatorUtils.copyResetUTF8Pointable(patternPtr, lastPatternStorage, lastPatternPtr);
        charSet = CharSet.getInstance(patternPtr.toString());
    }
}

From source file:org.apache.hyracks.data.std.primitive.UTF8StringPointableTest.java

@Test
public void testTrim() throws Exception {
    UTF8StringBuilder builder = new UTF8StringBuilder();
    GrowableArray storage = new GrowableArray();
    UTF8StringPointable result = new UTF8StringPointable();
    UTF8StringPointable input = generateUTF8Pointable("  this is it.i am;here.  ");

    // Trims both sides.
    input.trim(builder, storage, true, true, CharSet.getInstance(" "));
    result.set(storage.getByteArray(), 0, storage.getLength());
    UTF8StringPointable expected = generateUTF8Pointable("this is it.i am;here.");
    assertEquals(0, expected.compareTo(result));

    // Only trims the right side.
    storage.reset();/*from ww w. j  a v  a2  s  . c  o  m*/
    input.trim(builder, storage, false, true, CharSet.getInstance(" "));
    result.set(storage.getByteArray(), 0, storage.getLength());
    expected = generateUTF8Pointable("  this is it.i am;here.");
    assertEquals(0, expected.compareTo(result));

    // Only trims the left side.
    storage.reset();
    input.trim(builder, storage, true, false, CharSet.getInstance(" "));
    result.set(storage.getByteArray(), 0, storage.getLength());
    expected = generateUTF8Pointable("this is it.i am;here.  ");
    assertEquals(0, expected.compareTo(result));
}

From source file:org.apache.hyracks.data.std.primitive.UTF8StringPointableTest.java

@Test
public void testTrimWithPattern() throws Exception {
    UTF8StringBuilder builder = new UTF8StringBuilder();
    GrowableArray storage = new GrowableArray();
    UTF8StringPointable result = new UTF8StringPointable();
    UTF8StringPointable input = generateUTF8Pointable("  this is it.i am;here.  ");

    // Trims both sides.
    input.trim(builder, storage, true, true, CharSet.getInstance(" hert."));
    result.set(storage.getByteArray(), 0, storage.getLength());
    UTF8StringPointable expected = generateUTF8Pointable("is is it.i am;");
    assertEquals(0, expected.compareTo(result));

    // Only trims the right side.
    storage.reset();/*from w  w  w  . j  a  va2 s.  c o  m*/
    input.trim(builder, storage, false, true, CharSet.getInstance(" hert."));
    result.set(storage.getByteArray(), 0, storage.getLength());
    expected = generateUTF8Pointable("  this is it.i am;");
    assertEquals(0, expected.compareTo(result));

    // Only trims the left side.
    storage.reset();
    input.trim(builder, storage, true, false, CharSet.getInstance(" hert."));
    result.set(storage.getByteArray(), 0, storage.getLength());
    expected = generateUTF8Pointable("is is it.i am;here.  ");
    assertEquals(0, expected.compareTo(result));
}