io.vavr.collection.HashSet.empty()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中io.vavr.collection.HashSet.empty()方法的一些代码示例,展示了HashSet.empty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashSet.empty()方法的具体详情如下:
包路径:io.vavr.collection.HashSet
类名称:HashSet
方法名:empty

HashSet.empty介绍

暂无

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link HashSet#empty()}
 *
 * @param <T> Component type of element.
 * @return A singleton instance of empty {@link HashSet}
 */
public static <T> Set<T> Set() {
  return HashSet.empty();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Set}.
 *
 * @return A new {@link HashSet}.
 */
default Set<T> toSet() {
  return ValueModule.toTraversable(this, HashSet.empty(), HashSet::of, HashSet::ofAll);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns a singleton {@code HashSet}, i.e. a {@code HashSet} of one element.
 *
 * @param element An element.
 * @param <T>     The component type
 * @return A new HashSet instance containing the given element
 */
public static <T> HashSet<T> of(T element) {
  return HashSet.<T> empty().add(element);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns a HashSet containing tuples returned by {@code n} calls to a given Supplier {@code s}.
 *
 * @param <T> Component type of the HashSet
 * @param n   The number of elements in the HashSet
 * @param s   The Supplier computing element values
 * @return An HashSet of size {@code n}, where each element contains the result supplied by {@code s}.
 * @throws NullPointerException if {@code s} is null
 */
public static <T> HashSet<T> fill(int n, Supplier<? extends T> s) {
  Objects.requireNonNull(s, "s is null");
  return Collections.fill(n, s, HashSet.empty(), HashSet::of);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns an HashSet containing {@code n} values of a given Function {@code f}
 * over a range of integer values from 0 to {@code n - 1}.
 *
 * @param <T> Component type of the HashSet
 * @param n   The number of elements in the HashSet
 * @param f   The Function computing element values
 * @return An HashSet consisting of elements {@code f(0),f(1), ..., f(n - 1)}
 * @throws NullPointerException if {@code f} is null
 */
public static <T> HashSet<T> tabulate(int n, Function<? super Integer, ? extends T> f) {
  Objects.requireNonNull(f, "f is null");
  return Collections.tabulate(n, f, HashSet.empty(), HashSet::of);
}

代码示例来源:origin: vavr-io/vavr

/**
   * {@code readResolve} method for the serialization proxy pattern.
   * <p>
   * Returns a logically equivalent instance of the enclosing class. The presence of this method causes the
   * serialization system to translate the serialization proxy back into an instance of the enclosing class
   * upon deserialization.
   *
   * @return A deserialized instance of the enclosing class.
   */
  private Object readResolve() {
    return tree.isEmpty() ? HashSet.empty() : new HashSet<>(tree);
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
default <U> Iterator<T> distinctBy(Function<? super T, ? extends U> keyExtractor) {
  Objects.requireNonNull(keyExtractor, "keyExtractor is null");
  if (!hasNext()) {
    return empty();
  } else {
    return new DistinctIterator<>(this, io.vavr.collection.HashSet.empty(), keyExtractor);
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
default Iterator<T> distinct() {
  if (!hasNext()) {
    return empty();
  } else {
    return new DistinctIterator<>(this, io.vavr.collection.HashSet.empty(), Function.identity());
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> HashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  if (isEmpty()) {
    return empty();
  } else {
    final HashArrayMappedTrie<U, U> that = foldLeft(HashArrayMappedTrie.empty(),
        (tree, t) -> addAll(tree, mapper.apply(t)));
    return new HashSet<>(that);
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public <U> HashSet<U> map(Function<? super T, ? extends U> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  if (isEmpty()) {
    return empty();
  } else {
    final HashArrayMappedTrie<U, U> that = foldLeft(HashArrayMappedTrie.empty(), (tree, t) -> {
      final U u = mapper.apply(t);
      return tree.put(u, u);
    });
    return new HashSet<>(that);
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Creates a HashSet of the given elements.
 *
 * <pre><code>HashSet.of(1, 2, 3, 4)</code></pre>
 *
 * @param <T>      Component type of the HashSet.
 * @param elements Zero or more elements.
 * @return A set containing the given elements.
 * @throws NullPointerException if {@code elements} is null
 */
@SafeVarargs
public static <T> HashSet<T> of(T... elements) {
  Objects.requireNonNull(elements, "elements is null");
  HashArrayMappedTrie<T, T> tree = HashArrayMappedTrie.empty();
  for (T element : elements) {
    tree = tree.put(element, element);
  }
  return tree.isEmpty() ? empty() : new HashSet<>(tree);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Creates a HashSet of the given elements.
 *
 * @param elements Set elements
 * @param <T>      The value type
 * @return A new HashSet containing the given entries
 */
@SuppressWarnings("unchecked")
public static <T> HashSet<T> ofAll(Iterable<? extends T> elements) {
  Objects.requireNonNull(elements, "elements is null");
  if (elements instanceof HashSet) {
    return (HashSet<T>) elements;
  } else {
    final HashArrayMappedTrie<T, T> tree = addAll(HashArrayMappedTrie.empty(), elements);
    return tree.isEmpty() ? empty() : new HashSet<>(tree);
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public HashSet<T> filter(Predicate<? super T> predicate) {
  Objects.requireNonNull(predicate, "predicate is null");
  final HashSet<T> filtered = HashSet.ofAll(iterator().filter(predicate));
  if (filtered.isEmpty()) {
    return empty();
  } else if (filtered.length() == length()) {
    return this;
  } else {
    return filtered;
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public HashSet<T> take(int n) {
  if (n >= size() || isEmpty()) {
    return this;
  } else if (n <= 0) {
    return empty();
  } else {
    return ofAll(() -> iterator().take(n));
  }
}

代码示例来源:origin: vavr-io/vavr

@Override
public HashSet<T> intersect(Set<? extends T> elements) {
  Objects.requireNonNull(elements, "elements is null");
  if (isEmpty() || elements.isEmpty()) {
    return empty();
  } else {
    final int size = size();
    if (size <= elements.size()) {
      return retainAll(elements);
    } else {
      final HashSet<T> results = HashSet.<T> ofAll(elements).retainAll(this);
      return (size == results.size()) ? this : results;
    }
  }
}

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link HashSet#empty()}
 *
 * @param <T> Component type of element.
 * @return A singleton instance of empty {@link HashSet}
 */
public static <T> Set<T> Set() {
  return HashSet.empty();
}

代码示例来源:origin: io.vavr/vavr

/**
 * Converts this to a {@link Set}.
 *
 * @return A new {@link HashSet}.
 */
default Set<T> toSet() {
  return ValueModule.toTraversable(this, HashSet.empty(), HashSet::of, HashSet::ofAll);
}

代码示例来源:origin: io.vavr/vavr

@Override
default Iterator<T> distinct() {
  if (!hasNext()) {
    return empty();
  } else {
    return new DistinctIterator<>(this, io.vavr.collection.HashSet.empty(), Function.identity());
  }
}

代码示例来源:origin: io.vavr/vavr

@Override
public HashSet<T> filter(Predicate<? super T> predicate) {
  Objects.requireNonNull(predicate, "predicate is null");
  final HashSet<T> filtered = HashSet.ofAll(iterator().filter(predicate));
  if (filtered.isEmpty()) {
    return empty();
  } else if (filtered.length() == length()) {
    return this;
  } else {
    return filtered;
  }
}

代码示例来源:origin: io.vavr/vavr

@Override
public HashSet<T> take(int n) {
  if (n >= size() || isEmpty()) {
    return this;
  } else if (n <= 0) {
    return empty();
  } else {
    return ofAll(() -> iterator().take(n));
  }
}

相关文章