@Override public io.vavr.collection.Iterator<CharSeq> crossProduct(int power) { return io.vavr.collection.Collections.crossProduct(CharSeq.empty(), this, power); }
/** * 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)); } }
/** * Repeats this CharSeq {@code times} times. * <p> * Example: {@code CharSeq.of("ja").repeat(13) = "jajajajajajajajajajajajaja"} * * @param times Repetition count * @return A CharSeq representing {@code this * times} */ public CharSeq repeat(int times) { if (times <= 0 || isEmpty()) { return empty(); } else if (times == 1) { return this; } else { final int finalLength = length() * times; final char[] result = new char[finalLength]; back.getChars(0, length(), result, 0); int i = length(); for (; i <= (finalLength >>> 1); i <<= 1) { System.arraycopy(result, 0, result, i, i); } System.arraycopy(result, 0, result, i, finalLength - i); return of(new String(result)); } }
/** * Converts this to a {@link CharSeq}. * * @return A new {@link CharSeq}. */ default CharSeq toCharSeq() { if (this instanceof CharSeq) { return (CharSeq) this; } else if (isEmpty()) { return CharSeq.empty(); } else { return CharSeq.of(iterator().mkString()); } }
static IndexedSeq<CharSeq> apply(CharSeq elements, int k) { if (k == 0) { return Vector.of(CharSeq.empty()); } else { return elements.zipWithIndex().flatMap( t -> apply(elements.drop(t._2 + 1), (k - 1)).map((CharSeq c) -> c.prepend(t._1)) ); } } }
@Override public io.vavr.collection.Iterator<CharSeq> crossProduct(int power) { return io.vavr.collection.Collections.crossProduct(CharSeq.empty(), this, power); }
/** * 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)); } }
/** * Repeats this CharSeq {@code times} times. * <p> * Example: {@code CharSeq.of("ja").repeat(13) = "jajajajajajajajajajajajaja"} * * @param times Repetition count * @return A CharSeq representing {@code this * times} */ public CharSeq repeat(int times) { if (times <= 0 || isEmpty()) { return empty(); } else if (times == 1) { return this; } else { final int finalLength = length() * times; final char[] result = new char[finalLength]; back.getChars(0, length(), result, 0); int i = length(); for (; i <= (finalLength >>> 1); i <<= 1) { System.arraycopy(result, 0, result, i, i); } System.arraycopy(result, 0, result, i, finalLength - i); return of(new String(result)); } }
/** * Converts this to a {@link CharSeq}. * * @return A new {@link CharSeq}. */ default CharSeq toCharSeq() { if (this instanceof CharSeq) { return (CharSeq) this; } else if (isEmpty()) { return CharSeq.empty(); } else { return CharSeq.of(iterator().mkString()); } }
static IndexedSeq<CharSeq> apply(CharSeq elements, int k) { if (k == 0) { return Vector.of(CharSeq.empty()); } else { return elements.zipWithIndex().flatMap( t -> apply(elements.drop(t._2 + 1), (k - 1)).map((CharSeq c) -> c.prepend(t._1)) ); } } }
public BeanObjectOptional(boolean empty) { if (empty) { charSeq = CharSeq.empty(); either = Either.left(EITHER_VALUE); option = Option.none(); map = HashMap.empty(); multimap = HashMultimap.withSeq().empty(); seq = List.empty(); set = HashSet.empty(); } else { charSeq = CharSeq.of(CHARSEQ_VALUE); either = Either.right(EITHER_VALUE); option = Option.of(OPTION_VALUE); map = HashMap.of("key", MAP_VALUE); multimap = HashMultimap.withSeq().of("key", MULTIMAP_VALUE); seq = List.of(SEQ_VALUE); set = HashSet.of(SET_VALUE); } } }