Package de.scravy.bedrock
Class Seq<E>
java.lang.Object
de.scravy.bedrock.Seq<E>
- Type Parameters:
E- The type of the Elements contained in this Sequence.
- All Implemented Interfaces:
Container<E>,ExtendedIterable<E>,HasLengthAtLeast,Serializable,Iterable<E>,IntFunction<E>,RandomAccess
@Immutable public abstract class Seq<E> extends Object implements Serializable, RandomAccess, Container<E>, IntFunction<E>
An immutable sequence.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSeq.WithIndexConsumer<E>Deprecated.Nested classes/interfaces inherited from interface de.scravy.bedrock.ExtendedIterable
ExtendedIterable.ForEachWithIndexConsumer<T> -
Field Summary
Fields Modifier and Type Field Description static Comparator<Object>NULL_ACCEPTING_COMPARATORstatic longserialVersionUID -
Constructor Summary
Constructors Constructor Description Seq() -
Method Summary
Modifier and Type Method Description static booleanall(Seq<Boolean> seq)static booleanand(Seq<Boolean> seq)static booleanany(Seq<Boolean> seq)Eapply(int index)StringasString(String delimiter)Pair<Seq<E>,Seq<E>>breakBy(Predicate<? super E> predicate)Pair<Seq<E>,Seq<E>>breakByView(Predicate<? super E> predicate)static <E> SeqBuilder<E>builder()static <E> SeqBuilder<E>builder(int sizeHint)static Seq<Integer>codepointsOfString(String string)static <T> Collector<T,SeqBuilder<T>,Seq<T>>collector()static <E, A extends E, B extends E>
Seq<A>commonPrefix(Seq<A> as, Seq<B> bs)static <A, B> intcommonPrefixLength(Seq<A> as, Seq<B> bs)static <E, A extends E, B extends E>
Seq<A>commonPrefixView(Seq<A> as, Seq<B> bs)static <E> Seq<E>concat(Seq<E>... seqs)static <E> Seq<E>concatView(Seq<E>... seqs)booleancontains(E e)intcount(E e)intcountBy(Predicate<? super E> predicate)Seq<E>distinct()Returns a copy of this Seq with no duplicates.static doubledoubleProduct(Seq<Double> seq)static doubledoubleSum(Seq<Double> seq)Edraw(Random random)default Seq<E>drop(int length)default Seq<E>dropRight(int length)default Seq<E>dropRightView(int length)default Seq<E>dropView(int length)Seq<E>dropWhile(Predicate<? super E> predicate)Seq<E>dropWhileView(Predicate<? super E> predicate)static <E> Seq<E>empty()default booleanendsWith(Seq<E> sequence)booleanequals(Object that)booleanexists(Predicate<? super E> predicate)<F extends E>
Seq<F>filter(Class<F> clazz)Seq<E>filter(Predicate<? super E> predicate)Seq<E>filterNot(Predicate<? super E> predicate)intfind(E e)intfindBy(Predicate<? super E> predicate)Optional<E>findFirst(Predicate<? super E> predicate)<F> Seq<F>flatMap(Function<? super E,Seq<F>> function)<F> Seq<F>flatMapIterable(Function<? super E,? extends Iterable<F>> function)<F> Seq<F>flatMapOptional(Function<? super E,Optional<F>> function)<A> Afoldl(BiFunction<? super A,? super E,? extends A> function, A startValue)Efoldl1(BiFunction<? super E,? super E,? extends E> function)<A> Afoldl1f(BiFunction<? super A,? super E,? extends A> function, Function<? super E,? extends A> startValueFunction)<A> Afoldr(BiFunction<? super E,? super A,? extends A> function, A startValue)Efoldr1(BiFunction<? super E,? super E,? extends E> function)<A> Afoldr1f(BiFunction<? super E,? super A,? extends A> function, Function<? super E,? extends A> startValueFunction)booleanforAll(Predicate<? super E> predicate)abstract Eget(int index)Seq<Seq<E>>group()Seq<Seq<E>>groupBy(BiPredicate<? super E,? super E> operator)inthashCode()Ehead()Optional<E>headOptional()default Seq<E>init()Seq<Seq<E>>inits()Seq<Seq<E>>initsView()default Seq<E>initView()Seq<E>intercalate(Seq<E> seq)Seq<E>intersect(Seq<E> seq)Returns a distinct Seq that contains only the elements that occur in both sets.Seq<E>intersperse(E e)static intintProduct(Seq<Integer> seq)static intintSum(Seq<Integer> seq)booleanisEmpty()Iterator<E>iterator()Elast()Optional<E>lastOptional()intlength()static longlongProduct(Seq<Long> seq)static longlongSum(Seq<Long> seq)<F> Seq<F>map(Function<? super E,? extends F> function)Emaximum()static <E extends Comparable<? super E>>
Emaximum(Seq<E> seq)EmaximumBy(Comparator<? super E> comparator)Eminimum()static <E extends Comparable<? super E>>
Eminimum(Seq<E> seq)EminimumBy(Comparator<? super E> comparator)static <E> Seq<E>of(E... es)static <E> Seq<E>ofArray(E[] array)static <E> Seq<E>ofCollection(Collection<? extends E> collection)static <E> Seq<E>ofGenerator(IntFunction<E> function, int length)static <E> Seq<E>ofGeneratorMemoizing(IntFunction<E> function, int length)static <E> Seq<E>ofIterable(Iterable<? extends E> iterable)static <E> Seq<E>ofIterator(Iterator<? extends E> iterator)static <C, A extends C, B extends C>
Seq<C>ofPair(Pair<A,B> pair)static Seq<Character>ofString(String string)static booleanor(Seq<Boolean> seq)Pair<Seq<E>,Seq<E>>partitionBy(Predicate<? super E> predicate)Seq<Seq<E>>permutations()default Iterable<Seq<E>>permutationsIterable()Iterator<Seq<E>>permutationsIterator()default Stream<Seq<E>>permutationsStream()static Seq<Integer>rangeExclusive(int from, int to)static Seq<Integer>rangeInclusive(int from, int to)Seq<E>reversed()Iterator<E>reverseIterator()Seq<E>rotated(int amount)Rotates the list by amount positions.static <E> Seq<E>seq(E... es)default Seq<E>shuffled()Seq<E>shuffled(Random random)default intsize()Exactly the same as length().Seq<E>sorted()abstract Seq<E>sortedBy(Comparator<? super E> comparator)<F extends Comparable<? super F>>
Seq<E>sortedOn(Function<? super E,? extends F> function)Pair<Seq<E>,Seq<E>>spanBy(Predicate<? super E> predicate)Pair<Seq<E>,Seq<E>>spanByView(Predicate<? super E> predicate)default booleanstartsWith(Seq<E> sequence)Seq<E>subSequence(int beginOffset, int endOffset)Seq<E>subSequenceView(int beginOffset, int endOffset)default Seq<E>tail()Seq<Seq<E>>tails()Seq<Seq<E>>tailsView()default Seq<E>tailView()default Seq<E>take(int length)default Seq<E>takeRight(int length)default Seq<E>takeRightView(int length)default Seq<E>takeView(int length)Seq<E>takeWhile(Predicate<? super E> predicate)Seq<E>takeWhileView(Predicate<? super E> predicate)abstract Object[]toArray()abstract E[]toArray(Class<E> clazz)<K extends Comparable<K>>
ArrayMap<K,Seq<E>>toArrayMap(Function<? super E,? extends K> groupingFunction)List<E>toList()Create ajava.util.Listthat contains the elements of this sequence.<K> Mapping<K,Seq<E>>toMap(Function<? super E,? extends K> groupingFunction)StringtoString()Seq<E>trimmedToSize()Seq<E>union(Seq<E> seq)Returns a distinct Seq that contains the elements from both this Seq and the given Seq.Seq<E>without(Seq<E> seq)Returns a Seq with the elements from the given Seq removed.static Seq<Boolean>wrap(boolean[] array)static Seq<Byte>wrap(byte[] array)static Seq<Character>wrap(char[] array)static Seq<Double>wrap(double[] array)static Seq<Float>wrap(float[] array)static Seq<Integer>wrap(int[] array)static Seq<Long>wrap(long[] array)static Seq<Short>wrap(short[] array)static <E> Seq<E>wrap(E[] array)static Seq<Boolean>wrap(Boolean[] array)static Seq<Byte>wrap(Byte[] array)static Seq<Character>wrap(Character[] array)static Seq<Double>wrap(Double[] array)static Seq<Float>wrap(Float[] array)static Seq<Integer>wrap(Integer[] array)static Seq<Long>wrap(Long[] array)static Seq<Short>wrap(Short[] array)static Seq<Character>wrap(String string)static Seq<Boolean>wrap(BitSet bitSet)static <E> Seq<E>wrap(List<E> list)<A> Seq<Pair<E,A>>zip(Seq<A> a)static <A, B, C> Seq<Pair<A,B>>zip(Seq<A> as, Seq<B> bs)static <A, B, C> Seq<Triple<A,B,C>>zip(Seq<A> as, Seq<B> bs, Seq<C> cs)static <A, B, C, D> Seq<Quadruple<A,B,C,D>>zip(Seq<A> as, Seq<B> bs, Seq<C> cs, Seq<D> ds)<A, C> Seq<C>zipWith(BiFunction<? super E,? super A,? extends C> function, Seq<A> sequence)Seq<Pair<Integer,E>>zipWithIndex()
-
Field Details
-
serialVersionUID
public static final long serialVersionUID- See Also:
- Constant Field Values
-
NULL_ACCEPTING_COMPARATOR
-
-
Constructor Details
-
Seq
public Seq()
-
-
Method Details
-
get
-
apply
- Specified by:
applyin interfaceIntFunction<E>
-
isEmpty
public boolean isEmpty() -
shuffled
-
draw
- Specified by:
drawin interfaceContainer<E>- Throws:
NoSuchElementException
-
sortedBy
-
sortedOn
-
toArray
-
toArray
-
asString
-
count
-
countBy
-
find
-
findBy
-
findFirst
-
contains
-
exists
-
forAll
-
map
-
flatMap
-
flatMapOptional
-
flatMapIterable
-
zip
-
zipWith
-
zipWithIndex
-
foldl
-
foldl1
-
foldl1f
-
foldr
-
foldr1
-
foldr1f
-
partitionBy
-
maximum
-
minimum
-
maximumBy
-
minimumBy
-
group
-
groupBy
-
filter
-
filter
-
filterNot
-
takeWhile
-
takeWhileView
-
dropWhile
-
dropWhileView
-
breakBy
-
breakByView
-
spanBy
-
spanByView
-
inits
-
initsView
-
tails
-
tailsView
-
head
-
last
-
headOptional
-
lastOptional
-
intercalate
-
intersperse
-
distinct
Returns a copy of this Seq with no duplicates.Order is maintained.
-
without
Returns a Seq with the elements from the given Seq removed.Order is maintained, but the resuling Seq is not distinct; if this Seq contains duplicates then the result may contain duplicates too.
-
union
Returns a distinct Seq that contains the elements from both this Seq and the given Seq.Order is maintained, but there are no duplicates.
-
intersect
Returns a distinct Seq that contains only the elements that occur in both sets.Order is maintained.
-
equals
-
hashCode
public final int hashCode() -
toString
-
rotated
Rotates the list by amount positions.Positive values rotate items to the right, negative values to the left.
Seq.of(1, 2, 3).rotated(1).equals(Seq.of(3, 1, 2))Seq.of(1, 2, 3).rotated(-1).equals(Seq.of(2, 3, 1))- Parameters:
amount- The amount of positions to rotate, positive values to the right, negative values to the left.- Returns:
- The rotated sequence.
-
permutationsIterator
-
permutations
-
iterator
-
reverseIterator
-
toList
Create ajava.util.Listthat contains the elements of this sequence.This action does not copy any data.
-
collector
-
toMap
-
toArrayMap
-
empty
-
of
-
seq
-
ofArray
-
ofCollection
-
ofIterable
-
ofIterator
-
ofPair
-
ofString
-
codepointsOfString
-
concatView
-
concat
-
builder
-
builder
-
ofGenerator
@Nonnull public static <E> Seq<E> ofGenerator(@Nonnull IntFunction<E> function, @Nonnegative int length) -
ofGeneratorMemoizing
@Nonnull public static <E> Seq<E> ofGeneratorMemoizing(@Nonnull IntFunction<E> function, @Nonnegative int length) -
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
wrap
-
minimum
-
maximum
-
any
-
all
-
intSum
-
longSum
-
doubleSum
-
intProduct
-
longProduct
-
doubleProduct
-
and
-
or
-
commonPrefixLength
-
commonPrefix
-
commonPrefixView
-
rangeInclusive
-
rangeExclusive
-
zip
-
zip
-
zip
-
length
-
reversed
-
sorted
-
trimmedToSize
-
subSequence
@Nonnull public abstract Seq<E> subSequence(@Nonnegative int beginOffset, @Nonnegative int endOffset) -
subSequenceView
@Nonnull public abstract Seq<E> subSequenceView(@Nonnegative int beginOffset, @Nonnegative int endOffset) -
size
Exactly the same as length(). -
startsWith
-
endsWith
-
shuffled
-
init
-
initView
-
tail
-
tailView
-
take
-
takeView
-
takeRight
-
takeRightView
-
drop
-
dropView
-
dropRight
-
dropRightView
-
permutationsIterable
-
permutationsStream
-