List of usage examples for org.apache.commons.lang3 CharSet getInstance
public static CharSet getInstance(final String... setStrs)
Factory method to create a new CharSet using a special syntax.
The matching order is:
Matching works left to right.
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)); }