Esempio n. 1
0
 /**
  * Constructs a rose tree branch.
  *
  * @param value A value.
  * @param children A non-empty list of children.
  * @throws NullPointerException if children is null
  * @throws IllegalArgumentException if children is empty
  */
 public Node(T value, List<Node<T>> children) {
   Objects.requireNonNull(children, "children is null");
   this.value = value;
   this.children = children;
   this.size = Lazy.of(() -> 1 + children.foldLeft(0, (acc, child) -> acc + child.length()));
   this.hashCode = 31 * 31 + 31 * Objects.hashCode(value) + Objects.hashCode(children);
 }
 private static int testHashCode() {
   int errors = 0;
   errors += (Objects.hashCode(null) == 0) ? 0 : 1;
   String s = "42";
   errors += (Objects.hashCode(s) == s.hashCode()) ? 0 : 1;
   return errors;
 }