Package io.vavr.collection
Class Tree.Node<T>
- java.lang.Object
-
- io.vavr.collection.Tree<T>
-
- io.vavr.collection.Tree.Node<T>
-
- Type Parameters:
T- value type
- All Implemented Interfaces:
Foldable<T>,Traversable<T>,Iterable<T>,Value<T>,java.io.Serializable,java.lang.Iterable<T>
@Deprecated public static final class Tree.Node<T> extends Tree<T> implements java.io.Serializable
Deprecated.will be removed from the public APIRepresents a tree node.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.vavr.collection.Tree
Tree.Empty<T>, Tree.Node<T>, Tree.Order
-
-
Method Summary
Modifier and Type Method Description java.lang.Stringdraw()Deprecated.Creates a neat 2-dimensional drawing of a tree.booleanequals(java.lang.Object o)Deprecated.In Vavr there are four basic classes of collections: Seq (sequential elements) Set (distinct elements) Map (indexed elements) Multimap (indexed collections) Two collection instances of these classes are equal if and only if both collections belong to the same basic collection class (Seq, Set, Map or Multimap) contain the same elements have the same element order, if the collections are of type Seq Two Map/Multimap elements, resp.List<Tree.Node<T>>getChildren()Deprecated.Returns the children of this tree.TgetValue()Deprecated.Gets the value of this tree.inthashCode()Deprecated.Returns the hash code of this collection.booleanisEmpty()Deprecated.Checks if this Traversable is empty.booleanisLeaf()Deprecated.Checks if this Tree is a leaf.Tlast()Deprecated.Dual of Traversable.head(), returning the last element.intlength()Deprecated.Computes the number of elements of this Traversable.java.lang.StringtoLispString()Deprecated.Creates a Lisp-like representation of thisTree.java.lang.StringtoString()Deprecated.Clarifies that values have a proper toString() method implemented.-
Methods inherited from class io.vavr.collection.Tree
branchCount, build, collect, collector, distinct, distinctBy, distinctBy, drop, dropRight, dropUntil, dropWhile, empty, fill, fill, filter, filterNot, flatMap, foldRight, groupBy, grouped, hasDefiniteSize, head, init, initOption, isAsync, isBranch, isDistinct, isLazy, isSequential, isTraversableAgain, iterator, iterator, leafCount, map, narrow, nodeCount, of, of, of, of, ofAll, ofAll, orElse, orElse, partition, peek, recurse, reject, replace, replaceAll, retainAll, scan, scanLeft, scanRight, slideBy, sliding, sliding, span, stringPrefix, tabulate, tail, tailOption, take, takeRight, takeUntil, takeWhile, transform, traverse, traverse, unzip, unzip3, values, values, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, fold, foldLeft, forEachWithIndex, get, headOption, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
Method Detail
-
getChildren
public List<Tree.Node<T>> getChildren()
Deprecated.Description copied from class:TreeReturns the children of this tree.- Specified by:
getChildrenin classTree<T>- Returns:
- the tree's children
-
getValue
public T getValue()
Deprecated.Description copied from class:TreeGets the value of this tree.
-
isEmpty
public boolean isEmpty()
Deprecated.Description copied from interface:TraversableChecks if this Traversable is empty.
-
length
public int length()
Deprecated.Description copied from interface:TraversableComputes the number of elements of this Traversable.Same as
Traversable.size().- Specified by:
lengthin interfaceTraversable<T>- Returns:
- the number of elements
-
isLeaf
public boolean isLeaf()
Deprecated.Description copied from class:TreeChecks if this Tree is a leaf. A tree is a leaf if it is a Node with no children. Because the empty tree is no Node, it is not a leaf by definition.
-
last
public T last()
Deprecated.Description copied from interface:TraversableDual of Traversable.head(), returning the last element.- Specified by:
lastin interfaceTraversable<T>- Returns:
- the last element.
-
equals
public boolean equals(java.lang.Object o)
Deprecated.Description copied from interface:TraversableIn Vavr there are four basic classes of collections:- Seq (sequential elements)
- Set (distinct elements)
- Map (indexed elements)
- Multimap (indexed collections)
- belong to the same basic collection class (Seq, Set, Map or Multimap)
- contain the same elements
- have the same element order, if the collections are of type Seq
Notes:
- No collection instance equals null, e.g. Queue(1) not equals null.
- Nulls are allowed and handled as expected, e.g. List(null, 1) equals Stream(null, 1) and HashMap((null, 1)) equals LinkedHashMap((null, 1)).
- The element order is taken into account for Seq only. E.g. List(null, 1) not equals Stream(1, null) and HashMap((null, 1), ("a", null)) equals LinkedHashMap(("a", null), (null, 1)). The reason is, that we do not know which implementations we compare when having two instances of type Map, Multimap or Set (see Liskov Substitution Principle).
- Other collection classes are equal if their types are equal and their elements are equal (in iteration order).
- Iterator equality is defined to be object reference equality.
-
hashCode
public int hashCode()
Deprecated.Description copied from interface:TraversableReturns the hash code of this collection.
We distinguish between two types of hashes, those for collections with predictable iteration order (like Seq) and those with arbitrary iteration order (like Set, Map and Multimap).
In all cases the hash of an empty collection is defined to be 1.
Collections with predictable iteration order are hashed as follows:
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }
Generally, hash codes of collections aren't cached in Vavr (opposed to the size/length). Storing hash codes in order to reduce the time complexity would increase the memory footprint. Persistent collections are built upon tree structures, it allows us to implement efficient memory sharing. A drawback of tree structures is that they make it necessary to store collection attributes at each tree node (read: element).
The computation of the hash code is linear in time, i.e. O(n). If the hash code of a collection is re-calculated often, e.g. when using a List as HashMap key, we might want to cache the hash code. This can be achieved by simply using a wrapper class, which is not included in Vavr but could be implemented like this:public final class Hashed<K> { private final K key; private final Lazy<Integer> hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; } @Override public boolean equals(Object o) { if (o == key) { return true; } else if (key != null && o instanceof Hashed) { final Hashed that = (Hashed) o; return key.equals(that.key); } else { return false; } } @Override public int hashCode() { return hashCode.get(); } @Override public String toString() { return "Hashed(" + (key == null ? "null" : key.toString()) + ")"; } }
-
toString
public java.lang.String toString()
Deprecated.Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
toLispString
public java.lang.String toLispString()
Deprecated.Description copied from class:TreeCreates a Lisp-like representation of thisTree.- Specified by:
toLispStringin classTree<T>- Returns:
- This
Treeas Lisp-string, i.e. represented as list of lists.
-
-