/** * Removes all of the elements from this set. This set will be * empty after this call returns. * @stable ICU 2.0 */ public UnicodeSet clear() { checkFrozen(); list[0] = HIGH; len = 1; pat = null; strings.clear(); return this; }
/** * Reallocate this objects internal structures to take up the least * possible space, without changing this object's value. * @stable ICU 2.0 */ public UnicodeSet compact() { checkFrozen(); if (len != list.length) { int[] temp = new int[len]; System.arraycopy(list, 0, temp, 0, len); list = temp; } rangeList = null; buffer = null; return this; }
/** * Remove all strings from this UnicodeSet * @return this object, for chaining * @stable ICU 4.2 */ public final UnicodeSet removeAllStrings() { checkFrozen(); if (strings.size() != 0) { strings.clear(); pat = null; } return this; }
/** * Adds the specified character to this set if it is not already * present. If this set already contains the specified character, * the call leaves this set unchanged. * @stable ICU 2.0 */ public final UnicodeSet add(int c) { checkFrozen(); return add_unchecked(c); }
/** * Adds all characters in range (uses preferred naming convention). * @param start The index of where to start on adding all characters. * @param end The index of where to end on adding all characters. * @return a reference to this object * @stable ICU 4.4 */ public UnicodeSet addAll(int start, int end) { checkFrozen(); return add_unchecked(start, end); }
/** * @see #removeAll(com.ibm.icu.text.UnicodeSet) * @stable ICU 4.4 */ public <T extends CharSequence> UnicodeSet removeAll(Iterable<T> collection) { checkFrozen(); for (T o : collection) { remove(o); } return this; }
/** * @see #addAll(com.ibm.icu.text.UnicodeSet) * @stable ICU 4.4 */ @SuppressWarnings("unchecked") // See ticket #11395, this is safe. public <T extends CharSequence> UnicodeSet addAll(T... collection) { checkFrozen(); for (T str : collection) { add(str); } return this; }
/** * Modifies this set to represent the set specified by the given pattern. * See the class description for the syntax of the pattern language. * Whitespace is ignored. * @param pattern a string specifying what characters are in the set * @exception java.lang.IllegalArgumentException if the pattern * contains a syntax error. * @stable ICU 2.0 */ public final UnicodeSet applyPattern(String pattern) { checkFrozen(); return applyPattern(pattern, null, null, IGNORE_SPACE); }
/** * Modifies this set to represent the set specified by the given pattern, * optionally ignoring whitespace. * See the class description for the syntax of the pattern language. * @param pattern a string specifying what characters are in the set * @param ignoreWhitespace if true then Unicode Pattern_White_Space characters are ignored * @exception java.lang.IllegalArgumentException if the pattern * contains a syntax error. * @stable ICU 2.0 */ public UnicodeSet applyPattern(String pattern, boolean ignoreWhitespace) { checkFrozen(); return applyPattern(pattern, null, null, ignoreWhitespace ? IGNORE_SPACE : 0); }
/** * Make this object represent the same set as <code>other</code>. * @param other a <code>UnicodeSet</code> whose value will be * copied to this object * @stable ICU 2.0 */ public UnicodeSet set(UnicodeSet other) { checkFrozen(); list = other.list.clone(); len = other.len; pat = other.pat; strings = new TreeSet<String>(other.strings); return this; }
/** * Add a collection (as strings) into this UnicodeSet. * Uses standard naming convention. * @param source collection to add into * @return a reference to this object * @stable ICU 4.4 */ public UnicodeSet addAll(Iterable<?> source) { checkFrozen(); for (Object o : source) { add(o.toString()); } return this; }
/** * Modifies this set to represent the set specified by the given pattern, * optionally ignoring whitespace. * See the class description for the syntax of the pattern language. * @param pattern a string specifying what characters are in the set * @param options a bitmask indicating which options to apply. * Valid options are IGNORE_SPACE and CASE. * @exception java.lang.IllegalArgumentException if the pattern * contains a syntax error. * @stable ICU 3.8 */ public UnicodeSet applyPattern(String pattern, int options) { checkFrozen(); return applyPattern(pattern, null, null, options); }
/** * Adds the specified range to this set if it is not already * present. If this set already contains the specified range, * the call leaves this set unchanged. If <code>end > start</code> * then an empty range is added, leaving the set unchanged. * * @param start first character, inclusive, of range to be added * to this set. * @param end last character, inclusive, of range to be added * to this set. * @stable ICU 2.0 */ public UnicodeSet add(int start, int end) { checkFrozen(); return add_unchecked(start, end); }
/** * Adds all of the elements in the specified set to this set if * they're not already present. This operation effectively * modifies this set so that its value is the <i>union</i> of the two * sets. The behavior of this operation is unspecified if the specified * collection is modified while the operation is in progress. * * @param c set whose elements are to be added to this set. * @stable ICU 2.0 */ public UnicodeSet addAll(UnicodeSet c) { checkFrozen(); add(c.list, c.len, 0); strings.addAll(c.strings); return this; }
/** * Make this object represent the range <code>start - end</code>. * If <code>end > start</code> then this object is set to an * an empty range. * * @param start first character in the set, inclusive * @param end last character in the set, inclusive * @stable ICU 2.0 */ public UnicodeSet set(int start, int end) { checkFrozen(); clear(); complement(start, end); return this; }
/** * Complements in this set all elements contained in the specified * set. Any character in the other set will be removed if it is * in this set, or will be added if it is not in this set. * * @param c set that defines which elements will be complemented from * this set. * @stable ICU 2.0 */ public UnicodeSet complementAll(UnicodeSet c) { checkFrozen(); xor(c.list, c.len, 0); SortedSetRelation.doOperation(strings, SortedSetRelation.COMPLEMENTALL, c.strings); return this; }
/** * Retains only the elements in this set that are contained in the * specified set. In other words, removes from this set all of * its elements that are not contained in the specified set. This * operation effectively modifies this set so that its value is * the <i>intersection</i> of the two sets. * * @param c set that defines which elements this set will retain. * @stable ICU 2.0 */ public UnicodeSet retainAll(UnicodeSet c) { checkFrozen(); retain(c.list, c.len, 0); strings.retainAll(c.strings); return this; }
/** * Removes from this set all of its elements that are contained in the * specified set. This operation effectively modifies this * set so that its value is the <i>asymmetric set difference</i> of * the two sets. * * @param c set that defines which elements will be removed from * this set. * @stable ICU 2.0 */ public UnicodeSet removeAll(UnicodeSet c) { checkFrozen(); retain(c.list, c.len, 2); strings.removeAll(c.strings); return this; }
/** * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"} * If this set already any particular character, it has no effect on that character. * @param s the source string * @return this object, for chaining * @stable ICU 2.0 */ public final UnicodeSet addAll(CharSequence s) { checkFrozen(); int cp; for (int i = 0; i < s.length(); i += UTF16.getCharCount(cp)) { cp = UTF16.charAt(s, i); add_unchecked(cp, cp); } return this; }
/** * @see #retainAll(com.ibm.icu.text.UnicodeSet) * @stable ICU 4.4 */ public <T extends CharSequence> UnicodeSet retainAll(Iterable<T> collection) { checkFrozen(); // TODO optimize UnicodeSet toRetain = new UnicodeSet(); toRetain.addAll(collection); retainAll(toRetain); return this; }