/** * Returns a singleton {@code CharSeq}, i.e. a {@code CharSeq} of one character. * * @param character A character. * @return A new {@code CharSeq} instance containing the given element */ public static CharSeq of(char character) { return new CharSeq(new String(new char[] { character })); }
/** * Repeats a character {@code times} times. * * @param character A character * @param times Repetition count * @return A CharSeq representing {@code character * times} */ public static CharSeq repeat(char character, int times) { final int length = Math.max(times, 0); final char[] characters = new char[length]; java.util.Arrays.fill(characters, character); return new CharSeq(String.valueOf(characters)); }
@Override public CharSeq padTo(int length, Character element) { final int actualLength = back.length(); if (length <= actualLength) { return this; } else { return new CharSeq(back + padding(element, length - actualLength)); } }
/** * Creates a String of {@code CharSequence}. * * @param sequence {@code CharSequence} instance. * @return A new {@link io.vavr.collection.CharSeq} */ // DEV-NOTE: Needs to be 'of' instead of 'ofAll' because 'ofAll(CharSeq)' is ambiguous. public static CharSeq of(CharSequence sequence) { Objects.requireNonNull(sequence, "sequence is null"); if (sequence instanceof CharSeq) { return (CharSeq) sequence; } else { return sequence.length() == 0 ? empty() : new CharSeq(sequence.toString()); } }
/** * Creates a String of the given characters. * * @param characters Zero or more characters. * @return A string containing the given characters in the same order. * @throws NullPointerException if {@code elements} is null */ public static CharSeq of(char... characters) { Objects.requireNonNull(characters, "characters is null"); if (characters.length == 0) { return empty(); } else { final char[] chrs = new char[characters.length]; System.arraycopy(characters, 0, chrs, 0, characters.length); return new CharSeq(new String(chrs)); } }
public static CharSeq rangeBy(char from, char toExclusive, int step) { return new CharSeq(io.vavr.collection.Iterator.rangeBy(from, toExclusive, step).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toExclusive - 1}. * <p> * Examples: * <pre> * <code> * CharSeq.range('a', 'c') // = "ab" * CharSeq.range('c', 'a') // = "" * </code> * </pre> * * @param from the first character * @param toExclusive the successor of the last character * @return a range of characters as specified or the empty range if {@code from >= toExclusive} */ public static CharSeq range(char from, char toExclusive) { return new CharSeq(io.vavr.collection.Iterator.range(from, toExclusive).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toInclusive}. * <p> * Examples: * <pre> * <code> * CharSeq.rangeClosed('a', 'c') // = "abc" * CharSeq.rangeClosed('c', 'a') // = "" * </code> * </pre> * * @param from the first character * @param toInclusive the last character * @return a range of characters as specified or the empty range if {@code from > toInclusive} */ public static CharSeq rangeClosed(char from, char toInclusive) { return new CharSeq(io.vavr.collection.Iterator.rangeClosed(from, toInclusive).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toInclusive}, * with {@code step}. * <p> * Examples: * <pre> * <code> * CharSeq.rangeClosedBy('a', 'c', 1) // = ('a', 'b', 'c') * CharSeq.rangeClosedBy('a', 'd', 2) // = ('a', 'c') * CharSeq.rangeClosedBy('d', 'a', -2) // = ('d', 'b') * CharSeq.rangeClosedBy('d', 'a', 2) // = () * </code> * </pre> * * @param from the first character * @param toInclusive the last character * @param step the step * @return a range of characters as specified or the empty range if {@code step * (from - toInclusive) > 0}. * @throws IllegalArgumentException if {@code step} is zero */ public static CharSeq rangeClosedBy(char from, char toInclusive, int step) { return new CharSeq(io.vavr.collection.Iterator.rangeClosedBy(from, toInclusive, step).mkString()); }
/** * Returns a singleton {@code CharSeq}, i.e. a {@code CharSeq} of one character. * * @param character A character. * @return A new {@code CharSeq} instance containing the given element */ public static CharSeq of(char character) { return new CharSeq(new String(new char[] { character })); }
/** * Repeats a character {@code times} times. * * @param character A character * @param times Repetition count * @return A CharSeq representing {@code character * times} */ public static CharSeq repeat(char character, int times) { final int length = Math.max(times, 0); final char[] characters = new char[length]; java.util.Arrays.fill(characters, character); return new CharSeq(String.valueOf(characters)); }
@Override public CharSeq padTo(int length, Character element) { final int actualLength = back.length(); if (length <= actualLength) { return this; } else { return new CharSeq(back + padding(element, length - actualLength)); } }
/** * Creates a String of {@code CharSequence}. * * @param sequence {@code CharSequence} instance. * @return A new {@link io.vavr.collection.CharSeq} */ // DEV-NOTE: Needs to be 'of' instead of 'ofAll' because 'ofAll(CharSeq)' is ambiguous. public static CharSeq of(CharSequence sequence) { Objects.requireNonNull(sequence, "sequence is null"); if (sequence instanceof CharSeq) { return (CharSeq) sequence; } else { return sequence.length() == 0 ? empty() : new CharSeq(sequence.toString()); } }
/** * Creates a String of the given characters. * * @param characters Zero or more characters. * @return A string containing the given characters in the same order. * @throws NullPointerException if {@code elements} is null */ public static CharSeq of(char... characters) { Objects.requireNonNull(characters, "characters is null"); if (characters.length == 0) { return empty(); } else { final char[] chrs = new char[characters.length]; System.arraycopy(characters, 0, chrs, 0, characters.length); return new CharSeq(new String(chrs)); } }
public static CharSeq rangeBy(char from, char toExclusive, int step) { return new CharSeq(io.vavr.collection.Iterator.rangeBy(from, toExclusive, step).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toExclusive - 1}. * <p> * Examples: * <pre> * <code> * CharSeq.range('a', 'c') // = "ab" * CharSeq.range('c', 'a') // = "" * </code> * </pre> * * @param from the first character * @param toExclusive the successor of the last character * @return a range of characters as specified or the empty range if {@code from >= toExclusive} */ public static CharSeq range(char from, char toExclusive) { return new CharSeq(io.vavr.collection.Iterator.range(from, toExclusive).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toInclusive}. * <p> * Examples: * <pre> * <code> * CharSeq.rangeClosed('a', 'c') // = "abc" * CharSeq.rangeClosed('c', 'a') // = "" * </code> * </pre> * * @param from the first character * @param toInclusive the last character * @return a range of characters as specified or the empty range if {@code from > toInclusive} */ public static CharSeq rangeClosed(char from, char toInclusive) { return new CharSeq(io.vavr.collection.Iterator.rangeClosed(from, toInclusive).mkString()); }
/** * Creates a CharSeq starting from character {@code from}, extending to character {@code toInclusive}, * with {@code step}. * <p> * Examples: * <pre> * <code> * CharSeq.rangeClosedBy('a', 'c', 1) // = ('a', 'b', 'c') * CharSeq.rangeClosedBy('a', 'd', 2) // = ('a', 'c') * CharSeq.rangeClosedBy('d', 'a', -2) // = ('d', 'b') * CharSeq.rangeClosedBy('d', 'a', 2) // = () * </code> * </pre> * * @param from the first character * @param toInclusive the last character * @param step the step * @return a range of characters as specified or the empty range if {@code step * (from - toInclusive) > 0}. * @throws IllegalArgumentException if {@code step} is zero */ public static CharSeq rangeClosedBy(char from, char toInclusive, int step) { return new CharSeq(io.vavr.collection.Iterator.rangeClosedBy(from, toInclusive, step).mkString()); }