Interface Traversable<E>

All Known Subinterfaces:
IndexedList<E>, Iterable<E>, LinkedList<E>, List<E>, Map<K,V>, Set<E>, SortedMap<K,V>, SortedSet<E>
All Known Implementing Classes:
AbstractIndexedList, AbstractIterable, AbstractLinkedList, AbstractList, AbstractMap, AbstractSet, AbstractSortedMap, AbstractSortedSet, AbstractTraversable, ArrayList, Cons, ConsList, DerivedKeyHashMap, HashMap, HashSet, ListMap, ListMap.Node, MappedIterable, Nil, TreeMap, TreeSet, Vector

public interface Traversable<E>
Traversable is the root of the collection hierarchy.

Traversable allows collections to be defined by a forEach(Function) method and without an iterator. forEach(Function) can be a lot simpler to implement for tree-like structure and also offers a more direct method of traversal for such structures.

  • Method Summary

    Modifier and Type
    Method
    Description
    <U> void
    forEach(@NotNull Function<E,U> f)
    All collection methods can be built upon this forEach definition.
    boolean
    Returns true if this collection is empty.
    @NotNull String
    makeString(@NotNull String separator)
    Returns this collection converted to a string by joining elements together with the specified separator.
    @NotNull String
    makeString(@NotNull String separator, @NotNull String prefix, @NotNull String postfix, int limit, @NotNull String truncated)
    Returns this collection converted to a string.
    int
    Returns the size of the collection.
    <R extends Traversable<E>>
    R
    to(@NotNull Builder<E,R> builder)
    Converts this collection to another collection using a builder.
    @NotNull Object[]
    Converts this collection to an array of objects.
    E[]
    toArray(E[] array)
    Converts this collection to an array of objects of the correct type.
    @NotNull IndexedList<E>
    Converts this collection to an indexed list.
    @NotNull Set<E>
    Converts this collection to a set.
    @NotNull SortedSet<E>
    toSortedSet(Comparator<? super E> comparator)
    Converts this collection to a sorted set.
  • Method Details

    • forEach

      <U> void forEach(@NotNull @NotNull Function<E,U> f)
      All collection methods can be built upon this forEach definition.
    • size

      int size()
      Returns the size of the collection.

      Warning: infinite collections are possible, as are collections that require traversal to calculate the size.

    • isEmpty

      boolean isEmpty()
      Returns true if this collection is empty.
    • makeString

      @NotNull @NotNull String makeString(@NotNull @NotNull String separator)
      Returns this collection converted to a string by joining elements together with the specified separator.
    • makeString

      @NotNull @NotNull String makeString(@NotNull @NotNull String separator, @NotNull @NotNull String prefix, @NotNull @NotNull String postfix, int limit, @NotNull @NotNull String truncated)
      Returns this collection converted to a string.
      Parameters:
      separator - Specifies the joining character
      prefix - Specifies a prefix to the string
      postfix - Species a postfix to the string
      limit - Specifies the maximum number of elements to join. If the limit is exceeded, additional elements are ignored.
      truncated - If the limit is reached, the truncated value will be appended to indicate the limit was reached.
    • to

      @NotNull <R extends Traversable<E>> R to(@NotNull @NotNull Builder<E,R> builder)
      Converts this collection to another collection using a builder.
    • toSet

      @NotNull @NotNull Set<E> toSet()
      Converts this collection to a set.
    • toSortedSet

      @NotNull @NotNull SortedSet<E> toSortedSet(Comparator<? super E> comparator)
      Converts this collection to a sorted set.
    • toIndexedList

      @NotNull @NotNull IndexedList<E> toIndexedList()
      Converts this collection to an indexed list.
    • toArray

      @NotNull @NotNull Object[] toArray()
      Converts this collection to an array of objects.
    • toArray

      @NotNull E[] toArray(E[] array)
      Converts this collection to an array of objects of the correct type.