diff --git a/src/main/java/io/vavr/CheckedConsumer.java b/src/main/java/io/vavr/CheckedConsumer.java index d8bf47290..1f630c857 100644 --- a/src/main/java/io/vavr/CheckedConsumer.java +++ b/src/main/java/io/vavr/CheckedConsumer.java @@ -79,7 +79,6 @@ static CheckedConsumer of(CheckedConsumer methodReference) { * @throws NullPointerException if {@code after} is null */ default CheckedConsumer andThen(CheckedConsumer after) { - Objects.requireNonNull(after, "after is null"); return (T t) -> { accept(t); after.accept(t); }; } diff --git a/src/main/java/io/vavr/Lazy.java b/src/main/java/io/vavr/Lazy.java index b7bb3de21..8fa532c46 100644 --- a/src/main/java/io/vavr/Lazy.java +++ b/src/main/java/io/vavr/Lazy.java @@ -103,7 +103,6 @@ public static Lazy narrow(Lazy lazy) { */ @SuppressWarnings("unchecked") public static Lazy of(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); if (supplier instanceof Lazy) { return (Lazy) supplier; } else { @@ -122,7 +121,6 @@ public static Lazy of(Supplier supplier) { */ @SuppressWarnings("Convert2MethodRef") // TODO should be fixed in JDK 9 and Idea public static Lazy> sequence(Iterable> values) { - Objects.requireNonNull(values, "values is null"); return Lazy.of(() -> Vector.ofAll(values).map(lazy -> lazy.get())); } @@ -137,8 +135,6 @@ public static Lazy> sequence(Iterable> va */ @SuppressWarnings("unchecked") public static T val(Supplier supplier, Class type) { - Objects.requireNonNull(supplier, "supplier is null"); - Objects.requireNonNull(type, "type is null"); if (!type.isInterface()) { throw new IllegalArgumentException("type has to be an interface"); } @@ -148,13 +144,11 @@ public static T val(Supplier supplier, Class type) { } public Option filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final T v = get(); return predicate.test(v) ? Option.some(v) : Option.none(); } public Option filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @@ -245,7 +239,6 @@ public Lazy peek(Consumer action) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } diff --git a/src/main/java/io/vavr/Predicates.java b/src/main/java/io/vavr/Predicates.java index 041fe8213..b181a18d5 100644 --- a/src/main/java/io/vavr/Predicates.java +++ b/src/main/java/io/vavr/Predicates.java @@ -64,7 +64,6 @@ private Predicates() { @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static Predicate allOf(Predicate... predicates) { - Objects.requireNonNull(predicates, "predicates is null"); return t -> List.of(predicates).foldLeft(true, (bool, pred) -> bool && pred.test(t)); } @@ -88,7 +87,6 @@ public static Predicate allOf(Predicate... predicates) { @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static Predicate anyOf(Predicate... predicates) { - Objects.requireNonNull(predicates, "predicates is null"); return t -> List.of(predicates).find(pred -> pred.test(t)).isDefined(); } @@ -108,7 +106,6 @@ public static Predicate anyOf(Predicate... predicates) { * @throws NullPointerException if {@code predicate} is null */ public static Predicate> exists(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return iterable -> Iterator.ofAll(iterable).exists(predicate); } @@ -128,7 +125,6 @@ public static Predicate> exists(Predicate predicate) * @throws NullPointerException if {@code predicate} is null */ public static Predicate> forAll(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return iterable -> Iterator.ofAll(iterable).forAll(predicate); } @@ -148,7 +144,6 @@ public static Predicate> forAll(Predicate predicate) */ // DEV-NOTE: We need Class instead of Class, see {@link TryTest#shouldRecoverSuccessUsingCase()} public static Predicate instanceOf(Class type) { - Objects.requireNonNull(type, "type is null"); return obj -> obj != null && type.isAssignableFrom(obj.getClass()); } @@ -188,7 +183,6 @@ public static Predicate is(T value) { @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static Predicate isIn(T... values) { - Objects.requireNonNull(values, "values is null"); return obj -> List.of(values).find(value -> Objects.equals(value, obj)).isDefined(); } @@ -245,7 +239,6 @@ public static Predicate isNull() { @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static Predicate noneOf(Predicate... predicates) { - Objects.requireNonNull(predicates, "predicates is null"); return anyOf(predicates).negate(); } @@ -271,7 +264,6 @@ public static Predicate noneOf(Predicate... predicates) { */ @SuppressWarnings("unchecked") public static Predicate not(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return (Predicate) predicate.negate(); } diff --git a/src/main/java/io/vavr/Value.java b/src/main/java/io/vavr/Value.java index 0eaacbea3..f124e953c 100644 --- a/src/main/java/io/vavr/Value.java +++ b/src/main/java/io/vavr/Value.java @@ -313,7 +313,6 @@ default boolean eq(Object o) { * @throws NullPointerException if {@code predicate} is null */ default boolean exists(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (T t : this) { if (predicate.test(t)) { return true; @@ -330,7 +329,6 @@ default boolean exists(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default boolean forAll(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return !exists(predicate.negate()); } @@ -342,7 +340,6 @@ default boolean forAll(Predicate predicate) { */ @Override default void forEach(Consumer action) { - Objects.requireNonNull(action, "action is null"); for (T t : this) { action.accept(t); } @@ -383,7 +380,6 @@ default T getOrElse(T other) { * @throws NullPointerException if supplier is null */ default T getOrElse(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isEmpty() ? supplier.get() : get(); } @@ -397,7 +393,6 @@ default T getOrElse(Supplier supplier) { * @throws X if no value is present */ default T getOrElseThrow(Supplier supplier) throws X { - Objects.requireNonNull(supplier, "supplier is null"); if (isEmpty()) { throw supplier.get(); } else { @@ -413,7 +408,6 @@ default T getOrElseThrow(Supplier supplier) throws X { * @throws NullPointerException if supplier is null */ default T getOrElseTry(CheckedFunction0 supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isEmpty() ? Try.of(supplier).get() : get(); } @@ -612,7 +606,6 @@ default Validation toInvalid(U value) { */ @Deprecated default Validation toInvalid(Supplier valueSupplier) { - Objects.requireNonNull(valueSupplier, "valueSupplier is null"); return isEmpty() ? Validation.valid(valueSupplier.get()) : Validation.invalid(get()); } @@ -672,7 +665,6 @@ default Object[] toJavaArray() { @Deprecated @SuppressWarnings("unchecked") default T[] toJavaArray(Class componentType) { - Objects.requireNonNull(componentType, "componentType is null"); if (componentType.isPrimitive()) { final Class boxedType = componentType == boolean.class ? Boolean.class : @@ -852,8 +844,6 @@ default java.util.Map toJavaMap(Function> MAP toJavaMap(Supplier factory, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return toJavaMap(factory, t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))); } @@ -883,7 +873,6 @@ default > MAP toJavaMap(Supplier fact * @return a new {@code java.util.Map} of type {@code MAP} */ default > MAP toJavaMap(Supplier factory, Function> f) { - Objects.requireNonNull(f, "f is null"); final MAP map = factory.get(); if (!isEmpty()) { if (isSingleValued()) { @@ -1048,7 +1037,6 @@ default Either toLeft(R right) { */ @Deprecated default Either toLeft(Supplier right) { - Objects.requireNonNull(right, "right is null"); return isEmpty() ? Either.right(right.get()) : Either.left(get()); } @@ -1071,8 +1059,6 @@ default List toList() { * @return A new {@link HashMap}. */ default Map toMap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return toMap(t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))); } @@ -1085,7 +1071,6 @@ default Map toMap(Function keyMapper, Funct * @return A new {@link HashMap}. */ default Map toMap(Function> f) { - Objects.requireNonNull(f, "f is null"); final Function, Map> ofElement = HashMap::of; final Function>, Map> ofAll = HashMap::ofEntries; return ValueModule.toMap(this, HashMap.empty(), ofElement, ofAll, f); @@ -1101,8 +1086,6 @@ default Map toMap(Function Map toLinkedMap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return toLinkedMap(t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))); } @@ -1115,7 +1098,6 @@ default Map toLinkedMap(Function keyMapper, * @return A new {@link LinkedHashMap}. */ default Map toLinkedMap(Function> f) { - Objects.requireNonNull(f, "f is null"); final Function, Map> ofElement = LinkedHashMap::of; final Function>, Map> ofAll = LinkedHashMap::ofEntries; return ValueModule.toMap(this, LinkedHashMap.empty(), ofElement, ofAll, f); @@ -1131,8 +1113,6 @@ default Map toLinkedMap(Function, V> SortedMap toSortedMap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return toSortedMap(t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))); } @@ -1145,7 +1125,6 @@ default , V> SortedMap toSortedMap(Functio * @return A new {@link TreeMap}. */ default , V> SortedMap toSortedMap(Function> f) { - Objects.requireNonNull(f, "f is null"); return toSortedMap(Comparator.naturalOrder(), f); } @@ -1160,9 +1139,6 @@ default , V> SortedMap toSortedMap(Functio * @return A new {@link TreeMap}. */ default SortedMap toSortedMap(Comparator comparator, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return toSortedMap(comparator, t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))); } @@ -1176,8 +1152,6 @@ default SortedMap toSortedMap(Comparator comparator, Fun * @return A new {@link TreeMap}. */ default SortedMap toSortedMap(Comparator comparator, Function> f) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(f, "f is null"); final Function, SortedMap> ofElement = t -> TreeMap.of(comparator, t); final Function>, SortedMap> ofAll = t -> TreeMap.ofEntries(comparator, t); return ValueModule.toMap(this, TreeMap.empty(comparator), ofElement, ofAll, f); @@ -1219,7 +1193,6 @@ default Either toEither(L left) { * @return A new {@link Either}. */ default Either toEither(Supplier leftSupplier) { - Objects.requireNonNull(leftSupplier, "leftSupplier is null"); if (this instanceof Either) { return ((Either) this).mapLeft(ignored -> leftSupplier.get()); } else { @@ -1250,7 +1223,6 @@ default Validation toValidation(E invalid) { * @return A new {@link Validation}. */ default Validation toValidation(Supplier invalidSupplier) { - Objects.requireNonNull(invalidSupplier, "invalidSupplier is null"); if (this instanceof Validation) { return ((Validation) this).mapError(ignored -> invalidSupplier.get()); } else { @@ -1291,7 +1263,6 @@ default PriorityQueue toPriorityQueue() { * @return A new {@link PriorityQueue}. */ default PriorityQueue toPriorityQueue(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final PriorityQueue empty = PriorityQueue.empty(comparator); final Function> of = value -> PriorityQueue.of(comparator, value); final Function, PriorityQueue> ofAll = values -> PriorityQueue.ofAll(comparator, values); @@ -1324,7 +1295,6 @@ default Either toRight(L left) { */ @Deprecated default Either toRight(Supplier left) { - Objects.requireNonNull(left, "left is null"); return isEmpty() ? Either.left(left.get()) : Either.right(get()); } @@ -1372,7 +1342,6 @@ default SortedSet toSortedSet() throws ClassCastException { * @return A new {@link TreeSet}. */ default SortedSet toSortedSet(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return ValueModule.toTraversable(this, TreeSet.empty(comparator), value -> TreeSet.of(comparator, value), values -> TreeSet.ofAll(comparator, values)); } @@ -1411,7 +1380,6 @@ default Try toTry() { * @return A new {@link Try}. */ default Try toTry(Supplier ifEmpty) { - Objects.requireNonNull(ifEmpty, "ifEmpty is null"); return isEmpty() ? Try.failure(ifEmpty.get()) : toTry(); } @@ -1463,7 +1431,6 @@ default Validation toValid(E error) { */ @Deprecated default Validation toValid(Supplier errorSupplier) { - Objects.requireNonNull(errorSupplier, "errorSupplier is null"); return isEmpty() ? Validation.invalid(errorSupplier.get()) : Validation.valid(get()); } diff --git a/src/main/java/io/vavr/collection/AbstractMultimap.java b/src/main/java/io/vavr/collection/AbstractMultimap.java index a38dd542f..9f961aae3 100644 --- a/src/main/java/io/vavr/collection/AbstractMultimap.java +++ b/src/main/java/io/vavr/collection/AbstractMultimap.java @@ -86,8 +86,6 @@ public Map> asMap() { @Override public Multimap bimap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return createFromEntries(entries); } @@ -104,7 +102,6 @@ public ContainerType getContainerType() { @Override public Multimap flatMap(BiFunction>> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(this.emptyInstance(), (acc, entry) -> { for (Tuple2 mappedEntry : mapper.apply(entry._1, entry._2)) { acc = acc.put(mappedEntry); @@ -131,13 +128,11 @@ public Set keySet() { @Override public Multimap map(BiFunction> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(this.emptyInstance(), (acc, entry) -> acc.put(mapper.apply(entry._1, entry._2))); } @Override public Multimap mapValues(Function valueMapper) { - Objects.requireNonNull(valueMapper, "valueMapper is null"); return map((k, v) -> Tuple.of(k, valueMapper.apply(v))); } @@ -151,7 +146,6 @@ public M put(K key, V value) { @Override public M put(Tuple2 entry) { - Objects.requireNonNull(entry, "entry is null"); return put(entry._1, entry._2); } @@ -201,14 +195,12 @@ public M distinct() { @SuppressWarnings("unchecked") @Override public M distinctBy(Comparator> comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return (M) (isEmpty() ? this : createFromEntries(iterator().distinctBy(comparator))); } @SuppressWarnings("unchecked") @Override public M distinctBy(Function, ? extends U> keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return (M) (isEmpty() ? this : createFromEntries(iterator().distinctBy(keyExtractor))); } @@ -238,21 +230,18 @@ public M dropRight(int n) { @Override public M dropUntil(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @SuppressWarnings("unchecked") @Override public M dropWhile(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return (M) (isEmpty() ? this : createFromEntries(iterator().dropWhile(predicate))); } @SuppressWarnings("unchecked") @Override public M filter(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return (M) this; } else { @@ -263,43 +252,36 @@ public M filter(Predicate> predicate) { @Override public M filterNot(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @Override public M filter(BiPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(t -> predicate.test(t._1, t._2)); } @Override public M filterNot(BiPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterNot(t -> predicate.test(t._1, t._2)); } @Override public M filterKeys(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(t -> predicate.test(t._1)); } @Override public M filterNotKeys(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterNot(t -> predicate.test(t._1)); } @Override public M filterValues(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(t -> predicate.test(t._2)); } @Override public M filterNotValues(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterNot(t -> predicate.test(t._2)); } @@ -369,7 +351,6 @@ public Tuple2 last() { @SuppressWarnings("unchecked") @Override public M merge(Multimap that) { - Objects.requireNonNull(that, "that is null"); if (isEmpty()) { return (M) createFromEntries(that); } else if (that.isEmpty()) { @@ -382,8 +363,6 @@ public M merge(Multimap that) { @SuppressWarnings("unchecked") @Override public M merge(Multimap that, BiFunction, Traversable, Traversable> collisionResolution) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(collisionResolution, "collisionResolution is null"); if (isEmpty()) { return (M) createFromEntries(that); } else if (that.isEmpty()) { @@ -430,7 +409,6 @@ public M orElse(Supplier>> supplier) { @SuppressWarnings("unchecked") @Override public Tuple2 partition(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final java.util.List> left = new java.util.ArrayList<>(); final java.util.List> right = new java.util.ArrayList<>(); for (Tuple2 entry : this) { @@ -442,7 +420,6 @@ public Tuple2 partition(Predicate> predicate) { @SuppressWarnings("unchecked") @Override public M peek(Consumer> action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -452,8 +429,6 @@ public M peek(Consumer> action) { @SuppressWarnings("unchecked") @Override public M replace(Tuple2 currentElement, Tuple2 newElement) { - Objects.requireNonNull(currentElement, "currentElement is null"); - Objects.requireNonNull(newElement, "newElement is null"); return (M) (containsKey(currentElement._1) ? remove(currentElement._1, currentElement._2).put(newElement) : this); } @@ -483,7 +458,6 @@ public M replaceAll(BiFunction function) { @SuppressWarnings("unchecked") @Override public M retainAll(Iterable> elements) { - Objects.requireNonNull(elements, "elements is null"); return (M) createFromEntries(back.flatMap(t -> t._2.map(v -> Tuple.of(t._1, v))).retainAll(elements)); } @@ -513,7 +487,6 @@ public Iterator sliding(int size, int step) { @SuppressWarnings("unchecked") @Override public Tuple2 span(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Tuple2>, Iterator>> t = iterator().span(predicate); return Tuple.of((M) createFromEntries(t._1), (M) createFromEntries(t._2)); } @@ -559,14 +532,12 @@ public M takeRight(int n) { @Override public M takeUntil(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @SuppressWarnings("unchecked") @Override public M takeWhile(Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Multimap taken = createFromEntries(iterator().takeWhile(predicate)); return (M) (taken.length() == length() ? this : taken); } diff --git a/src/main/java/io/vavr/collection/AbstractQueue.java b/src/main/java/io/vavr/collection/AbstractQueue.java index aaec975ca..ba31ca8fc 100644 --- a/src/main/java/io/vavr/collection/AbstractQueue.java +++ b/src/main/java/io/vavr/collection/AbstractQueue.java @@ -77,7 +77,6 @@ public Option> dequeueOption() { */ @SuppressWarnings("unchecked") public Q enqueue(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return enqueueAll(List.of(elements)); } @@ -116,7 +115,6 @@ public Option peekOption() { @Override public Q dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @@ -175,7 +173,6 @@ public Q removeAll(Iterable elements) { @Override public Q takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeUntil(predicate.negate()); } @@ -185,7 +182,6 @@ public Q takeWhile(Predicate predicate) { @SuppressWarnings("unchecked") @Override public Q peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } diff --git a/src/main/java/io/vavr/collection/Array.java b/src/main/java/io/vavr/collection/Array.java index 102eb1c31..ead41c4ee 100644 --- a/src/main/java/io/vavr/collection/Array.java +++ b/src/main/java/io/vavr/collection/Array.java @@ -129,7 +129,6 @@ public static Array of(T element) { @SuppressWarnings("varargs") @SafeVarargs public static Array of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return wrap(copyOf(elements, elements.length)); } @@ -151,7 +150,6 @@ public static Array of(T... elements) { */ @SuppressWarnings("unchecked") public static Array ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof Array) { return (Array) elements; } @@ -175,7 +173,6 @@ public static Array ofAll(Iterable elements) { * @return An Array containing the given elements in the same order. */ public static Array ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return wrap(javaStream.toArray()); } @@ -191,7 +188,6 @@ public static Array ofAll(java.util.stream.Stream javaStream * @throws NullPointerException if elements is null */ public static Array ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -207,7 +203,6 @@ public static Array ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -223,7 +218,6 @@ public static Array ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -238,7 +232,6 @@ public static Array ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -254,7 +247,6 @@ public static Array ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -270,7 +262,6 @@ public static Array ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -286,7 +277,6 @@ public static Array ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -302,7 +292,6 @@ public static Array ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static Array ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -321,7 +310,6 @@ public static Array ofAll(short... elements) { * @throws NullPointerException if {@code f} is null */ public static Array tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return io.vavr.collection.Collections.tabulate(n, f, empty(), Array::of); } @@ -335,7 +323,6 @@ public static Array tabulate(int n, Function Array fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return io.vavr.collection.Collections.fill(n, s, empty(), Array::of); } @@ -673,7 +660,6 @@ public Array append(T element) { @Override public Array appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof Array) { @SuppressWarnings("unchecked") final Array array = (Array) elements; @@ -793,14 +779,12 @@ public Array distinct() { @Override public Array distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final java.util.Set seen = new java.util.TreeSet<>(comparator); return filter(seen::add); } @Override public Array distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); final java.util.Set seen = new java.util.HashSet<>(); return filter(t -> seen.add(keyExtractor.apply(t))); } @@ -825,7 +809,6 @@ public Array dropUntil(Predicate predicate) { @Override public Array dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropUntil(predicate.negate()); } @@ -847,13 +830,11 @@ public Array dropRightUntil(Predicate predicate) { @Override public Array dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @Override public Array filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final java.util.List list = new ArrayList<>(); for (T t : this) { if (predicate.test(t)) { @@ -871,13 +852,11 @@ public Array filter(Predicate predicate) { @Override public Array filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Collections.filterNot(this, predicate); } @Override public Array flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -1015,7 +994,6 @@ public int length() { @Override public Array map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); final Object[] arr = new Object[length()]; for (int i = 0; i < delegate.length; i++) { arr[i] = mapper.apply(get(i)); @@ -1065,7 +1043,6 @@ public Array patch(int from, Iterable that, int replaced) { @Override public Tuple2, Array> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final java.util.List left = new ArrayList<>(), right = new ArrayList<>(); for (T t : this) { (predicate.test(t) ? left : right).add(t); @@ -1075,7 +1052,6 @@ public Tuple2, Array> partition(Predicate predicate) { @Override public Array peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -1126,7 +1102,6 @@ public Array remove(T element) { @Override public Array removeFirst(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); int found = -1; for (int i = 0; i < length(); i++) { final T value = get(i); @@ -1144,7 +1119,6 @@ public Array removeFirst(Predicate predicate) { @Override public Array removeLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); int found = -1; for (int i = length() - 1; i >= 0; i--) { final T value = get(i); @@ -1336,14 +1310,12 @@ public Tuple2, Array> splitAt(int n) { @Override public Tuple2, Array> splitAt(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Array init = takeWhile(predicate.negate()); return Tuple.of(init, drop(init.length())); } @Override public Tuple2, Array> splitAtInclusive(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = 0; i < delegate.length; i++) { final T value = get(i); if (predicate.test(value)) { @@ -1359,7 +1331,6 @@ public Tuple2, Array> splitAtInclusive(Predicate predicat @Override public Tuple2, Array> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Tuple.of(takeWhile(predicate), dropWhile(predicate)); } @@ -1420,7 +1391,6 @@ public Array takeUntil(Predicate predicate) { @Override public Array takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeUntil(predicate.negate()); } @@ -1444,7 +1414,6 @@ public Array takeRightUntil(Predicate predicate) { @Override public Array takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightUntil(predicate.negate()); } @@ -1457,7 +1426,6 @@ public Array takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1474,7 +1442,6 @@ public Array update(int index, T element) { @Override public Array update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); } @@ -1485,14 +1452,11 @@ public Array> zip(Iterable that) { @Override public Array zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWith(that, mapper)); } @Override public Array> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -1503,7 +1467,6 @@ public Array> zipWithIndex() { @Override public Array zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/BitSet.java b/src/main/java/io/vavr/collection/BitSet.java index d7ae93fab..ed32ea297 100644 --- a/src/main/java/io/vavr/collection/BitSet.java +++ b/src/main/java/io/vavr/collection/BitSet.java @@ -92,22 +92,18 @@ public final BitSet of(T... values) { } public BitSet ofAll(Iterable values) { - Objects.requireNonNull(values, "values is null"); return empty().addAll(values); } public BitSet ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return empty().addAll(Iterator.ofAll(javaStream.iterator())); } public BitSet tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return empty().addAll(Collections.tabulate(n, f)); } public BitSet fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return empty().addAll(Collections.fill(n, s)); } } @@ -200,7 +196,6 @@ public static BitSet ofAll(java.util.stream.Stream javaStream) * @throws NullPointerException if elements is null */ public static BitSet ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.withRelations(i -> i != 0, b -> b ? 1 : 0).ofAll(Iterator.ofAll(elements)); } @@ -212,7 +207,6 @@ public static BitSet ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static BitSet ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.withBytes().ofAll(Iterator.ofAll(elements)); } @@ -224,7 +218,6 @@ public static BitSet ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static BitSet ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.withCharacters().ofAll(Iterator.ofAll(elements)); } @@ -236,7 +229,6 @@ public static BitSet ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static BitSet ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.ofAll(Iterator.ofAll(elements)); } @@ -248,7 +240,6 @@ public static BitSet ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static BitSet ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.withLongs().ofAll(Iterator.ofAll(elements)); } @@ -260,7 +251,6 @@ public static BitSet ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static BitSet ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return BitSet.withShorts().ofAll(Iterator.ofAll(elements)); } @@ -358,7 +348,6 @@ public static BitSet rangeClosedBy(long from, long toInclusive, long step) @Override public final SortedSet collect(PartialFunction partialFunction) { - Objects.requireNonNull(partialFunction, "partialFunction is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().collect(partialFunction)); } @@ -386,7 +375,6 @@ public final BitSet distinct() { @Override public final BitSet dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @@ -401,19 +389,16 @@ public final BitSet dropUntil(Predicate predicate) { @Override public final SortedSet flatMap(Comparator comparator, Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().flatMap(mapper)); } @Override public final Set flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? HashSet.empty() : HashSet.ofAll(this).flatMap(mapper); } @Override public final U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); } @@ -476,7 +461,6 @@ public final T last() { @Override public final BitSet peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -490,13 +474,11 @@ public final String stringPrefix() { @Override public final SortedSet map(Comparator comparator, Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().map(mapper)); } @Override public final Set map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? HashSet.empty() : HashSet.ofAll(this).map(mapper); } @@ -575,7 +557,6 @@ public final Option> tailOption() { @Override public final BitSet takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @@ -596,33 +577,27 @@ public final java.util.SortedSet toJavaSet() { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @Override public final BitSet union(Set elements) { - Objects.requireNonNull(elements, "elements is null"); return elements.isEmpty() ? this : addAll(elements); } @Override public final TreeSet> zip(Iterable that) { - Objects.requireNonNull(that, "that is null"); final Comparator> tuple2Comparator = Tuple2.comparator(comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zip(that)); } @Override public final TreeSet zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWith(that, mapper)); } @Override public final TreeSet> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); final Comparator> tuple2Comparator = Tuple2.comparator(comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zipAll(that, thisElem, thatElem)); } @@ -636,7 +611,6 @@ public final TreeSet> zipWithIndex() { @Override public final TreeSet zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWithIndex(mapper)); } @@ -711,13 +685,11 @@ BitSet addElement(int element) { @Override public BitSet distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : createFromAll(iterator().distinctBy(comparator)); } @Override public BitSet distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return isEmpty() ? this : createFromAll(iterator().distinctBy(keyExtractor)); } @@ -745,14 +717,12 @@ public BitSet dropRight(int n) { @Override public BitSet dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final BitSet bitSet = createFromAll(iterator().dropWhile(predicate)); return (bitSet.length() == length()) ? this : bitSet; } @Override public BitSet intersect(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { return this; } else if (elements.isEmpty()) { @@ -806,7 +776,6 @@ public Iterator> sliding(int size, int step) { @Override public Tuple2, BitSet> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return iterator().span(predicate).map(this::createFromAll, this::createFromAll); } @@ -822,14 +791,12 @@ public Tuple2, BitSet> partition(Predicate predicate) { @Override public BitSet filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final BitSet bitSet = createFromAll(iterator().filter(predicate)); return (bitSet.length() == length()) ? this : bitSet; } @Override public BitSet filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final BitSet bitSet = createFromAll(iterator().filterNot(predicate)); return (bitSet.length() == length()) ? this : bitSet; } @@ -846,7 +813,6 @@ public Comparator comparator() { @Override public BitSet takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final BitSet result = createFromAll(iterator().takeWhile(predicate)); return (result.length() == length()) ? this : result; } diff --git a/src/main/java/io/vavr/collection/CharSeq.java b/src/main/java/io/vavr/collection/CharSeq.java index 0730a3e52..bb9be83dd 100644 --- a/src/main/java/io/vavr/collection/CharSeq.java +++ b/src/main/java/io/vavr/collection/CharSeq.java @@ -86,7 +86,6 @@ public static Collector, CharSeq> collector() { */ // DEV-NOTE: Needs to be 'of' instead of 'ofAll' because 'ofAll(CharSeq)' is ambiguous. public static CharSeq of(CharSequence sequence) { - Objects.requireNonNull(sequence, "sequence is null"); if (sequence instanceof CharSeq) { return (CharSeq) sequence; } else { @@ -112,7 +111,6 @@ public static CharSeq of(char character) { * @throws NullPointerException if {@code elements} is null */ public static CharSeq of(char... characters) { - Objects.requireNonNull(characters, "characters is null"); if (characters.length == 0) { return empty(); } else { @@ -134,7 +132,6 @@ public static CharSeq of(char... characters) { */ @SuppressWarnings("unchecked") public static CharSeq ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (Collections.isEmpty(elements)){ return EMPTY; } @@ -162,7 +159,6 @@ public static CharSeq ofAll(Iterable elements) { * @throws NullPointerException if {@code f} is null */ public static CharSeq tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(f.apply(i).charValue()); @@ -398,7 +394,6 @@ public CharSeq append(Character element) { @Override public CharSeq appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (Collections.isEmpty(elements)) { return this; } @@ -456,14 +451,12 @@ public CharSeq distinct() { @Override public CharSeq distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final java.util.Set seen = new java.util.TreeSet<>(comparator); return filter(seen::add); } @Override public CharSeq distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); final java.util.Set seen = new java.util.HashSet<>(); return filter(t -> seen.add(keyExtractor.apply(t))); } @@ -486,7 +479,6 @@ public CharSeq dropUntil(Predicate predicate) { @Override public CharSeq dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropUntil(predicate.negate()); } @@ -503,7 +495,6 @@ public CharSeq dropRight(int n) { @Override public CharSeq dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @@ -514,7 +505,6 @@ public CharSeq dropRightUntil(Predicate predicate) { @Override public CharSeq filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < back.length(); i++) { final char ch = get(i); @@ -533,13 +523,11 @@ public CharSeq filter(Predicate predicate) { @Override public CharSeq filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Collections.filterNot(this, predicate); } @Override public IndexedSeq flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return Vector.empty(); } else { @@ -554,7 +542,6 @@ public IndexedSeq flatMap(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return this; } else { @@ -614,7 +601,6 @@ public CharSeq insert(int index, Character element) { @Override public CharSeq insertAll(int index, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (index < 0) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements)"); } @@ -650,7 +636,6 @@ public CharSeq intersperse(Character element) { @Override public IndexedSeq map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); IndexedSeq result = Vector.empty(); for (int i = 0; i < length(); i++) { result = result.append(mapper.apply(get(i))); @@ -717,7 +702,6 @@ public CharSeq patch(int from, Iterable that, int replaced) } public CharSeq mapChars(CharUnaryOperator mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return this; } else { @@ -731,7 +715,6 @@ public CharSeq mapChars(CharUnaryOperator mapper) { @Override public Tuple2 partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Tuple.of(EMPTY, EMPTY); } @@ -752,7 +735,6 @@ public Tuple2 partition(Predicate predicate @Override public CharSeq peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(get(0)); } @@ -786,7 +768,6 @@ public CharSeq prepend(Character element) { @Override public CharSeq prependAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (Collections.isEmpty(elements)) { return this; } else if (isEmpty()) { @@ -821,7 +802,6 @@ public CharSeq remove(Character element) { @Override public CharSeq removeFirst(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final StringBuilder sb = new StringBuilder(); boolean found = false; for (int i = 0; i < back.length(); i++) { @@ -840,7 +820,6 @@ public CharSeq removeFirst(Predicate predicate) { @Override public CharSeq removeLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = length() - 1; i >= 0; i--) { if (predicate.test(get(i))) { return removeAt(i); @@ -990,7 +969,6 @@ public CharSeq sorted() { @Override public CharSeq sorted(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : toJavaStream().sorted(comparator).collect(CharSeq.collector()); } @@ -1006,7 +984,6 @@ public CharSeq sortBy(Comparator comparator, Function span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < length(); i++) { final char c = get(i); @@ -1065,7 +1042,6 @@ public CharSeq takeUntil(Predicate predicate) { @Override public CharSeq takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeUntil(predicate.negate()); } @@ -1087,7 +1063,6 @@ public CharSeq takeRightUntil(Predicate predicate) { @Override public CharSeq takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightUntil(predicate.negate()); } @@ -1100,7 +1075,6 @@ public CharSeq takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1116,7 +1090,6 @@ public CharSeq update(int index, Character element) { @Override public CharSeq update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); final char c = updater.apply(get(index)); return update(index, c); } @@ -1128,8 +1101,6 @@ public IndexedSeq> zip(Iterable that) { @Override public IndexedSeq zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); IndexedSeq result = Vector.empty(); final io.vavr.collection.Iterator list1 = iterator(); final java.util.Iterator list2 = that.iterator(); @@ -1141,7 +1112,6 @@ public IndexedSeq zipWith(Iterable that, BiFunction IndexedSeq> zipAll(Iterable that, Character thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); IndexedSeq> result = Vector.empty(); final io.vavr.collection.Iterator list1 = iterator(); final java.util.Iterator list2 = that.iterator(); @@ -1160,7 +1130,6 @@ public IndexedSeq> zipWithIndex() { @Override public IndexedSeq zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); IndexedSeq result = Vector.empty(); for (int i = 0; i < length(); i++) { result = result.append(mapper.apply(get(i), i)); @@ -1196,7 +1165,6 @@ public Tuple2 splitAt(int n) { @Override public Tuple2 splitAt(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Tuple.of(EMPTY, EMPTY); } @@ -1214,7 +1182,6 @@ public Tuple2 splitAt(Predicate predicate) @Override public Tuple2 splitAtInclusive(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Tuple.of(EMPTY, EMPTY); } diff --git a/src/main/java/io/vavr/collection/Collections.java b/src/main/java/io/vavr/collection/Collections.java index 74fdefcb4..dc724f07f 100644 --- a/src/main/java/io/vavr/collection/Collections.java +++ b/src/main/java/io/vavr/collection/Collections.java @@ -54,7 +54,6 @@ static boolean areEqual(Iterable iterable1, Iterable iterable2) { } static > C asJava(C source, Consumer> action, ChangePolicy changePolicy) { - Objects.requireNonNull(action, "action is null"); final ListView view = JavaConverters.asJava(source, changePolicy); action.accept(view); return view.getDelegate(); @@ -75,7 +74,6 @@ static > Iterator crossProduct(S empty, S seq, int power) // see https://github.com/vavr-io/vavr/issues/2007 @SuppressWarnings("unchecked") static > S dropRightUntil(S seq, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = seq.length() - 1; i >= 0; i--) { if (predicate.test(seq.get(i))) { return (S) seq.take(i + 1); @@ -89,7 +87,6 @@ static > S dropRightUntil(S seq, Predicate // see https://github.com/vavr-io/vavr/issues/2007 @SuppressWarnings("unchecked") static > S dropUntil(S seq, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = 0; i < seq.length(); i++) { if (predicate.test(seq.get(i))) { return (S) seq.drop(i); @@ -171,7 +168,6 @@ static boolean equals(Set source, Object object) { } static Iterator fill(int n, Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return tabulate(n, ignored -> supplier.get()); } @@ -190,15 +186,10 @@ static Iterator fillObject(int n, T element) { } static , T> C fill(int n, Supplier s, C empty, Function of) { - Objects.requireNonNull(s, "s is null"); - Objects.requireNonNull(empty, "empty is null"); - Objects.requireNonNull(of, "of is null"); return tabulate(n, anything -> s.get(), empty, of); } static , T> C fillObject(int n, T element, C empty, Function of) { - Objects.requireNonNull(empty, "empty is null"); - Objects.requireNonNull(of, "of is null"); if (n <= 0) { return empty; } else { @@ -211,7 +202,6 @@ static , T> C fillObject(int n, T element, C empty, Fun @SuppressWarnings("unchecked") static , T> C filterNot(C source, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (source.isEmpty()) { return source; } else { @@ -227,8 +217,6 @@ static > Seq group(S source, Supplier supplier) { } static > Map groupBy(Traversable source, Function classifier, Function, R> mapper) { - Objects.requireNonNull(classifier, "classifier is null"); - Objects.requireNonNull(mapper, "mapper is null"); Map results = LinkedHashMap.empty(); for (java.util.Map.Entry> entry : groupBy(source, classifier)) { results = results.put(entry.getKey(), mapper.apply(entry.getValue())); @@ -299,9 +287,6 @@ static T last(Traversable source){ @SuppressWarnings("unchecked") static > U mapKeys(Map source, U zero, Function keyMapper, BiFunction valueMerge) { - Objects.requireNonNull(zero, "zero is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMerge, "valueMerge is null"); return source.foldLeft(zero, (acc, entry) -> { final K2 k2 = keyMapper.apply(entry._1); final V v2 = entry._2; @@ -313,7 +298,6 @@ static > U mapKeys(Map source, U zero, Func static , T> Tuple2 partition(C collection, Function, C> creator, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final java.util.List left = new java.util.ArrayList<>(); final java.util.List right = new java.util.ArrayList<>(); for (T element : collection) { @@ -324,7 +308,6 @@ static , T> Tuple2 partition(C collection, Functi @SuppressWarnings("unchecked") static , T> C removeAll(C source, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (source.isEmpty()) { return source; } else { @@ -344,7 +327,6 @@ static , T> C removeAll(C source, T element) { @SuppressWarnings("unchecked") static , T> C retainAll(C source, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (source.isEmpty()) { return source; } else { @@ -415,21 +397,17 @@ static > C rotateRight(C source, int n) { static > R scanLeft(Traversable source, U zero, BiFunction operation, Function, R> finisher) { - Objects.requireNonNull(operation, "operation is null"); final Iterator iterator = source.iterator().scanLeft(zero, operation); return finisher.apply(iterator); } static > R scanRight(Traversable source, U zero, BiFunction operation, Function, R> finisher) { - Objects.requireNonNull(operation, "operation is null"); final Iterator reversedElements = reverseIterator(source); return scanLeft(reversedElements, zero, (u, t) -> operation.apply(t, u), us -> finisher.apply(reverseIterator(us))); } static > R sortBy(Seq source, Comparator comparator, Function mapper, Collector collector) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(mapper, "mapper is null"); return source.toJavaStream() .sorted((e1, e2) -> comparator.compare(mapper.apply(e1), mapper.apply(e2))) .collect(collector); @@ -464,7 +442,6 @@ static void subSequenceRangeCheck(int beginIndex, int endIndex, int length) { } static Iterator tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); if (n <= 0) { return Iterator.empty(); } else { @@ -489,9 +466,6 @@ public T next() { } static , T> C tabulate(int n, Function f, C empty, Function of) { - Objects.requireNonNull(f, "f is null"); - Objects.requireNonNull(empty, "empty is null"); - Objects.requireNonNull(of, "of is null"); if (n <= 0) { return empty; } else { @@ -509,7 +483,6 @@ static , T> C tabulate(int n, Function> S takeRightUntil(S seq, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = seq.length() - 1; i >= 0; i--) { if (predicate.test(seq.get(i))) { return (S) seq.drop(i + 1); @@ -523,7 +496,6 @@ static > S takeRightUntil(S seq, Predicate // see https://github.com/vavr-io/vavr/issues/2007 @SuppressWarnings("unchecked") static > S takeUntil(S seq, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = 0; i < seq.length(); i++) { if (predicate.test(seq.get(i))) { return (S) seq.take(i); @@ -533,7 +505,6 @@ static > S takeUntil(S seq, Predicate pred } static , V extends Seq> V transpose(V matrix, Function, V> rowFactory, Function columnFactory) { - Objects.requireNonNull(matrix, "matrix is null"); if (matrix.isEmpty() || (matrix.length() == 1 && matrix.head().length() <= 1)) { return matrix; } else { diff --git a/src/main/java/io/vavr/collection/Foldable.java b/src/main/java/io/vavr/collection/Foldable.java index 91fcf5cd4..bd23d23fc 100644 --- a/src/main/java/io/vavr/collection/Foldable.java +++ b/src/main/java/io/vavr/collection/Foldable.java @@ -83,7 +83,6 @@ public interface Foldable { * @throws NullPointerException if {@code combine} is null */ default T fold(T zero, BiFunction combine) { - Objects.requireNonNull(combine, "combine is null"); return foldLeft(zero, combine); } @@ -133,7 +132,6 @@ default T fold(T zero, BiFunction combine) { * @throws NullPointerException if {@code op} is null */ default T reduce(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return reduceLeft(op); } @@ -146,7 +144,6 @@ default T reduce(BiFunction op) { * @throws NullPointerException if {@code op} is null */ default Option reduceOption(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return reduceLeftOption(op); } diff --git a/src/main/java/io/vavr/collection/HashMap.java b/src/main/java/io/vavr/collection/HashMap.java index 5f5dc4861..fa9b4056e 100644 --- a/src/main/java/io/vavr/collection/HashMap.java +++ b/src/main/java/io/vavr/collection/HashMap.java @@ -77,7 +77,6 @@ public static Collector, ArrayList>, HashMap Collector, HashMap> collector(Function keyMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); return HashMap.collector(keyMapper, v -> v); } @@ -94,8 +93,6 @@ public static Collector, HashMap> coll */ public static Collector, HashMap> collector( Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return Collections.toListAndThen(arr -> HashMap.ofEntries(Iterator.ofAll(arr) .map(t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))))); } @@ -141,7 +138,6 @@ public static HashMap of(Tuple2 entry) { * @return A new Map containing the given map */ public static HashMap ofAll(java.util.Map map) { - Objects.requireNonNull(map, "map is null"); HashArrayMappedTrie tree = HashArrayMappedTrie.empty(); for (java.util.Map.Entry entry : map.entrySet()) { tree = tree.put(entry.getKey(), entry.getValue()); @@ -414,7 +410,6 @@ public static HashMap of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, */ @SuppressWarnings("unchecked") public static HashMap tabulate(int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return ofEntries(Collections.tabulate(n, (Function>) f)); } @@ -430,7 +425,6 @@ public static HashMap tabulate(int n, Function HashMap fill(int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return ofEntries(Collections.fill(n, (Supplier>) s)); } @@ -444,7 +438,6 @@ public static HashMap fill(int n, Supplier HashMap ofEntries(java.util.Map.Entry... entries) { - Objects.requireNonNull(entries, "entries is null"); HashArrayMappedTrie trie = HashArrayMappedTrie.empty(); for (java.util.Map.Entry entry : entries) { trie = trie.put(entry.getKey(), entry.getValue()); @@ -462,7 +455,6 @@ public static HashMap ofEntries(java.util.Map.Entry HashMap ofEntries(Tuple2... entries) { - Objects.requireNonNull(entries, "entries is null"); HashArrayMappedTrie trie = HashArrayMappedTrie.empty(); for (Tuple2 entry : entries) { trie = trie.put(entry._1, entry._2); @@ -480,7 +472,6 @@ public static HashMap ofEntries(Tuple2... */ @SuppressWarnings("unchecked") public static HashMap ofEntries(Iterable> entries) { - Objects.requireNonNull(entries, "entries is null"); if (entries instanceof HashMap) { return (HashMap) entries; } else { @@ -494,8 +485,6 @@ public static HashMap ofEntries(Iterable HashMap bimap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return HashMap.ofEntries(entries); } @@ -592,7 +581,6 @@ public HashMap filterNotValues(Predicate predicate) { @Override public HashMap flatMap(BiFunction>> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(HashMap. empty(), (acc, entry) -> { for (Tuple2 mappedEntry : mapper.apply(entry._1, entry._2)) { acc = acc.put(mappedEntry); @@ -691,13 +679,11 @@ public Tuple2 last() { @Override public HashMap map(BiFunction> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(HashMap.empty(), (acc, entry) -> acc.put(entry.map(mapper))); } @Override public HashMap mapKeys(Function keyMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); return map((k, v) -> Tuple.of(keyMapper.apply(k), v)); } @@ -708,7 +694,6 @@ public HashMap mapKeys(Function keyMapper, @Override public HashMap mapValues(Function valueMapper) { - Objects.requireNonNull(valueMapper, "valueMapper is null"); return map((k, v) -> Tuple.of(k, valueMapper.apply(v))); } @@ -772,7 +757,6 @@ public HashMap remove(K key) { @Override public HashMap removeAll(Iterable keys) { - Objects.requireNonNull(keys, "keys is null"); HashArrayMappedTrie result = trie; for (K key : keys) { result = result.remove(key); @@ -814,7 +798,6 @@ public HashMap replaceAll(BiFunction fu @Override public HashMap retainAll(Iterable> elements) { - Objects.requireNonNull(elements, "elements is null"); HashArrayMappedTrie tree = HashArrayMappedTrie.empty(); for (Tuple2 entry : elements) { if (contains(entry)) { diff --git a/src/main/java/io/vavr/collection/HashMultimap.java b/src/main/java/io/vavr/collection/HashMultimap.java index 44fd3a810..6a27d5ef7 100644 --- a/src/main/java/io/vavr/collection/HashMultimap.java +++ b/src/main/java/io/vavr/collection/HashMultimap.java @@ -96,7 +96,6 @@ public HashMultimap empty() { * @return A new HashMultimap containing the given entries. */ public HashMultimap ofEntries(Iterable> entries) { - Objects.requireNonNull(entries, "entries is null"); HashMultimap result = empty(); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -114,7 +113,6 @@ public HashMultimap ofEntries(Iterable HashMultimap ofEntries(Tuple2... entries) { - Objects.requireNonNull(entries, "entries is null"); HashMultimap result = empty(); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -132,7 +130,6 @@ public final HashMultimap ofEntries(Tuple2 HashMultimap ofEntries(java.util.Map.Entry... entries) { - Objects.requireNonNull(entries, "entries is null"); HashMultimap result = empty(); for (java.util.Map.Entry entry : entries) { result = result.put(entry.getKey(), entry.getValue()); @@ -197,7 +194,6 @@ public HashMultimap ofAll(java.util.stream.Stream HashMultimap tabulate(int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return ofEntries(Collections.tabulate(n, (Function>) f)); } @@ -213,7 +209,6 @@ public HashMultimap tabulate(int n, Function HashMultimap fill(int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return ofEntries(Collections.fill(n, (Supplier>) s)); } diff --git a/src/main/java/io/vavr/collection/HashSet.java b/src/main/java/io/vavr/collection/HashSet.java index b7f678ad9..0c0b30e3f 100644 --- a/src/main/java/io/vavr/collection/HashSet.java +++ b/src/main/java/io/vavr/collection/HashSet.java @@ -108,7 +108,6 @@ public static HashSet of(T element) { */ @SafeVarargs public static HashSet of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); HashArrayMappedTrie tree = HashArrayMappedTrie.empty(); for (T element : elements) { tree = tree.put(element, element); @@ -127,7 +126,6 @@ public static HashSet of(T... elements) { * @throws NullPointerException if {@code f} is null */ public static HashSet tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return Collections.tabulate(n, f, HashSet.empty(), HashSet::of); } @@ -141,7 +139,6 @@ public static HashSet tabulate(int n, Function HashSet fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return Collections.fill(n, s, HashSet.empty(), HashSet::of); } @@ -154,7 +151,6 @@ public static HashSet fill(int n, Supplier s) { */ @SuppressWarnings("unchecked") public static HashSet ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof HashSet) { return (HashSet) elements; } else { @@ -171,7 +167,6 @@ public static HashSet ofAll(Iterable elements) { * @return A HashSet containing the given elements in the same order. */ public static HashSet ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return HashSet.ofAll(Iterator.ofAll(javaStream.iterator())); } @@ -183,7 +178,6 @@ public static HashSet ofAll(java.util.stream.Stream javaStre * @throws NullPointerException if elements is null */ public static HashSet ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -195,7 +189,6 @@ public static HashSet ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -207,7 +200,6 @@ public static HashSet ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -219,7 +211,6 @@ public static HashSet ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -231,7 +222,6 @@ public static HashSet ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -243,7 +233,6 @@ public static HashSet ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -255,7 +244,6 @@ public static HashSet ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -267,7 +255,6 @@ public static HashSet ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static HashSet ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return HashSet.ofAll(Iterator.ofAll(elements)); } @@ -486,7 +473,6 @@ public HashSet add(T element) { @Override public HashSet addAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof HashSet) { @SuppressWarnings("unchecked") final HashSet set = (HashSet) elements; @@ -512,7 +498,6 @@ public boolean contains(T element) { @Override public HashSet diff(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() || elements.isEmpty()) { return this; } else { @@ -527,13 +512,11 @@ public HashSet distinct() { @Override public HashSet distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return HashSet.ofAll(iterator().distinctBy(comparator)); } @Override public HashSet distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return HashSet.ofAll(iterator().distinctBy(keyExtractor)); } @@ -553,20 +536,17 @@ public HashSet dropRight(int n) { @Override public HashSet dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public HashSet dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final HashSet dropped = HashSet.ofAll(iterator().dropWhile(predicate)); return dropped.length() == length() ? this : dropped; } @Override public HashSet filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final HashSet filtered = HashSet.ofAll(iterator().filter(predicate)); if (filtered.isEmpty()) { @@ -580,13 +560,11 @@ public HashSet filter(Predicate predicate) { @Override public HashSet filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @Override public HashSet flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -641,7 +619,6 @@ public Option> initOption() { @Override public HashSet intersect(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() || elements.isEmpty()) { return empty(); } else { @@ -702,7 +679,6 @@ public int length() { @Override public HashSet map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -736,7 +712,6 @@ public Tuple2, HashSet> partition(Predicate predicate) @Override public HashSet peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(iterator().head()); } @@ -805,7 +780,6 @@ public Iterator> sliding(int size, int step) { @Override public Tuple2, HashSet> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Tuple2, Iterator> t = iterator().span(predicate); return Tuple.of(HashSet.ofAll(t._1), HashSet.ofAll(t._2)); } @@ -845,13 +819,11 @@ public HashSet takeRight(int n) { @Override public HashSet takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @Override public HashSet takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final HashSet taken = HashSet.ofAll(iterator().takeWhile(predicate)); return taken.length() == length() ? this : taken; } @@ -865,7 +837,6 @@ public HashSet takeWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -877,7 +848,6 @@ public java.util.HashSet toJavaSet() { @SuppressWarnings("unchecked") @Override public HashSet union(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { if (elements instanceof HashSet) { return (HashSet) elements; @@ -903,14 +873,11 @@ public HashSet> zip(Iterable that) { @Override public HashSet zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return HashSet.ofAll(iterator().zipWith(that, mapper)); } @Override public HashSet> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return HashSet.ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -921,7 +888,6 @@ public HashSet> zipWithIndex() { @Override public HashSet zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return HashSet.ofAll(iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/IndexedSeq.java b/src/main/java/io/vavr/collection/IndexedSeq.java index 1c266510c..2a263cfaa 100644 --- a/src/main/java/io/vavr/collection/IndexedSeq.java +++ b/src/main/java/io/vavr/collection/IndexedSeq.java @@ -130,7 +130,6 @@ public boolean isDefinedAt(Integer index) { @Override default boolean endsWith(Seq that) { - Objects.requireNonNull(that, "that is null"); if (that instanceof IndexedSeq) { int i = length() - 1; int j = that.length() - 1; @@ -171,7 +170,6 @@ default boolean endsWith(Seq that) { @Override default int indexWhere(Predicate predicate, int from) { - Objects.requireNonNull(predicate, "predicate is null"); int start = Math.max(from, 0); int n = start + segmentLength(predicate.negate(), start); return (n >= length()) ? -1 : n; @@ -179,7 +177,6 @@ default int indexWhere(Predicate predicate, int from) { @Override default int indexOfSlice(Iterable that, int from) { - Objects.requireNonNull(that, "that is null"); return IndexedSeqModule.Slice.indexOfSlice(this, that, from); } @@ -215,13 +212,11 @@ default T last() { @Override default int lastIndexOfSlice(Iterable that, int end) { - Objects.requireNonNull(that, "that is null"); return IndexedSeqModule.Slice.lastIndexOfSlice(this, that, end); } @Override default int lastIndexWhere(Predicate predicate, int end) { - Objects.requireNonNull(predicate, "predicate is null"); int i = Math.min(end, length() - 1); while (i >= 0 && !predicate.test(this.get(i))) { i--; @@ -326,7 +321,6 @@ public T next() { @Override default int segmentLength(Predicate predicate, int from) { - Objects.requireNonNull(predicate, "predicate is null"); int len = length(); int i = from; while (i < len && predicate.test(this.get(i))) { @@ -370,7 +364,6 @@ default int segmentLength(Predicate predicate, int from) { @Override default boolean startsWith(Iterable that, int offset) { - Objects.requireNonNull(that, "that is null"); if (offset < 0) { return false; } if (that instanceof IndexedSeq) { IndexedSeq thatIndexedSeq = (IndexedSeq) that; @@ -484,7 +477,6 @@ default int search(T element) { */ @Override default int search(T element, Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); IntUnaryOperator comparison = midIndex -> { T midVal = get(midIndex); return comparator.compare(midVal, element); diff --git a/src/main/java/io/vavr/collection/Iterator.java b/src/main/java/io/vavr/collection/Iterator.java index fa2a8d4bd..dfd34d38c 100644 --- a/src/main/java/io/vavr/collection/Iterator.java +++ b/src/main/java/io/vavr/collection/Iterator.java @@ -74,7 +74,6 @@ public interface Iterator extends java.util.Iterator, Traversable { @SuppressWarnings("varargs") @SafeVarargs static Iterator concat(Iterable... iterables) { - Objects.requireNonNull(iterables, "iterables is null"); if (iterables.length == 0) { return empty(); } else { @@ -90,7 +89,6 @@ static Iterator concat(Iterable... iterables) { * @return A new {@code io.vavr.collection.Iterator} */ static Iterator concat(Iterable> iterables) { - Objects.requireNonNull(iterables, "iterables is null"); final Iterator> iterators = ofAll(iterables).map(Iterator::ofAll); if (!iterators.hasNext()) { return empty(); @@ -154,7 +152,6 @@ static Iterator of(T element) { @SafeVarargs @SuppressWarnings("varargs") static Iterator of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return (elements.length == 0) ? empty() : new ArrayIterator<>(elements); } @@ -168,7 +165,6 @@ static Iterator of(T... elements) { */ @SuppressWarnings("unchecked") static Iterator ofAll(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); if (iterable instanceof Iterator) { return (Iterator) iterable; } else { @@ -186,7 +182,6 @@ static Iterator ofAll(Iterable iterable) { */ @SuppressWarnings("unchecked") static Iterator ofAll(java.util.Iterator iterator) { - Objects.requireNonNull(iterator, "iterator is null"); if (iterator instanceof Iterator) { return (Iterator) iterator; } else { @@ -216,7 +211,6 @@ public T next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -243,7 +237,6 @@ public Boolean next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -270,7 +263,6 @@ public Byte next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -297,7 +289,6 @@ public Character next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -324,7 +315,6 @@ public Double next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -351,7 +341,6 @@ public Float next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -378,7 +367,6 @@ public Integer next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -405,7 +393,6 @@ public Long next() { * @throws NullPointerException if elements is null */ static Iterator ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return new Iterator() { int i = 0; @@ -435,7 +422,6 @@ public Short next() { * @throws NullPointerException if {@code f} is null */ static Iterator tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return io.vavr.collection.Collections.tabulate(n, f); } @@ -449,7 +435,6 @@ static Iterator tabulate(int n, Function f) * @throws NullPointerException if {@code s} is null */ static Iterator fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return io.vavr.collection.Collections.fill(n, s); } @@ -939,7 +924,6 @@ public Long next() { * @return A new {@code Iterator} */ static Iterator continually(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return new Iterator() { @Override public boolean hasNext() { @@ -966,7 +950,6 @@ public T next() { * @throws NullPointerException if supplier produces null value */ static Iterator iterate(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return new Iterator() { Option nextOption; @@ -1000,7 +983,6 @@ public T next() { * @return A new {@code Iterator} */ static Iterator iterate(T seed, Function f) { - Objects.requireNonNull(f, "f is null"); return new Iterator() { Function nextFunc = s -> { nextFunc = f; @@ -1051,14 +1033,16 @@ public T next() { // -- Additional methods of Iterator @Override + @SuppressWarnings("unchecked") default Iterator collect(PartialFunction partialFunction) { - Objects.requireNonNull(partialFunction, "partialFunction is null"); + if (!hasNext()) { + return (Iterator)this; + } return filter(partialFunction::isDefinedAt).map(partialFunction); } // DEV-NOTE: cannot use arg Iterable, it would be ambiguous default Iterator concat(java.util.Iterator that) { - Objects.requireNonNull(that, "that is null"); if (!that.hasNext()) { return this; } else if (!hasNext()) { @@ -1114,7 +1098,6 @@ public T next() { * @throws NullPointerException if {@code f} is null */ default U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1125,8 +1108,6 @@ default Iterator> zip(Iterable that) { @Override default Iterator zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -1151,7 +1132,6 @@ public R next() { @Override default Iterator> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); final java.util.Iterator thatIt = that.iterator(); if (isEmpty() && !thatIt.hasNext()) { return empty(); @@ -1183,7 +1163,6 @@ default Iterator> zipWithIndex() { @Override default Iterator zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -1210,8 +1189,6 @@ public U next() { @Override default Tuple2, Iterator> unzip( Function unzipper1, Function unzipper2) { - Objects.requireNonNull(unzipper1, "unzipper1 is null"); - Objects.requireNonNull(unzipper2, "unzipper2 is null"); if (!hasNext()) { return Tuple.of(empty(), empty()); } else { @@ -1227,9 +1204,6 @@ default Tuple3, Iterator, Iterator> unzip3( Function unzipper1, Function unzipper2, Function unzipper3) { - Objects.requireNonNull(unzipper1, "unzipper1 is null"); - Objects.requireNonNull(unzipper2, "unzipper2 is null"); - Objects.requireNonNull(unzipper3, "unzipper3 is null"); if (!hasNext()) { return Tuple.of(empty(), empty(), empty()); } else { @@ -1295,7 +1269,6 @@ static Iterator unfold(T seed, Function Iterator unfoldLeft(T seed, Function>> f) { - Objects.requireNonNull(f, "f is null"); return Stream. ofAll( unfoldRight(seed, f.andThen(tupleOpt -> tupleOpt.map(t -> Tuple.of(t._2, t._1))))) .reverse().iterator(); @@ -1327,7 +1300,6 @@ static Iterator unfoldLeft(T seed, Function Iterator unfoldRight(T seed, Function>> f) { - Objects.requireNonNull(f, "the unfold iterating function is null"); return new Iterator() { private Option> nextVal = f.apply(seed); @@ -1361,7 +1333,6 @@ default Iterator distinct() { @Override default Iterator distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); if (!hasNext()) { return empty(); } else { @@ -1371,7 +1342,6 @@ default Iterator distinctBy(Comparator comparator) { @Override default Iterator distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); if (!hasNext()) { return empty(); } else { @@ -1451,13 +1421,11 @@ public T next() { @Override default Iterator dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override default Iterator dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (!hasNext()) { return empty(); } else { @@ -1477,7 +1445,6 @@ default Iterator dropWhile(Predicate predicate) { */ @Override default Iterator filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (!hasNext()) { return empty(); } else { @@ -1518,13 +1485,11 @@ public T next() { */ @Override default Iterator filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @Override default Option findLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); T last = null; while (hasNext()) { final T elem = next(); @@ -1545,7 +1510,6 @@ default Option findLast(Predicate predicate) { // DEV-NOTE: the shorter implementation `concat(map(mapper))` does not perform well @Override default Iterator flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (!hasNext()) { return empty(); } else { @@ -1577,7 +1541,6 @@ public U next() { @Override default U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); return Stream.ofAll(this).foldRight(zero, f); } @@ -1682,7 +1645,6 @@ default int length() { */ @Override default Iterator map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (!hasNext()) { return empty(); } else { @@ -1730,7 +1692,6 @@ default Iterator orElse(Supplier> supplier) { @Override default Tuple2, Iterator> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (!hasNext()) { return Tuple.of(empty(), empty()); } else { @@ -1741,7 +1702,6 @@ default Tuple2, Iterator> partition(Predicate predicat @Override default Iterator peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!hasNext()) { return empty(); } else { @@ -1767,7 +1727,6 @@ public T next() { @Override default T reduceLeft(BiFunction op) { - Objects.requireNonNull(op, "op is null"); if (isEmpty()) { throw new NoSuchElementException("reduceLeft on Nil"); } else { @@ -1781,7 +1740,6 @@ default T reduceLeft(BiFunction op) { @Override default T reduceRight(BiFunction op) { - Objects.requireNonNull(op, "op is null"); if (isEmpty()) { throw new NoSuchElementException("reduceRight on Nil"); } else { @@ -1862,7 +1820,6 @@ default Traversable scan(T zero, BiFunction Iterator scanLeft(U zero, BiFunction operation) { - Objects.requireNonNull(operation, "operation is null"); if (isEmpty()) { return of(zero); } else { @@ -1897,7 +1854,6 @@ public U next() { // not lazy! @Override default Iterator scanRight(U zero, BiFunction operation) { - Objects.requireNonNull(operation, "operation is null"); if (isEmpty()) { return of(zero); } else { @@ -1907,7 +1863,6 @@ default Iterator scanRight(U zero, BiFunction> slideBy(Function classifier) { - Objects.requireNonNull(classifier, "classifier is null"); if (!hasNext()) { return empty(); } else { @@ -1954,7 +1909,6 @@ default Iterator> sliding(int size, int step) { @Override default Tuple2, Iterator> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (!hasNext()) { return Tuple.of(empty(), empty()); } else { @@ -2057,13 +2011,11 @@ public T next() { @Override default Iterator takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @Override default Iterator takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (!hasNext()) { return empty(); } else { @@ -2139,7 +2091,6 @@ public T next() { @Override public void forEachRemaining(Consumer action) { - Objects.requireNonNull(action); while (index < elements.length) { action.accept(elements[index++]); } @@ -2372,7 +2323,6 @@ public Object next() { @Override public void forEachRemaining(Consumer action) { - Objects.requireNonNull(action); } @Override @@ -2483,7 +2433,6 @@ public T next() { @Override public void forEachRemaining(Consumer action) { - Objects.requireNonNull(action); if (hasNext) { action.accept(element); hasNext = false; diff --git a/src/main/java/io/vavr/collection/JavaConverters.java b/src/main/java/io/vavr/collection/JavaConverters.java index 509a0d91b..ee88d1a3c 100644 --- a/src/main/java/io/vavr/collection/JavaConverters.java +++ b/src/main/java/io/vavr/collection/JavaConverters.java @@ -130,14 +130,12 @@ public void add(int index, T element) { @SuppressWarnings("unchecked") @Override public boolean addAll(Collection collection) { - Objects.requireNonNull(collection, "collection is null"); return setDelegateAndCheckChanged(() -> (C) getDelegate().appendAll(collection)); } @SuppressWarnings("unchecked") @Override public boolean addAll(int index, Collection collection) { - Objects.requireNonNull(collection, "collection is null"); return setDelegateAndCheckChanged(() -> (C) getDelegate().insertAll(index, collection)); } @@ -159,7 +157,6 @@ public boolean contains(Object obj) { @Override public boolean containsAll(Collection collection) { - Objects.requireNonNull(collection, "collection is null"); @SuppressWarnings("unchecked") final Collection that = (Collection) collection; return getDelegate().containsAll(that); } @@ -217,7 +214,6 @@ public boolean remove(Object obj) { @SuppressWarnings("unchecked") @Override public boolean removeAll(Collection collection) { - Objects.requireNonNull(collection, "collection is null"); @SuppressWarnings("unchecked") final Collection that = (Collection) collection; return setDelegateAndCheckChanged(() -> (C) getDelegate().removeAll(that)); } @@ -225,7 +221,6 @@ public boolean removeAll(Collection collection) { @SuppressWarnings("unchecked") @Override public boolean retainAll(Collection collection) { - Objects.requireNonNull(collection, "collection is null"); @SuppressWarnings("unchecked") final Collection that = (Collection) collection; return setDelegateAndCheckChanged(() -> (C) getDelegate().retainAll(that)); } @@ -244,7 +239,6 @@ public int size() { @SuppressWarnings("unchecked") @Override public void sort(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); if (isEmpty()) { return; } @@ -264,7 +258,6 @@ public Object[] toArray() { @SuppressWarnings("unchecked") @Override public U[] toArray(U[] array) { - Objects.requireNonNull(array, "array is null"); final U[] target; final C delegate = getDelegate(); final int length = delegate.length(); @@ -362,7 +355,6 @@ public void remove() { @Override public void forEachRemaining(Consumer consumer) { - Objects.requireNonNull(consumer, "consumer is null"); checkForComodification(); if (nextIndex >= list.size()) { return; diff --git a/src/main/java/io/vavr/collection/LinearSeq.java b/src/main/java/io/vavr/collection/LinearSeq.java index 2bd1401ed..1eddd806f 100644 --- a/src/main/java/io/vavr/collection/LinearSeq.java +++ b/src/main/java/io/vavr/collection/LinearSeq.java @@ -148,13 +148,11 @@ public boolean isDefinedAt(Integer index) { @Override default int indexOfSlice(Iterable that, int from) { - Objects.requireNonNull(that, "that is null"); return LinearSeqModule.Slice.indexOfSlice(this, that, from); } @Override default int indexWhere(Predicate predicate, int from) { - Objects.requireNonNull(predicate, "predicate is null"); int i = from; LinearSeq these = drop(from); while (!these.isEmpty()) { @@ -184,13 +182,11 @@ default int indexWhere(Predicate predicate, int from) { @Override default int lastIndexOfSlice(Iterable that, int end) { - Objects.requireNonNull(that, "that is null"); return LinearSeqModule.Slice.lastIndexOfSlice(this, that, end); } @Override default int lastIndexWhere(Predicate predicate, int end) { - Objects.requireNonNull(predicate, "predicate is null"); int i = 0; LinearSeq these = this; int last = -1; @@ -292,7 +288,6 @@ default Iterator reverseIterator() { @Override default int segmentLength(Predicate predicate, int from) { - Objects.requireNonNull(predicate, "predicate is null"); int i = 0; LinearSeq these = this.drop(from); while (!these.isEmpty() && predicate.test(these.head())) { @@ -413,7 +408,6 @@ default int search(T element) { */ @Override default int search(T element, Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final ToIntFunction comparison = current -> comparator.compare(element, current); return LinearSeqModule.Search.linearSearch(this, comparison); } diff --git a/src/main/java/io/vavr/collection/LinkedHashMap.java b/src/main/java/io/vavr/collection/LinkedHashMap.java index b8121a6ac..1d2ad7a9d 100644 --- a/src/main/java/io/vavr/collection/LinkedHashMap.java +++ b/src/main/java/io/vavr/collection/LinkedHashMap.java @@ -76,7 +76,6 @@ public static Collector, ArrayList>, LinkedHash * @return A {@link LinkedHashMap} Collector. */ public static Collector, LinkedHashMap> collector(Function keyMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); return LinkedHashMap.collector(keyMapper, v -> v); } @@ -93,8 +92,6 @@ public static Collector, LinkedHashMap */ public static Collector, LinkedHashMap> collector( Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return Collections.toListAndThen(arr -> LinkedHashMap.ofEntries(Iterator.ofAll(arr) .map(t -> Tuple.of(keyMapper.apply(t), valueMapper.apply(t))))); } @@ -143,7 +140,6 @@ public static LinkedHashMap of(Tuple2 ent * @return A new Map containing the given map */ public static LinkedHashMap ofAll(java.util.Map map) { - Objects.requireNonNull(map, "map is null"); LinkedHashMap result = LinkedHashMap.empty(); for (java.util.Map.Entry entry : map.entrySet()) { result = result.put(entry.getKey(), entry.getValue()); @@ -436,7 +432,6 @@ public static LinkedHashMap of(K k1, V v1, K k2, V v2, K k3, V v3, */ @SuppressWarnings("unchecked") public static LinkedHashMap tabulate(int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return ofEntries(Collections.tabulate(n, (Function>) f)); } @@ -452,7 +447,6 @@ public static LinkedHashMap tabulate(int n, Function LinkedHashMap fill(int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return ofEntries(Collections.fill(n, (Supplier>) s)); } @@ -501,7 +495,6 @@ public static LinkedHashMap ofEntries(Tuple2 LinkedHashMap ofEntries(Iterable> entries) { - Objects.requireNonNull(entries, "entries is null"); if (entries instanceof LinkedHashMap) { return (LinkedHashMap) entries; } else { @@ -517,8 +510,6 @@ public static LinkedHashMap ofEntries(Iterable LinkedHashMap bimap(Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return LinkedHashMap.ofEntries(entries); } @@ -615,7 +606,6 @@ public LinkedHashMap filterNotValues(Predicate predicate) { @Override public LinkedHashMap flatMap(BiFunction>> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(LinkedHashMap. empty(), (acc, entry) -> { for (Tuple2 mappedEntry : mapper.apply(entry._1, entry._2)) { acc = acc.put(mappedEntry); @@ -711,13 +701,11 @@ public Tuple2 last() { @Override public LinkedHashMap map(BiFunction> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return foldLeft(LinkedHashMap.empty(), (acc, entry) -> acc.put(entry.map(mapper))); } @Override public LinkedHashMap mapKeys(Function keyMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); return map((k, v) -> Tuple.of(keyMapper.apply(k), v)); } @@ -728,7 +716,6 @@ public LinkedHashMap mapKeys(Function keyMa @Override public LinkedHashMap mapValues(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return map((k, v) -> Tuple.of(k, mapper.apply(v))); } @@ -816,7 +803,6 @@ public LinkedHashMap remove(K key) { @Override public LinkedHashMap removeAll(Iterable keys) { - Objects.requireNonNull(keys, "keys is null"); final HashSet toRemove = HashSet.ofAll(keys); final Queue> newList = list.filter(t -> !toRemove.contains(t._1)); final HashMap newMap = map.filter(t -> !toRemove.contains(t._1)); @@ -825,8 +811,6 @@ public LinkedHashMap removeAll(Iterable keys) { @Override public LinkedHashMap replace(Tuple2 currentElement, Tuple2 newElement) { - Objects.requireNonNull(currentElement, "currentElement is null"); - Objects.requireNonNull(newElement, "newElement is null"); // We replace the whole element, i.e. key and value have to be present. if (!Objects.equals(currentElement, newElement) && contains(currentElement)) { @@ -878,7 +862,6 @@ public LinkedHashMap replaceAll(BiFunction retainAll(Iterable> elements) { - Objects.requireNonNull(elements, "elements is null"); LinkedHashMap result = empty(); for (Tuple2 entry : elements) { if (contains(entry)) { diff --git a/src/main/java/io/vavr/collection/LinkedHashMultimap.java b/src/main/java/io/vavr/collection/LinkedHashMultimap.java index 4dca8a267..8f4f50c98 100644 --- a/src/main/java/io/vavr/collection/LinkedHashMultimap.java +++ b/src/main/java/io/vavr/collection/LinkedHashMultimap.java @@ -96,7 +96,6 @@ public LinkedHashMultimap empty() { * @return A new LinkedHashMultimap containing the given entries. */ public LinkedHashMultimap ofEntries(Iterable> entries) { - Objects.requireNonNull(entries, "entries is null"); LinkedHashMultimap result = empty(); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -114,7 +113,6 @@ public LinkedHashMultimap ofEntries(Iterable LinkedHashMultimap ofEntries(Tuple2... entries) { - Objects.requireNonNull(entries, "entries is null"); LinkedHashMultimap result = empty(); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -132,7 +130,6 @@ public final LinkedHashMultimap ofEntries(Tuple2 LinkedHashMultimap ofEntries(java.util.Map.Entry... entries) { - Objects.requireNonNull(entries, "entries is null"); LinkedHashMultimap result = empty(); for (java.util.Map.Entry entry : entries) { result = result.put(entry.getKey(), entry.getValue()); @@ -197,7 +194,6 @@ public LinkedHashMultimap ofAll(java.util.stream.Str */ @SuppressWarnings("unchecked") public LinkedHashMultimap tabulate(int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return ofEntries(Collections.tabulate(n, (Function>) f)); } @@ -213,7 +209,6 @@ public LinkedHashMultimap tabulate(int n, Function LinkedHashMultimap fill(int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return ofEntries(Collections.fill(n, (Supplier>) s)); } diff --git a/src/main/java/io/vavr/collection/LinkedHashSet.java b/src/main/java/io/vavr/collection/LinkedHashSet.java index 842778ece..e1018ac69 100644 --- a/src/main/java/io/vavr/collection/LinkedHashSet.java +++ b/src/main/java/io/vavr/collection/LinkedHashSet.java @@ -112,7 +112,6 @@ public static LinkedHashSet of(T element) { */ @SafeVarargs public static LinkedHashSet of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); LinkedHashMap map = LinkedHashMap.empty(); for (T element : elements) { map = map.put(element, element); @@ -131,7 +130,6 @@ public static LinkedHashSet of(T... elements) { * @throws NullPointerException if {@code f} is null */ public static LinkedHashSet tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return Collections.tabulate(n, f, LinkedHashSet.empty(), LinkedHashSet::of); } @@ -145,7 +143,6 @@ public static LinkedHashSet tabulate(int n, Function LinkedHashSet fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return Collections.fill(n, s, LinkedHashSet.empty(), LinkedHashSet::of); } @@ -158,7 +155,6 @@ public static LinkedHashSet fill(int n, Supplier s) { */ @SuppressWarnings("unchecked") public static LinkedHashSet ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof LinkedHashSet) { return (LinkedHashSet) elements; } else { @@ -175,7 +171,6 @@ public static LinkedHashSet ofAll(Iterable elements) { * @return A LinkedHashSet containing the given elements in the same order. */ public static LinkedHashSet ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(Iterator.ofAll(javaStream.iterator())); } @@ -187,7 +182,6 @@ public static LinkedHashSet ofAll(java.util.stream.Stream ja * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -199,7 +193,6 @@ public static LinkedHashSet ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -211,7 +204,6 @@ public static LinkedHashSet ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -223,7 +215,6 @@ public static LinkedHashSet ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -235,7 +226,6 @@ public static LinkedHashSet ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -247,7 +237,6 @@ public static LinkedHashSet ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -259,7 +248,6 @@ public static LinkedHashSet ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -271,7 +259,6 @@ public static LinkedHashSet ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static LinkedHashSet ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return LinkedHashSet.ofAll(Iterator.ofAll(elements)); } @@ -506,7 +493,6 @@ public LinkedHashSet add(T element) { */ @Override public LinkedHashSet addAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof LinkedHashSet) { @SuppressWarnings("unchecked") final LinkedHashSet set = (LinkedHashSet) elements; @@ -532,7 +518,6 @@ public boolean contains(T element) { @Override public LinkedHashSet diff(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() || elements.isEmpty()) { return this; } else { @@ -547,13 +532,11 @@ public LinkedHashSet distinct() { @Override public LinkedHashSet distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return LinkedHashSet.ofAll(iterator().distinctBy(comparator)); } @Override public LinkedHashSet distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return LinkedHashSet.ofAll(iterator().distinctBy(keyExtractor)); } @@ -577,33 +560,28 @@ public LinkedHashSet dropRight(int n) { @Override public LinkedHashSet dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public LinkedHashSet dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final LinkedHashSet dropped = LinkedHashSet.ofAll(iterator().dropWhile(predicate)); return dropped.length() == length() ? this : dropped; } @Override public LinkedHashSet filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final LinkedHashSet filtered = LinkedHashSet.ofAll(iterator().filter(predicate)); return filtered.length() == length() ? this : filtered; } @Override public LinkedHashSet filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @Override public LinkedHashSet flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -615,7 +593,6 @@ public LinkedHashSet flatMap(Function U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); } @@ -663,7 +640,6 @@ public Option> initOption() { @Override public LinkedHashSet intersect(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() || elements.isEmpty()) { return empty(); } else { @@ -723,7 +699,6 @@ public int length() { @Override public LinkedHashSet map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -757,7 +732,6 @@ public Tuple2, LinkedHashSet> partition(Predicate @Override public LinkedHashSet peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(iterator().head()); } @@ -829,7 +803,6 @@ public Iterator> sliding(int size, int step) { @Override public Tuple2, LinkedHashSet> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Tuple2, Iterator> t = iterator().span(predicate); return Tuple.of(LinkedHashSet.ofAll(t._1), LinkedHashSet.ofAll(t._2)); } @@ -865,13 +838,11 @@ public LinkedHashSet takeRight(int n) { @Override public LinkedHashSet takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @Override public LinkedHashSet takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final LinkedHashSet taken = LinkedHashSet.ofAll(iterator().takeWhile(predicate)); return taken.length() == length() ? this : taken; } @@ -885,7 +856,6 @@ public LinkedHashSet takeWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -907,7 +877,6 @@ public java.util.LinkedHashSet toJavaSet() { @SuppressWarnings("unchecked") @Override public LinkedHashSet union(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { if (elements instanceof LinkedHashSet) { return (LinkedHashSet) elements; @@ -933,14 +902,11 @@ public LinkedHashSet> zip(Iterable that) { @Override public LinkedHashSet zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return LinkedHashSet.ofAll(iterator().zipWith(that, mapper)); } @Override public LinkedHashSet> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return LinkedHashSet.ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -951,7 +917,6 @@ public LinkedHashSet> zipWithIndex() { @Override public LinkedHashSet zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return LinkedHashSet.ofAll(iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/List.java b/src/main/java/io/vavr/collection/List.java index a6e48ed74..cb0411936 100644 --- a/src/main/java/io/vavr/collection/List.java +++ b/src/main/java/io/vavr/collection/List.java @@ -220,7 +220,6 @@ public static List of(T element) { */ @SafeVarargs public static List of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); List result = Nil.instance(); for (int i = elements.length - 1; i >= 0; i--) { result = result.prepend(elements[i]); @@ -241,7 +240,6 @@ public static List of(T... elements) { */ @SuppressWarnings("unchecked") public static List ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof List) { return (List) elements; } else if (elements instanceof ListView @@ -279,7 +277,6 @@ public static List ofAll(Iterable elements) { * @return A List containing the given elements in the same order. */ public static List ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); final java.util.Iterator iterator = javaStream.iterator(); List list = List.empty(); while (iterator.hasNext()) { @@ -296,7 +293,6 @@ public static List ofAll(java.util.stream.Stream javaStream) * @throws NullPointerException if elements is null */ public static List ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -308,7 +304,6 @@ public static List ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -320,7 +315,6 @@ public static List ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -332,7 +326,6 @@ public static List ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -344,7 +337,6 @@ public static List ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -356,7 +348,6 @@ public static List ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -368,7 +359,6 @@ public static List ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -380,7 +370,6 @@ public static List ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static List ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(Iterator.ofAll(elements)); } @@ -395,7 +384,6 @@ public static List ofAll(short... elements) { * @throws NullPointerException if {@code f} is null */ public static List tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return Collections.tabulate(n, f, empty(), List::of); } @@ -409,7 +397,6 @@ public static List tabulate(int n, Function * @throws NullPointerException if {@code s} is null */ public static List fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return Collections.fill(n, s, empty(), List::of); } @@ -744,7 +731,6 @@ public final List append(T element) { @Override public final List appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); return List. ofAll(elements).prependAll(this); } @@ -795,14 +781,12 @@ public final List distinct() { @Override public final List distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final java.util.Set seen = new java.util.TreeSet<>(comparator); return filter(seen::add); } @Override public final List distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); final java.util.Set seen = new java.util.HashSet<>(); return filter(t -> seen.add(keyExtractor.apply(t))); } @@ -824,13 +808,11 @@ public final List drop(int n) { @Override public final List dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public final List dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); List list = this; while (!list.isEmpty() && predicate.test(list.head())) { list = list.tail(); @@ -851,19 +833,16 @@ public final List dropRight(int n) { @Override public final List dropRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return reverse().dropUntil(predicate).reverse(); } @Override public final List dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @Override public final List filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return this; } else { @@ -880,13 +859,11 @@ public final List filter(Predicate predicate) { @Override public final List filterNot(Predicate predicate){ - Objects.requireNonNull(predicate, "predicate is null"); return Collections.filterNot(this, predicate); } @Override public final List flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); List list = empty(); for (T t : this) { for (U u : mapper.apply(t)) { @@ -981,7 +958,6 @@ public final List insert(int index, T element) { @Override public final List insertAll(int index, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (index < 0) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements)"); } @@ -1028,7 +1004,6 @@ public final int lastIndexOf(T element, int end) { @Override public final List map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); List list = empty(); for (T t : this) { list = list.prepend(mapper.apply(t)); @@ -1078,7 +1053,6 @@ public final List patch(int from, Iterable that, int replaced) { @Override public final Tuple2, List> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); List left = empty(), right = empty(); for (T t : this) { if (predicate.test(t)) { @@ -1124,7 +1098,6 @@ public final Option peekOption() { */ @Override public final List peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -1208,7 +1181,6 @@ public final List prepend(T element) { @Override public final List prependAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); return isEmpty() ? ofAll(elements) : ofAll(elements).reverse().foldLeft(this, List::prepend); } @@ -1236,7 +1208,6 @@ public final List push(T element) { @Deprecated @SuppressWarnings("unchecked") public final List push(T... elements) { - Objects.requireNonNull(elements, "elements is null"); List result = this; for (T element : elements) { result = result.prepend(element); @@ -1255,7 +1226,6 @@ public final List push(T... elements) { */ @Deprecated public final List pushAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); List result = this; for (T element : elements) { result = result.prepend(element); @@ -1288,7 +1258,6 @@ public final List remove(T element) { @Override public final List removeFirst(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); List init = empty(); List tail = this; while (!tail.isEmpty() && !predicate.test(tail.head())) { @@ -1304,7 +1273,6 @@ public final List removeFirst(Predicate predicate) { @Override public final List removeLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final List removedAndReversed = reverse().removeFirst(predicate); return removedAndReversed.length() == length() ? this : removedAndReversed.reverse(); } @@ -1461,7 +1429,6 @@ public final List sorted() { @Override public final List sorted(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : toJavaStream().sorted(comparator).collect(collector()); } @@ -1477,7 +1444,6 @@ public final List sortBy(Comparator comparator, Function, List> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Tuple2, Iterator> itt = iterator().span(predicate); return Tuple.of(ofAll(itt._1), ofAll(itt._2)); } @@ -1585,13 +1551,11 @@ public final List take(int n) { @Override public final List takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @Override public final List takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); List result = Nil.instance(); for (List list = this; !list.isEmpty() && predicate.test(list.head()); list = list.tail()) { result = result.prepend(list.head()); @@ -1612,13 +1576,11 @@ public final List takeRight(int n) { @Override public final List takeRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightWhile(predicate.negate()); } @Override public final List takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return reverse().takeWhile(predicate).reverse(); } @@ -1631,7 +1593,6 @@ public final List takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1664,7 +1625,6 @@ public final List update(int index, T element) { @Override public final List update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); } @@ -1675,14 +1635,11 @@ public final List> zip(Iterable that) { @Override public final List zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWith(that, mapper)); } @Override public final List> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -1693,7 +1650,6 @@ public final List> zipWithIndex() { @Override public final List zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWithIndex(mapper)); } @@ -1953,7 +1909,6 @@ static List> apply(List elements, int k) { private interface SplitAt { static Tuple2, List> splitByPredicateReversed(List source, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); List init = Nil.instance(); List tail = source; while (!tail.isEmpty() && !predicate.test(tail.head())) { diff --git a/src/main/java/io/vavr/collection/Map.java b/src/main/java/io/vavr/collection/Map.java index fbf4a3105..d42b1d36b 100644 --- a/src/main/java/io/vavr/collection/Map.java +++ b/src/main/java/io/vavr/collection/Map.java @@ -315,14 +315,12 @@ default boolean containsValue(V value) { @SuppressWarnings("unchecked") @Override default Seq flatMap(Function, ? extends Iterable> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); // don't remove cast, doesn't compile in Eclipse without it return (Seq) iterator().flatMap(mapper).toStream(); } @Override default U foldRight(U zero, BiFunction, ? super U, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); } @@ -333,7 +331,6 @@ default U foldRight(U zero, BiFunction, ? super U, ? ex * @throws NullPointerException if {@code action} is null */ default void forEach(BiConsumer action) { - Objects.requireNonNull(action, "action is null"); for (Tuple2 t : this) { action.accept(t._1, t._2); } @@ -380,7 +377,6 @@ default boolean isTraversableAgain() { * @return An iterator through the mapped elements. */ default Iterator iterator(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return iterator().map(t -> mapper.apply(t._1, t._2)); } @@ -426,7 +422,6 @@ default Function1> lift() { @SuppressWarnings("unchecked") @Override default Seq map(Function, ? extends U> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); // don't remove cast, doesn't compile in Eclipse without it return (Seq) iterator().map(mapper).toStream(); } @@ -597,7 +592,6 @@ default Seq scanRight(U zero, BiFunction, ? super U, * @throws NullPointerException if {@code f} is null */ default U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -638,14 +632,11 @@ default Seq, U>> zip(Iterable that) { @Override default Seq zipWith(Iterable that, BiFunction, ? super U, ? extends R> mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWith(that, mapper)); } @Override default Seq, U>> zipAll(Iterable that, Tuple2 thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return Stream.ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -656,7 +647,6 @@ default Seq, Integer>> zipWithIndex() { @Override default Seq zipWithIndex(BiFunction, ? super Integer, ? extends U> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/Maps.java b/src/main/java/io/vavr/collection/Maps.java index 90fbf4486..ad4553417 100644 --- a/src/main/java/io/vavr/collection/Maps.java +++ b/src/main/java/io/vavr/collection/Maps.java @@ -46,7 +46,6 @@ private Maps() { @SuppressWarnings("unchecked") static > Tuple2 computeIfAbsent(M map, K key, Function mappingFunction) { - Objects.requireNonNull(mappingFunction, "mappingFunction is null"); final Option value = map.get(key); if (value.isDefined()) { return Tuple.of(value.get(), map); @@ -75,13 +74,11 @@ static > M distinct(M map) { static > M distinctBy(M map, OfEntries ofEntries, Comparator> comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return ofEntries.apply(map.iterator().distinctBy(comparator)); } static > M distinctBy( M map, OfEntries ofEntries, Function, ? extends U> keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return ofEntries.apply(map.iterator().distinctBy(keyExtractor)); } @@ -108,37 +105,31 @@ static > M dropRight(M map, OfEntries ofEntri static > M dropUntil(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(map, ofEntries, predicate.negate()); } static > M dropWhile(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return ofEntries.apply(map.iterator().dropWhile(predicate)); } static > M filter(M map, OfEntries ofEntries, BiPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(map, ofEntries, t -> predicate.test(t._1, t._2)); } static > M filter(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return ofEntries.apply(map.iterator().filter(predicate)); } static > M filterKeys(M map, OfEntries ofEntries, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(map, ofEntries, t -> predicate.test(t._1)); } static > M filterValues(M map, OfEntries ofEntries, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(map, ofEntries, t -> predicate.test(t._2)); } @@ -158,7 +149,6 @@ static > Option initOption(M map) { static > M merge(M map, OfEntries ofEntries, Map that) { - Objects.requireNonNull(that, "that is null"); if (map.isEmpty()) { return ofEntries.apply(Map.narrow(that)); } else if (that.isEmpty()) { @@ -172,8 +162,6 @@ static > M merge(M map, OfEntries ofEntries, static > M merge( M map, OfEntries ofEntries, Map that, BiFunction collisionResolution) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(collisionResolution, "collisionResolution is null"); if (map.isEmpty()) { return ofEntries.apply(Map.narrow(that)); } else if (that.isEmpty()) { @@ -192,23 +180,17 @@ static > M merge( static > M ofStream(M map, java.util.stream.Stream stream, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(stream, "stream is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return Stream.ofAll(stream).foldLeft(map, (m, el) -> (M) m.put(keyMapper.apply(el), valueMapper.apply(el))); } @SuppressWarnings("unchecked") static > M ofStream(M map, java.util.stream.Stream stream, Function> entryMapper) { - Objects.requireNonNull(stream, "stream is null"); - Objects.requireNonNull(entryMapper, "entryMapper is null"); return Stream.ofAll(stream).foldLeft(map, (m, el) -> (M) m.put(entryMapper.apply(el))); } static > Tuple2 partition(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final java.util.List> left = new java.util.ArrayList<>(); final java.util.List> right = new java.util.ArrayList<>(); for (Tuple2 entry : map) { @@ -218,7 +200,6 @@ static > Tuple2 partition(M map, OfEntries> M peek(M map, Consumer> action) { - Objects.requireNonNull(action, "action is null"); if (!map.isEmpty()) { action.accept(map.head()); } @@ -228,7 +209,6 @@ static > M peek(M map, Consumer> @SuppressWarnings("unchecked") static > M put(M map, K key, U value, BiFunction merge) { - Objects.requireNonNull(merge, "the merge function is null"); final Option currentValue = map.get(key); if (currentValue.isEmpty()) { return (M) map.put(key, value); @@ -239,13 +219,11 @@ static > M put(M map, K key, U value, @SuppressWarnings("unchecked") static > M put(M map, Tuple2 entry) { - Objects.requireNonNull(entry, "entry is null"); return (M) map.put(entry._1, entry._2); } static > M put(M map, Tuple2 entry, BiFunction merge) { - Objects.requireNonNull(merge, "the merge function is null"); final Option currentValue = map.get(entry._1); if (currentValue.isEmpty()) { return put(map, entry); @@ -256,25 +234,21 @@ static > M put(M map, Tuple2> M filterNot(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(map, ofEntries, predicate.negate()); } static > M filterNot(M map, OfEntries ofEntries, BiPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(map, ofEntries, predicate.negate()); } static > M filterNotKeys(M map, OfEntries ofEntries, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterKeys(map, ofEntries, predicate.negate()); } static > M filterNotValues(M map, OfEntries ofEntries, Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterValues(map, ofEntries, predicate.negate()); } @@ -285,8 +259,6 @@ static > M replace(M map, K key, V oldValue, V newValu @SuppressWarnings("unchecked") static > M replace(M map, Tuple2 currentElement, Tuple2 newElement) { - Objects.requireNonNull(currentElement, "currentElement is null"); - Objects.requireNonNull(newElement, "newElement is null"); return (M) (map.containsKey(currentElement._1) ? map.remove(currentElement._1).put(newElement) : map); } @@ -326,7 +298,6 @@ static > Iterator sliding(M map, OfEntries static > Tuple2 span(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Tuple2>, Iterator>> t = map.iterator().span(predicate); return Tuple.of(ofEntries.apply(t._1), ofEntries.apply(t._2)); } @@ -354,13 +325,11 @@ static > M takeRight(M map, OfEntries ofEntri static > M takeUntil(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(map, ofEntries, predicate.negate()); } static > M takeWhile(M map, OfEntries ofEntries, Predicate> predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final M taken = ofEntries.apply(map.iterator().takeWhile(predicate)); return taken.size() == map.size() ? map : taken; } diff --git a/src/main/java/io/vavr/collection/Multimap.java b/src/main/java/io/vavr/collection/Multimap.java index d566ea543..f5e370edb 100644 --- a/src/main/java/io/vavr/collection/Multimap.java +++ b/src/main/java/io/vavr/collection/Multimap.java @@ -311,7 +311,6 @@ default boolean containsValue(V value) { * @throws NullPointerException if {@code action} is null */ default void forEach(BiConsumer action) { - Objects.requireNonNull(action, "action is null"); for (Tuple2 t : this) { action.accept(t._1, t._2); } @@ -376,7 +375,6 @@ default boolean isTraversableAgain() { * @return An iterator through the mapped elements. */ default Iterator iterator(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return iterator().map(t -> mapper.apply(t._1, t._2)); } @@ -415,7 +413,6 @@ default int length() { @SuppressWarnings("unchecked") @Override default Seq map(Function, ? extends U> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); // don't remove cast, doesn't compile in Eclipse without it return (Seq) iterator().map(mapper).toStream(); } @@ -534,7 +531,6 @@ default Seq scanRight(U zero, BiFunction, ? super U, * @throws NullPointerException if {@code f} is null */ default U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -547,14 +543,11 @@ default Seq, U>> zip(Iterable that) { @Override default Seq, U>> zipAll(Iterable that, Tuple2 thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return Stream.ofAll(iterator().zipAll(that, thisElem, thatElem)); } @Override default Seq zipWith(Iterable that, BiFunction, ? super U, ? extends R> mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWith(that, mapper)); } @@ -565,7 +558,6 @@ default Seq, Integer>> zipWithIndex() { @Override default Seq zipWithIndex(BiFunction, ? super Integer, ? extends U> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWithIndex(mapper)); } @@ -610,14 +602,12 @@ default Seq zipWithIndex(BiFunction, ? super Integer @SuppressWarnings("unchecked") @Override default Seq flatMap(Function, ? extends Iterable> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); // don't remove cast, doesn't compile in Eclipse without it return (Seq) iterator().flatMap(mapper).toStream(); } @Override default U foldRight(U zero, BiFunction, ? super U, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); } diff --git a/src/main/java/io/vavr/collection/Multimaps.java b/src/main/java/io/vavr/collection/Multimaps.java index 3be274924..4a930d4eb 100644 --- a/src/main/java/io/vavr/collection/Multimaps.java +++ b/src/main/java/io/vavr/collection/Multimaps.java @@ -38,7 +38,6 @@ class Multimaps { @SuppressWarnings("unchecked") static > M ofJavaMap(M source, java.util.Map map) { - Objects.requireNonNull(map, "map is null"); return Stream.ofAll(map.entrySet()).foldLeft(source, (m, el) -> (M) m.put(el.getKey(), el.getValue())); } @@ -46,17 +45,12 @@ static > M ofJavaMap(M source, java.util.Map> M ofStream(M source, java.util.stream.Stream stream, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(stream, "stream is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return Stream.ofAll(stream).foldLeft(source, (m, el) -> (M) m.put(keyMapper.apply(el), valueMapper.apply(el))); } @SuppressWarnings("unchecked") static > M ofStream(M source, java.util.stream.Stream stream, Function> entryMapper) { - Objects.requireNonNull(stream, "stream is null"); - Objects.requireNonNull(entryMapper, "entryMapper is null"); return Stream.ofAll(stream).foldLeft(source, (m, el) -> (M) m.put(entryMapper.apply(el))); } } diff --git a/src/main/java/io/vavr/collection/PriorityQueue.java b/src/main/java/io/vavr/collection/PriorityQueue.java index 6baa1a133..4cb13fe5a 100644 --- a/src/main/java/io/vavr/collection/PriorityQueue.java +++ b/src/main/java/io/vavr/collection/PriorityQueue.java @@ -233,7 +233,6 @@ public static > PriorityQueue ofAll(Iterable< @SuppressWarnings("unchecked") public static PriorityQueue ofAll(Comparator comparator, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof PriorityQueue && ((PriorityQueue) elements).comparator == comparator) { return (PriorityQueue) elements; } else { @@ -266,7 +265,6 @@ public static PriorityQueue ofAll(Comparator comparator, java. * @throws NullPointerException if {@code function} is null */ public static PriorityQueue tabulate(int size, Function function) { - Objects.requireNonNull(function, "function is null"); final Comparator comparator = Comparators.naturalComparator(); return io.vavr.collection.Collections.tabulate(size, function, empty(comparator), values -> ofAll(comparator, io.vavr.collection.List.of(values))); } @@ -282,7 +280,6 @@ public static PriorityQueue tabulate(int size, Function PriorityQueue fill(int size, Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); final Comparator comparator = Comparators.naturalComparator(); return io.vavr.collection.Collections.fill(size, supplier, empty(comparator), values -> ofAll(comparator, io.vavr.collection.List.of(values))); } @@ -321,7 +318,6 @@ public io.vavr.collection.List toList() { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -332,13 +328,11 @@ public PriorityQueue distinct() { @Override public PriorityQueue distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : ofAll(comparator, iterator().distinctBy(comparator)); } @Override public PriorityQueue distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return isEmpty() ? this : ofAll(comparator, iterator().distinctBy(keyExtractor)); } @@ -366,7 +360,6 @@ public PriorityQueue dropRight(int n) { @Override public PriorityQueue dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); PriorityQueue result = this; while (!result.isEmpty() && predicate.test(result.head())) { result = result.tail(); @@ -376,7 +369,6 @@ public PriorityQueue dropWhile(Predicate predicate) { @Override public PriorityQueue filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return this; } else { @@ -390,8 +382,6 @@ public PriorityQueue flatMap(Function PriorityQueue flatMap(Comparator comparator, Function> mapper) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(comparator, iterator().flatMap(mapper)); } @@ -408,8 +398,6 @@ public PriorityQueue flatMap(Comparator comparator, Function U foldRight(U zero, BiFunction accumulator) { - Objects.requireNonNull(zero, "zero is null"); - Objects.requireNonNull(accumulator, "accumulator is null"); return toList().foldRight(zero, accumulator); } @@ -477,13 +465,10 @@ public int length() { @Override public PriorityQueue map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return map(Comparators.naturalComparator(), mapper); } public PriorityQueue map(Comparator comparator, Function mapper) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(comparator, iterator().map(mapper)); } @@ -515,7 +500,6 @@ public PriorityQueue orElse(Supplier> supplie @Override public Tuple2, ? extends PriorityQueue> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); PriorityQueue left = empty(comparator), right = left; for (T t : this) { if (predicate.test(t)) { @@ -530,15 +514,11 @@ public PriorityQueue orElse(Supplier> supplie @Override public PriorityQueue replace(T currentElement, T newElement) { - Objects.requireNonNull(currentElement, "currentElement is null"); - Objects.requireNonNull(newElement, "newElement is null"); return ofAll(comparator, iterator().replace(currentElement, newElement)); } @Override public PriorityQueue replaceAll(T currentElement, T newElement) { - Objects.requireNonNull(currentElement, "currentElement is null"); - Objects.requireNonNull(newElement, "newElement is null"); return ofAll(comparator, iterator().replaceAll(currentElement, newElement)); } @@ -574,7 +554,6 @@ public io.vavr.collection.Iterator> sliding(int size, @Override public Tuple2, ? extends PriorityQueue> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Tuple.of(takeWhile(predicate), dropWhile(predicate)); } @@ -602,26 +581,21 @@ public PriorityQueue takeRight(int n) { @Override public PriorityQueue takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return isEmpty() ? this : ofAll(comparator, iterator().takeUntil(predicate)); } @Override public PriorityQueue> zip(Iterable that) { - Objects.requireNonNull(that, "that is null"); return ofAll(Tuple2.comparator(comparator(), Comparators.naturalComparator()), iterator().zipWith(that, Tuple::of)); } @Override public PriorityQueue zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(Comparators.naturalComparator(), iterator().zipWith(that, mapper)); } @Override public PriorityQueue> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return ofAll(Tuple2.comparator(comparator(), Comparators.naturalComparator()), iterator().zipAll(that, thisElem, thatElem)); } @@ -632,7 +606,6 @@ public PriorityQueue> zipWithIndex() { @Override public PriorityQueue zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(Comparators.naturalComparator(), iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/Queue.java b/src/main/java/io/vavr/collection/Queue.java index 9a8237158..fd948c5e5 100644 --- a/src/main/java/io/vavr/collection/Queue.java +++ b/src/main/java/io/vavr/collection/Queue.java @@ -146,7 +146,6 @@ public static Queue of(T element) { @SuppressWarnings("varargs") @SafeVarargs public static Queue of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.of(elements)); } @@ -160,7 +159,6 @@ public static Queue of(T... elements) { */ @SuppressWarnings("unchecked") public static Queue ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof Queue) { return (Queue) elements; } else if (elements instanceof ListView @@ -183,7 +181,6 @@ public static Queue ofAll(Iterable elements) { * @return A Queue containing the given elements in the same order. */ public static Queue ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return new Queue<>(io.vavr.collection.List.ofAll(javaStream), io.vavr.collection.List.empty()); } @@ -195,7 +192,6 @@ public static Queue ofAll(java.util.stream.Stream javaStream * @throws NullPointerException if elements is null */ public static Queue ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -207,7 +203,6 @@ public static Queue ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -219,7 +214,6 @@ public static Queue ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -231,7 +225,6 @@ public static Queue ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -243,7 +236,6 @@ public static Queue ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -255,7 +247,6 @@ public static Queue ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -267,7 +258,6 @@ public static Queue ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -279,7 +269,6 @@ public static Queue ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static Queue ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(io.vavr.collection.List.ofAll(elements)); } @@ -294,7 +283,6 @@ public static Queue ofAll(short... elements) { * @throws NullPointerException if {@code f} is null */ public static Queue tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return io.vavr.collection.Collections.tabulate(n, f, empty(), Queue::of); } @@ -308,7 +296,6 @@ public static Queue tabulate(int n, Function Queue fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return io.vavr.collection.Collections.fill(n, s, empty(), Queue::of); } @@ -656,7 +643,6 @@ public Queue enqueue(T element) { */ @SuppressWarnings("unchecked") public Queue enqueueAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof Queue) { return (Queue) elements; } else { @@ -723,13 +709,11 @@ public Queue distinct() { @Override public Queue distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return ofAll(toList().distinctBy(comparator)); } @Override public Queue distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return ofAll(toList().distinctBy(keyExtractor)); } @@ -746,7 +730,6 @@ public Queue drop(int n) { @Override public Queue dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final List dropped = toList().dropWhile(predicate); return ofAll(dropped.length() == length() ? this : dropped); } @@ -764,19 +747,16 @@ public Queue dropRight(int n) { @Override public Queue dropRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return reverse().dropUntil(predicate).reverse(); } @Override public Queue dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @Override public Queue filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final io.vavr.collection.List filtered = toList().filter(predicate); if (filtered.isEmpty()) { @@ -790,7 +770,6 @@ public Queue filter(Predicate predicate) { @Override public Queue flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return empty(); } else { @@ -890,7 +869,6 @@ public Queue insert(int index, T element) { @SuppressWarnings("unchecked") @Override public Queue insertAll(int index, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (index < 0) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements)"); } @@ -979,7 +957,6 @@ public boolean isDefinedAt(Integer index) { @Override public Queue map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return new Queue<>(front.map(mapper), rear.map(mapper)); } @@ -1025,7 +1002,6 @@ public Queue patch(int from, Iterable that, int replaced) { @Override public Tuple2, Queue> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return toList().partition(predicate).map(io.vavr.collection.List::toQueue, io.vavr.collection.List::toQueue); } @@ -1042,7 +1018,6 @@ public Queue prepend(T element) { @SuppressWarnings("unchecked") @Override public Queue prependAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty() && elements instanceof Queue) { return (Queue) elements; } else { @@ -1164,7 +1139,6 @@ public Queue sorted() { @Override public Queue sorted(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return ofAll(toList().sorted(comparator)); } @@ -1180,7 +1154,6 @@ public Queue sortBy(Comparator comparator, Function, Queue> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return toList().span(predicate).map(io.vavr.collection.List::toQueue, io.vavr.collection.List::toQueue); } @@ -1254,7 +1227,6 @@ public Queue take(int n) { @Override public Queue takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final io.vavr.collection.List taken = toList().takeUntil(predicate); return taken.length() == length() ? this : ofAll(taken); } @@ -1279,14 +1251,12 @@ public Queue takeRight(int n) { @Override public Queue takeRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final io.vavr.collection.List taken = toList().takeRightUntil(predicate); return taken.length() == length() ? this : ofAll(taken); } @Override public Queue takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightUntil(predicate.negate()); } @@ -1299,7 +1269,6 @@ public Queue takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1310,7 +1279,6 @@ public Queue update(int index, T element) { @Override public Queue update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); } @@ -1322,14 +1290,11 @@ public Queue> zip(Iterable that) { @SuppressWarnings("unchecked") @Override public Queue zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(toList().zipWith(that, mapper)); } @Override public Queue> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return ofAll(toList().zipAll(that, thisElem, thatElem)); } @@ -1340,7 +1305,6 @@ public Queue> zipWithIndex() { @Override public Queue zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(toList().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/collection/RedBlackTree.java b/src/main/java/io/vavr/collection/RedBlackTree.java index 4ea3d9df8..13d6678da 100644 --- a/src/main/java/io/vavr/collection/RedBlackTree.java +++ b/src/main/java/io/vavr/collection/RedBlackTree.java @@ -53,20 +53,16 @@ interface RedBlackTree extends Iterable { static RedBlackTree empty(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return new Empty<>(comparator); } static RedBlackTree of(Comparator comparator, T value) { - Objects.requireNonNull(comparator, "comparator is null"); final Empty empty = new Empty<>(comparator); return new Node<>(BLACK, 1, empty, value, empty, empty); } @SafeVarargs static RedBlackTree of(Comparator comparator, T... values) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(values, "values is null"); RedBlackTree tree = empty(comparator); for (T value : values) { tree = tree.insert(value); @@ -76,8 +72,6 @@ static RedBlackTree of(Comparator comparator, T... values) { @SuppressWarnings("unchecked") static RedBlackTree ofAll(Comparator comparator, Iterable values) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(values, "values is null"); // function equality is not computable => same object check if (values instanceof RedBlackTree && ((RedBlackTree) values).comparator() == comparator) { return (RedBlackTree) values; @@ -136,7 +130,6 @@ default RedBlackTree delete(T value) { } default RedBlackTree difference(RedBlackTree tree) { - Objects.requireNonNull(tree, "tree is null"); if (isEmpty() || tree.isEmpty()) { return this; } else { @@ -166,7 +159,6 @@ default RedBlackTree difference(RedBlackTree tree) { Option find(T value); default RedBlackTree intersection(RedBlackTree tree) { - Objects.requireNonNull(tree, "tree is null"); if (isEmpty()) { return this; } else if (tree.isEmpty()) { @@ -237,7 +229,6 @@ default Option min() { * @return A new RedBlackTree that contains all distinct elements of this and the given {@code tree}. */ default RedBlackTree union(RedBlackTree tree) { - Objects.requireNonNull(tree, "tree is null"); if (tree.isEmpty()) { return this; } else { diff --git a/src/main/java/io/vavr/collection/Seq.java b/src/main/java/io/vavr/collection/Seq.java index 79bbcfbe3..21e12fe7e 100644 --- a/src/main/java/io/vavr/collection/Seq.java +++ b/src/main/java/io/vavr/collection/Seq.java @@ -265,7 +265,6 @@ static Seq narrow(Seq seq) { * @throws NullPointerException if {@code that} is null. */ default boolean containsSlice(Iterable that) { - Objects.requireNonNull(that, "that is null"); return indexOfSlice(that) >= 0; } @@ -329,7 +328,6 @@ default Iterator> crossProduct() { * @throws NullPointerException if that is null */ default Iterator> crossProduct(Iterable that) { - Objects.requireNonNull(that, "that is null"); final Stream other = Stream.ofAll(that); return Iterator.ofAll(this).flatMap(a -> other.map(b -> Tuple.of(a, b))); } @@ -343,7 +341,6 @@ default Iterator> crossProduct(Iterable that) { * @return true if this sequence has that as a suffix, false otherwise. */ default boolean endsWith(Seq that) { - Objects.requireNonNull(that, "that is null"); final Iterator i = this.iterator().drop(length() - that.length()); final Iterator j = that.iterator(); while (i.hasNext() && j.hasNext()) { @@ -1026,7 +1023,6 @@ default boolean startsWith(Iterable that) { * @return true if that is empty or that is prefix of this collection starting from the given offset, false otherwise. */ default boolean startsWith(Iterable that, int offset) { - Objects.requireNonNull(that, "that is null"); if (offset < 0) { return false; } final Iterator i = this.iterator().drop(offset); final java.util.Iterator j = that.iterator(); @@ -1200,7 +1196,6 @@ default boolean startsWith(Iterable that, int offset) { @Override default U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); return reverse().foldLeft(zero, (xs, x) -> f.apply(x, xs)); } diff --git a/src/main/java/io/vavr/collection/Stream.java b/src/main/java/io/vavr/collection/Stream.java index 1cec7fd94..01e40117d 100644 --- a/src/main/java/io/vavr/collection/Stream.java +++ b/src/main/java/io/vavr/collection/Stream.java @@ -218,7 +218,6 @@ public static Stream from(long value, long step) { * @return A new Stream */ public static Stream continually(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return Stream.ofAll(Iterator.continually(supplier)); } @@ -232,7 +231,6 @@ public static Stream continually(Supplier supplier) { * @return A new Stream */ public static Stream iterate(T seed, Function f) { - Objects.requireNonNull(f, "f is null"); return Stream.ofAll(Iterator.iterate(seed, f)); } @@ -248,7 +246,6 @@ public static Stream iterate(T seed, Function f) * @return A new Stream */ public static Stream iterate(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return Stream.ofAll(Iterator.iterate(supplier)); } @@ -262,7 +259,6 @@ public static Stream iterate(Supplier> supp */ @SuppressWarnings("unchecked") public static Stream cons(T head, Supplier> tailSupplier) { - Objects.requireNonNull(tailSupplier, "tailSupplier is null"); return new ConsImpl<>(head, (Supplier>) tailSupplier); } @@ -317,7 +313,6 @@ public static Stream of(T element) { */ @SafeVarargs public static Stream of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(new Iterator() { int i = 0; @@ -344,7 +339,6 @@ public T next() { * @throws NullPointerException if {@code f} is null */ public static Stream tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return Stream.ofAll(io.vavr.collection.Collections.tabulate(n, f)); } @@ -358,7 +352,6 @@ public static Stream tabulate(int n, Function Stream fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return Stream.ofAll(io.vavr.collection.Collections.fill(n, s)); } @@ -383,7 +376,6 @@ public static Stream fill(int n, T element) { */ @SuppressWarnings("unchecked") public static Stream ofAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof Stream) { return (Stream) elements; } else if (elements instanceof ListView @@ -402,7 +394,6 @@ public static Stream ofAll(Iterable elements) { * @return A Stream containing the given elements in the same order. */ public static Stream ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return StreamFactory.create(javaStream.iterator()); } @@ -414,7 +405,6 @@ public static Stream ofAll(java.util.stream.Stream javaStrea * @throws NullPointerException if elements is null */ public static Stream ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -426,7 +416,6 @@ public static Stream ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -438,7 +427,6 @@ public static Stream ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -450,7 +438,6 @@ public static Stream ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -462,7 +449,6 @@ public static Stream ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -474,7 +460,6 @@ public static Stream ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -486,7 +471,6 @@ public static Stream ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -498,7 +482,6 @@ public static Stream ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static Stream ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return Stream.ofAll(Iterator.ofAll(elements)); } @@ -851,7 +834,6 @@ public static Stream continually(T t) { * @return a new Stream */ public final Stream appendSelf(Function, ? extends Stream> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? this : new AppendSelf<>((Cons) this, mapper).stream(); } @@ -967,7 +949,6 @@ public final Stream distinct() { @Override public final Stream distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final java.util.Set seen = new java.util.TreeSet<>(comparator); return filter(seen::add); } @@ -989,13 +970,11 @@ public final Stream drop(int n) { @Override public final Stream dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public final Stream dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); Stream stream = this; while (!stream.isEmpty() && predicate.test(stream.head())) { stream = stream.tail(); @@ -1014,19 +993,16 @@ public final Stream dropRight(int n) { @Override public final Stream dropRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return reverse().dropUntil(predicate).reverse(); } @Override public final Stream dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @Override public final Stream filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return this; } else { @@ -1042,13 +1018,11 @@ public final Stream filter(Predicate predicate) { @Override public final Stream filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Collections.filterNot(this, predicate); } @Override public final Stream flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? Empty.instance() : Stream.ofAll(new FlatMapIterator<>(this.iterator(), mapper)); } @@ -1160,7 +1134,6 @@ public final Stream insert(int index, T element) { @Override public final Stream insertAll(int index, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (index < 0) { throw new IndexOutOfBoundsException("insertAll(" + index + ", elements)"); } else if (index == 0) { @@ -1239,7 +1212,6 @@ public boolean isDefinedAt(Integer index) { @Override public final Stream map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return Empty.instance(); } else { @@ -1290,13 +1262,14 @@ public final Stream patch(int from, Iterable that, int replaced) @Override public final Tuple2, Stream> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); + if (isEmpty()) { + return Tuple.of(empty(), empty()); + } return Tuple.of(filter(predicate), filter(predicate.negate())); } @Override public final Stream peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isEmpty()) { return this; } else { @@ -1331,7 +1304,6 @@ public final Stream prepend(T element) { @Override public final Stream prependAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { if (elements instanceof Stream) { @SuppressWarnings("unchecked") @@ -1357,7 +1329,6 @@ public final Stream remove(T element) { @Override public final Stream removeFirst(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return this; } else { @@ -1502,7 +1473,6 @@ public final Stream sorted() { @Override public final Stream sorted(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : toJavaStream().sorted(comparator).collect(Stream.collector()); } @@ -1518,7 +1488,6 @@ public final Stream sortBy(Comparator comparator, Function, Stream> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Tuple.of(takeWhile(predicate), dropWhile(predicate)); } @@ -1529,7 +1498,6 @@ public final Tuple2, Stream> splitAt(int n) { @Override public final Tuple2, Stream> splitAt(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Tuple.of(takeWhile(predicate.negate()), dropWhile(predicate.negate())); } @@ -1602,13 +1570,11 @@ public final Stream take(int n) { @Override public final Stream takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeWhile(predicate.negate()); } @Override public final Stream takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Empty.instance(); } else { @@ -1634,13 +1600,11 @@ public final Stream takeRight(int n) { @Override public final Stream takeRightUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return reverse().takeUntil(predicate).reverse(); } @Override public final Stream takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightUntil(predicate.negate()); } @@ -1653,7 +1617,6 @@ public final Stream takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1682,7 +1645,6 @@ public final Stream update(int index, T element) { @Override public final Stream update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); } @@ -1693,14 +1655,11 @@ public final Stream> zip(Iterable that) { @Override public final Stream zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWith(that, mapper)); } @Override public final Stream> zipAll(Iterable iterable, T thisElem, U thatElem) { - Objects.requireNonNull(iterable, "iterable is null"); return Stream.ofAll(iterator().zipAll(iterable, thisElem, thatElem)); } @@ -1711,7 +1670,6 @@ public final Stream> zipWithIndex() { @Override public final Stream zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return Stream.ofAll(iterator().zipWithIndex(mapper)); } @@ -1732,7 +1690,6 @@ public final Stream extend(T next) { * @return new {@code Stream} composed from this stream extended with values provided by the supplier */ public final Stream extend(Supplier nextSupplier) { - Objects.requireNonNull(nextSupplier, "nextSupplier is null"); return Stream.ofAll(appendAll(Stream.continually(nextSupplier))); } @@ -1744,7 +1701,6 @@ public final Stream extend(Supplier nextSupplier) { * @return new {@code Stream} composed from this stream extended with values calculated by the provided function */ public final Stream extend(Function nextFunction) { - Objects.requireNonNull(nextFunction, "nextFunction is null"); if (isEmpty()) { return this; } else { @@ -1801,7 +1757,6 @@ public Stream append(T element) { @Override public Stream appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (Collections.isEmpty(elements)) { return this; } else { @@ -1881,7 +1836,6 @@ public static abstract class Cons extends Stream { final Lazy> tail; Cons(T head, Supplier> tail) { - Objects.requireNonNull(tail, "tail is null"); this.head = head; this.tail = Lazy.of(tail); } @@ -1947,7 +1901,6 @@ public Stream append(T element) { @Override public Stream appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if (Collections.isEmpty(elements)) { return this; } else { @@ -1987,7 +1940,6 @@ public Stream append(T element) { @Override public Stream appendAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); return new AppendElements<>(head, queue.appendAll(elements), tail); } diff --git a/src/main/java/io/vavr/collection/Traversable.java b/src/main/java/io/vavr/collection/Traversable.java index 70ae8e541..1d7b5f1fb 100644 --- a/src/main/java/io/vavr/collection/Traversable.java +++ b/src/main/java/io/vavr/collection/Traversable.java @@ -269,7 +269,6 @@ default Option average() { * @throws NullPointerException if {@code elements} is null */ default boolean containsAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); for (T element : elements) { if (!contains(element)) { return false; @@ -286,7 +285,6 @@ default boolean containsAll(Iterable elements) { * @throws NullPointerException if {@code predicate} is null. */ default int count(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return foldLeft(0, (i, t) -> predicate.test(t) ? i + 1 : i); } @@ -411,7 +409,6 @@ default int count(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default boolean existsUnique(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); boolean exists = false; for (T t : this) { if (predicate.test(t)) { @@ -446,7 +443,6 @@ default boolean existsUnique(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default Traversable filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @@ -458,7 +454,6 @@ default Traversable filterNot(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default Option find(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (T a : this) { if (predicate.test(a)) { return Option.some(a); // may be Some(null) @@ -477,7 +472,6 @@ default Option find(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default Option findLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return iterator().findLast(predicate); } @@ -525,7 +519,6 @@ default Option findLast(Predicate predicate) { * @throws NullPointerException if {@code combine} is null */ default T fold(T zero, BiFunction combine) { - Objects.requireNonNull(combine, "combine is null"); return foldLeft(zero, combine); } @@ -547,7 +540,6 @@ default T fold(T zero, BiFunction combine) { */ @Override default U foldLeft(U zero, BiFunction combine) { - Objects.requireNonNull(combine, "combine is null"); U xs = zero; for (T x : this) { xs = combine.apply(xs, x); @@ -590,7 +582,6 @@ default U foldLeft(U zero, BiFunction com * @throws NullPointerException if {@code action} is null */ default void forEachWithIndex(ObjIntConsumer action) { - Objects.requireNonNull(action, "action is null"); int index = 0; for (T t : this) { action.accept(t, index++); @@ -921,7 +912,6 @@ default Option max() { * @throws NullPointerException if {@code comparator} is null */ default Option maxBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); if (isEmpty()) { return Option.none(); } else { @@ -939,7 +929,6 @@ default Option maxBy(Comparator comparator) { * @throws NullPointerException if {@code f} is null. */ default > Option maxBy(Function f) { - Objects.requireNonNull(f, "f is null"); if (isEmpty()) { return Option.none(); } else { @@ -1006,10 +995,9 @@ default Option min() { * * @param comparator A non-null element comparator * @return {@code Some(minimum)} of this elements or {@code None} if this is empty - * @throws NullPointerException if {@code comparator} is null + * @throws NullPointerException if {@code comparator} is null, unless no comparison is needed. */ default Option minBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); if (isEmpty()) { return Option.none(); } else { @@ -1027,7 +1015,6 @@ default Option minBy(Comparator comparator) { * @throws NullPointerException if {@code f} is null. */ default > Option minBy(Function f) { - Objects.requireNonNull(f, "f is null"); if (isEmpty()) { return Option.none(); } else { @@ -1214,7 +1201,6 @@ default Number product() { * @throws NullPointerException if {@code op} is null */ default T reduce(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return reduceLeft(op); } @@ -1227,7 +1213,6 @@ default T reduce(BiFunction op) { * @throws NullPointerException if {@code op} is null */ default Option reduceOption(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return reduceLeftOption(op); } @@ -1240,7 +1225,6 @@ default Option reduceOption(BiFunction op) * @throws NullPointerException if {@code op} is null */ default T reduceLeft(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return iterator().reduceLeft(op); } @@ -1254,7 +1238,6 @@ default T reduceLeft(BiFunction op) { * @throws NullPointerException if {@code op} is null */ default Option reduceLeftOption(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return isEmpty() ? Option.none() : Option.some(reduceLeft(op)); } @@ -1267,7 +1250,6 @@ default Option reduceLeftOption(BiFunction * @throws NullPointerException if {@code op} is null */ default T reduceRight(BiFunction op) { - Objects.requireNonNull(op, "op is null"); if (isEmpty()) { throw new NoSuchElementException("reduceRight on empty"); } else { @@ -1285,7 +1267,6 @@ default T reduceRight(BiFunction op) { * @throws NullPointerException if {@code op} is null */ default Option reduceRightOption(BiFunction op) { - Objects.requireNonNull(op, "op is null"); return isEmpty() ? Option.none() : Option.some(reduceRight(op)); } @@ -1603,8 +1584,6 @@ default Number sum() { */ default Tuple2, Iterator> unzip( Function unzipper1, Function unzipper2) { - Objects.requireNonNull(unzipper1, "unzipper1 is null"); - Objects.requireNonNull(unzipper2, "unzipper2 is null"); final Iterator iter1 = iterator().map(unzipper1); final Iterator iter2 = iterator().map(unzipper2); return Tuple.of(iter1, iter2); @@ -1626,9 +1605,6 @@ default Tuple3, Iterator, Iterator> unzip3( Function unzipper1, Function unzipper2, Function unzipper3) { - Objects.requireNonNull(unzipper1, "unzipper1 is null"); - Objects.requireNonNull(unzipper2, "unzipper2 is null"); - Objects.requireNonNull(unzipper2, "unzipper3 is null"); final Iterator iter1 = iterator().map(unzipper1); final Iterator iter2 = iterator().map(unzipper2); final Iterator iter3 = iterator().map(unzipper3); @@ -1723,7 +1699,6 @@ default SortedMap toSortedMap( Function keyMapper, Function valueMapper, BiFunction merge) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); if (isEmpty()) { return TreeMap.empty(keyComparator); } @@ -1786,9 +1761,6 @@ default Map toMap( Function keyMapper, Function valueMapper, BiFunction merge) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); - Objects.requireNonNull(merge, "merge is null"); if (isEmpty()) { return HashMap.empty(); } diff --git a/src/main/java/io/vavr/collection/Tree.java b/src/main/java/io/vavr/collection/Tree.java index 919a7b5d3..b0aa721e5 100644 --- a/src/main/java/io/vavr/collection/Tree.java +++ b/src/main/java/io/vavr/collection/Tree.java @@ -106,7 +106,6 @@ public static Node of(T value) { @SuppressWarnings("varargs") @SafeVarargs public static Node of(T value, Node... children) { - Objects.requireNonNull(children, "children is null"); return new Node<>(value, io.vavr.collection.List.of(children)); } @@ -119,7 +118,6 @@ public static Node of(T value, Node... children) { * @return A new Node instance. */ public static Node of(T value, Iterable> children) { - Objects.requireNonNull(children, "children is null"); return new Node<>(value, io.vavr.collection.List.ofAll(children)); } @@ -134,7 +132,6 @@ public static Node of(T value, Iterable> children) { @SuppressWarnings("varargs") @SafeVarargs public static Tree of(T... values) { - Objects.requireNonNull(values, "values is null"); final io.vavr.collection.List list = io.vavr.collection.List.of(values); return list.isEmpty() ? Empty.instance() : new Node<>(list.head(), list.tail().map(Tree::of)); } @@ -152,7 +149,6 @@ public static Tree of(T... values) { */ @SuppressWarnings("unchecked") public static Tree ofAll(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); if (iterable instanceof Tree) { return (Tree) iterable; } else { @@ -169,7 +165,6 @@ public static Tree ofAll(Iterable iterable) { * @return A Tree containing the given elements in the same order. */ public static Tree ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(io.vavr.collection.Iterator.ofAll(javaStream.iterator())); } @@ -184,7 +179,6 @@ public static Tree ofAll(java.util.stream.Stream javaStream) * @throws NullPointerException if {@code f} is null */ public static Tree tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return io.vavr.collection.Collections.tabulate(n, f, empty(), Tree::of); } @@ -198,7 +192,6 @@ public static Tree tabulate(int n, Function * @throws NullPointerException if {@code s} is null */ public static Tree fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return io.vavr.collection.Collections.fill(n, s, empty(), Tree::of); } @@ -241,7 +234,6 @@ public static Tree fill(int n, T element) { * @throws NullPointerException if {@code descend} is null */ public static Node recurse(T seed, Function> descend) { - Objects.requireNonNull(descend, "descend is null"); return Tree.of(seed, Stream.of(seed).flatMap(descend).map(children -> recurse(children, descend))); } @@ -271,9 +263,6 @@ public static Node recurse(T seed, Function List> build(Iterable source, Function idMapper, Function parentMapper) { - Objects.requireNonNull(source, "source is null"); - Objects.requireNonNull(source, "idMapper is null"); - Objects.requireNonNull(source, "parentMapper is null"); final List list = List.ofAll(source); final Map> byParent = list.groupBy(parentMapper); final Function> descend = idMapper @@ -377,7 +366,6 @@ public final io.vavr.collection.Iterator iterator(Order order) { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -398,7 +386,6 @@ public final Seq> traverse() { * @throws java.lang.NullPointerException if order is null */ public final Seq> traverse(Order order) { - Objects.requireNonNull(order, "order is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -486,7 +473,6 @@ public final Seq distinct() { @Override public final Seq distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -496,7 +482,6 @@ public final Seq distinctBy(Comparator comparator) { @Override public final Seq distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -524,13 +509,11 @@ public final Seq dropRight(int n) { @Override public final Seq dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public final Seq dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -540,7 +523,6 @@ public final Seq dropWhile(Predicate predicate) { @Override public final Seq filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -550,7 +532,6 @@ public final Seq filter(Predicate predicate) { @Override public final Seq filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Stream.empty(); } else { @@ -560,13 +541,11 @@ public final Seq filterNot(Predicate predicate) { @Override public final Tree flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? Empty.instance() : Tree.flatMap((Node) this, mapper); } @Override public final U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); if (isEmpty()) { return zero; } else { @@ -625,7 +604,6 @@ public final io.vavr.collection.Iterator iterator() { @Override public final Tree map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? Empty.instance() : Tree.map((Node) this, mapper); } @@ -642,7 +620,6 @@ public final Tree orElse(Supplier> supplier) @SuppressWarnings("unchecked") @Override public final Tuple2, Seq> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Tuple.of(Stream.empty(), Stream.empty()); } else { @@ -652,7 +629,6 @@ public final Tuple2, Seq> partition(Predicate predicate) { @Override public final Tree peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -675,7 +651,6 @@ public final Tree replaceAll(T currentElement, T newElement) { @Override public final Seq retainAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); return values().retainAll(elements); } @@ -712,7 +687,6 @@ public final io.vavr.collection.Iterator> sliding(int size, int step) { @SuppressWarnings("unchecked") @Override public final Tuple2, Seq> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); if (isEmpty()) { return Tuple.of(Stream.empty(), Stream.empty()); } else { @@ -759,13 +733,11 @@ public final Seq takeRight(int n) { @Override public final Seq takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return values().takeUntil(predicate); } @Override public final Seq takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return values().takeWhile(predicate); } @@ -776,8 +748,6 @@ public final Tree> zip(Iterable that) { @Override public final Tree zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); if (isEmpty()) { return Empty.instance(); } else { @@ -787,7 +757,6 @@ public final Tree zipWith(Iterable that, BiFunction Tree> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); if (isEmpty()) { return io.vavr.collection.Iterator.ofAll(that).map(elem -> Tuple.of(thisElem, elem)).toTree(); } else { @@ -811,7 +780,6 @@ public final Tree> zipWithIndex() { @Override public final Tree zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return zipWith(io.vavr.collection.Iterator.from(0), mapper); } @@ -847,7 +815,6 @@ public static final class Node extends Tree implements Serializable { * @throws IllegalArgumentException if children is empty */ public Node(T value, io.vavr.collection.List> children) { - Objects.requireNonNull(children, "children is null"); this.value = value; this.children = children; this.size = children.foldLeft(1, (acc, child) -> acc + child.size); diff --git a/src/main/java/io/vavr/collection/TreeMap.java b/src/main/java/io/vavr/collection/TreeMap.java index 5ae1b1556..f8680dd36 100644 --- a/src/main/java/io/vavr/collection/TreeMap.java +++ b/src/main/java/io/vavr/collection/TreeMap.java @@ -98,8 +98,6 @@ public static Collector, ArrayList>, TreeMap, V, T extends V> Collector, TreeMap> collector( Function keyMapper) { - Objects.requireNonNull(keyMapper, "key comparator is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); return createCollector(EntryComparator.natural(), keyMapper, v -> v); } @@ -119,9 +117,6 @@ public static , V, T extends V> Collector, V, T> Collector, TreeMap> collector( Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "key comparator is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return createCollector(EntryComparator.natural(), keyMapper, valueMapper); } @@ -139,8 +134,6 @@ public static , V, T> Collector, public static Collector, TreeMap> collector( Comparator keyComparator, Function keyMapper) { - Objects.requireNonNull(keyMapper, "key comparator is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); return createCollector(EntryComparator.of(keyComparator), keyMapper, v -> v); } @@ -159,9 +152,6 @@ public static Collector, TreeMap> coll public static Collector, TreeMap> collector( Comparator keyComparator, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "key comparator is null"); - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return createCollector(EntryComparator.of(keyComparator), keyMapper, valueMapper); } @@ -215,7 +205,6 @@ public static TreeMap narrow(TreeMap tree * @return A new TreeMap containing the given entry. */ public static , V> TreeMap of(Tuple2 entry) { - Objects.requireNonNull(entry, "entry is null"); return createFromTuple(EntryComparator.natural(), entry); } @@ -229,7 +218,6 @@ public static , V> TreeMap of(Tuple2 TreeMap of(Comparator keyComparator, Tuple2 entry) { - Objects.requireNonNull(entry, "entry is null"); return createFromTuple(EntryComparator.of(keyComparator), entry); } @@ -242,7 +230,6 @@ public static TreeMap of(Comparator keyComparator, Tuple * @return A new Map containing the given map */ public static , V> TreeMap ofAll(java.util.Map map) { - Objects.requireNonNull(map, "map is null"); return createFromMap(EntryComparator.natural(), map); } @@ -324,7 +311,6 @@ public static TreeMap ofAll(Comparator keyComparator, * @return A new Map containing the given map */ public static TreeMap ofAll(Comparator keyComparator, java.util.Map map) { - Objects.requireNonNull(map, "map is null"); return createFromMap(EntryComparator.of(keyComparator), map); } @@ -791,7 +777,6 @@ public static TreeMap of(Comparator keyComparator, K k1, * @throws NullPointerException if {@code keyComparator} or {@code f} are null */ public static TreeMap tabulate(Comparator keyComparator, int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return createTreeMap(EntryComparator.of(keyComparator), Collections.tabulate(n, f)); } @@ -808,7 +793,6 @@ public static TreeMap tabulate(Comparator keyComparator, * @throws NullPointerException if {@code f} is null */ public static , V> TreeMap tabulate(int n, Function> f) { - Objects.requireNonNull(f, "f is null"); return createTreeMap(EntryComparator.natural(), Collections.tabulate(n, f)); } @@ -825,7 +809,6 @@ public static , V> TreeMap tabulate(int n, */ @SuppressWarnings("unchecked") public static TreeMap fill(Comparator keyComparator, int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return createTreeMap(EntryComparator.of(keyComparator), Collections.fill(n, s)); } @@ -841,7 +824,6 @@ public static TreeMap fill(Comparator keyComparator, int * @throws NullPointerException if {@code s} is null */ public static , V> TreeMap fill(int n, Supplier> s) { - Objects.requireNonNull(s, "s is null"); return createTreeMap(EntryComparator.natural(), Collections.fill(n, s)); } @@ -1140,13 +1122,11 @@ public TreeMap map(BiFunction TreeMap map(Comparator keyComparator, BiFunction> mapper) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); return map(this, EntryComparator.of(keyComparator), mapper); } @Override public TreeMap mapKeys(Function keyMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); return map((k, v) -> Tuple.of(keyMapper.apply(k), v)); } @@ -1158,7 +1138,6 @@ public TreeMap mapKeys(Function keyMapper, @Override public TreeMap mapValues(Function valueMapper) { - Objects.requireNonNull(valueMapper, "valueMapper is null"); return map(comparator(), (k, v) -> Tuple.of(k, valueMapper.apply(v))); } @@ -1285,7 +1264,6 @@ public TreeMap replaceAll(BiFunction fu @Override public TreeMap retainAll(Iterable> elements) { - Objects.requireNonNull(elements, "elements is null"); RedBlackTree> tree = RedBlackTree.empty(entries.comparator()); for (Tuple2 entry : elements) { if (contains(entry)) { @@ -1398,20 +1376,16 @@ public String toString() { private static TreeMap bimap(TreeMap map, EntryComparator entryComparator, Function keyMapper, Function valueMapper) { - Objects.requireNonNull(keyMapper, "keyMapper is null"); - Objects.requireNonNull(valueMapper, "valueMapper is null"); return createTreeMap(entryComparator, map.entries, entry -> entry.map(keyMapper, valueMapper)); } private static TreeMap flatMap(TreeMap map, EntryComparator entryComparator, BiFunction>> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return createTreeMap(entryComparator, map.entries.iterator().flatMap(entry -> mapper.apply(entry._1, entry._2))); } private static TreeMap map(TreeMap map, EntryComparator entryComparator, BiFunction> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return createTreeMap(entryComparator, map.entries, entry -> entry.map(mapper)); } @@ -1431,7 +1405,6 @@ private static Collector, TreeMap> createCollect @SuppressWarnings("unchecked") private static TreeMap createTreeMap(EntryComparator entryComparator, Iterable> entries) { - Objects.requireNonNull(entries, "entries is null"); RedBlackTree> tree = RedBlackTree.empty(entryComparator); for (Tuple2 entry : (Iterable>) entries) { tree = tree.insert(entry); @@ -1450,7 +1423,6 @@ private static TreeMap createTreeMap(EntryComparator TreeMap createFromMap(EntryComparator entryComparator, java.util.Map map) { - Objects.requireNonNull(map, "map is null"); RedBlackTree> tree = RedBlackTree.empty(entryComparator); for (java.util.Map.Entry entry : ((java.util.Map) map).entrySet()) { tree = tree.insert(Tuple.of(entry.getKey(), entry.getValue())); @@ -1460,13 +1432,11 @@ private static TreeMap createFromMap(EntryComparator entryCom @SuppressWarnings("unchecked") private static TreeMap createFromTuple(EntryComparator entryComparator, Tuple2 entry) { - Objects.requireNonNull(entry, "entry is null"); return new TreeMap<>(RedBlackTree.of(entryComparator, (Tuple2) entry)); } @SuppressWarnings("unchecked") private static TreeMap createFromTuples(EntryComparator entryComparator, Tuple2... entries) { - Objects.requireNonNull(entries, "entries is null"); RedBlackTree> tree = RedBlackTree.empty(entryComparator); for (Tuple2 entry : entries) { tree = tree.insert((Tuple2) entry); @@ -1476,7 +1446,6 @@ private static TreeMap createFromTuples(EntryComparator entry @SafeVarargs private static TreeMap createFromMapEntries(EntryComparator entryComparator, java.util.Map.Entry... entries) { - Objects.requireNonNull(entries, "entries is null"); RedBlackTree> tree = RedBlackTree.empty(entryComparator); for (java.util.Map.Entry entry : entries) { final K key = entry.getKey(); @@ -1517,7 +1486,6 @@ private interface EntryComparator extends Comparator>, Serial long serialVersionUID = 1L; static EntryComparator of(Comparator keyComparator) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); return new Specific<>(keyComparator); } diff --git a/src/main/java/io/vavr/collection/TreeMultimap.java b/src/main/java/io/vavr/collection/TreeMultimap.java index e3da5b05d..caa6332ca 100644 --- a/src/main/java/io/vavr/collection/TreeMultimap.java +++ b/src/main/java/io/vavr/collection/TreeMultimap.java @@ -97,7 +97,6 @@ public , V2 extends V> TreeMultimap empty * @return A new empty TreeMultimap. */ public TreeMultimap empty(Comparator keyComparator) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); return new TreeMultimap<>(TreeMap.empty(keyComparator), containerType, emptyContainer); } @@ -124,8 +123,6 @@ public , V2 extends V> TreeMultimap ofEnt * @return A new TreeMultimap containing the given entries. */ public TreeMultimap ofEntries(Comparator keyComparator, Iterable> entries) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); - Objects.requireNonNull(entries, "entries is null"); TreeMultimap result = empty(keyComparator); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -160,8 +157,6 @@ public final , V2 extends V> TreeMultimap @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public final TreeMultimap ofEntries(Comparator keyComparator, Tuple2... entries) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); - Objects.requireNonNull(entries, "entries is null"); TreeMultimap result = empty(keyComparator); for (Tuple2 entry : entries) { result = result.put(entry._1, entry._2); @@ -196,8 +191,6 @@ public final , V2 extends V> TreeMultimap @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public final TreeMultimap ofEntries(Comparator keyComparator, java.util.Map.Entry... entries) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); - Objects.requireNonNull(entries, "entries is null"); TreeMultimap result = empty(keyComparator); for (java.util.Map.Entry entry : entries) { result = result.put(entry.getKey(), entry.getValue()); @@ -329,8 +322,6 @@ public , V2 extends V> TreeMultimap tabul */ @SuppressWarnings("unchecked") public TreeMultimap tabulate(Comparator keyComparator, int n, Function> f) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); - Objects.requireNonNull(f, "f is null"); return ofEntries(keyComparator, Collections.tabulate(n, (Function>) f)); } @@ -363,8 +354,6 @@ public , V2 extends V> TreeMultimap fill( */ @SuppressWarnings("unchecked") public TreeMultimap fill(Comparator keyComparator, int n, Supplier> s) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); - Objects.requireNonNull(s, "s is null"); return ofEntries(keyComparator, Collections.fill(n, (Supplier>) s)); } @@ -395,7 +384,6 @@ public , V2 extends V> TreeMultimap fill( */ @SuppressWarnings("unchecked") public TreeMultimap fill(Comparator keyComparator, int n, Tuple2 element) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); return ofEntries(keyComparator, Collections.fillObject(n, element)); } @@ -902,7 +890,6 @@ public , V2 extends V> Collector, * @return A {@link TreeMultimap} Collector. */ public Collector, ArrayList>, TreeMultimap> collector(Comparator keyComparator) { - Objects.requireNonNull(keyComparator, "keyComparator is null"); return Collections.toListAndThen(list -> ofEntries(keyComparator, list)); } } diff --git a/src/main/java/io/vavr/collection/TreeSet.java b/src/main/java/io/vavr/collection/TreeSet.java index 470ddd4ad..9900c511b 100644 --- a/src/main/java/io/vavr/collection/TreeSet.java +++ b/src/main/java/io/vavr/collection/TreeSet.java @@ -76,7 +76,6 @@ public static > Collector, TreeS * @return A io.vavr.collection.List Collector. */ public static Collector, TreeSet> collector(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return Collections.toListAndThen(list -> TreeSet.ofAll(comparator, list)); } @@ -85,7 +84,6 @@ public static > TreeSet empty() { } public static TreeSet empty(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return new TreeSet<>(RedBlackTree.empty(comparator)); } @@ -110,7 +108,6 @@ public static > TreeSet of(T value) { } public static TreeSet of(Comparator comparator, T value) { - Objects.requireNonNull(comparator, "comparator is null"); return new TreeSet<>(RedBlackTree.of(comparator, value)); } @@ -123,8 +120,6 @@ public static > TreeSet of(T... values) { @SuppressWarnings("varargs") @SafeVarargs public static TreeSet of(Comparator comparator, T... values) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(values, "values is null"); return new TreeSet<>(RedBlackTree.of(comparator, values)); } @@ -140,8 +135,6 @@ public static TreeSet of(Comparator comparator, T... values) { * @throws NullPointerException if {@code comparator} or {@code f} are null */ public static TreeSet tabulate(Comparator comparator, int n, Function f) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(f, "f is null"); return Collections.tabulate(n, f, TreeSet.empty(comparator), values -> of(comparator, values)); } @@ -157,7 +150,6 @@ public static TreeSet tabulate(Comparator comparator, int n, F * @throws NullPointerException if {@code f} is null */ public static > TreeSet tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return tabulate(Comparators.naturalComparator(), n, f); } @@ -172,8 +164,6 @@ public static > TreeSet tabulate(int n, Funct * @throws NullPointerException if {@code comparator} or {@code s} are null */ public static TreeSet fill(Comparator comparator, int n, Supplier s) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(s, "s is null"); return Collections.fill(n, s, TreeSet.empty(comparator), values -> of(comparator, values)); } @@ -188,7 +178,6 @@ public static TreeSet fill(Comparator comparator, int n, Suppl * @throws NullPointerException if {@code s} is null */ public static > TreeSet fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return fill(Comparators.naturalComparator(), n, s); } @@ -198,8 +187,6 @@ public static > TreeSet ofAll(Iterable TreeSet ofAll(Comparator comparator, Iterable values) { - Objects.requireNonNull(comparator, "comparator is null"); - Objects.requireNonNull(values, "values is null"); if (values instanceof TreeSet && ((TreeSet) values).comparator() == comparator) { return (TreeSet) values; } else { @@ -208,12 +195,10 @@ public static TreeSet ofAll(Comparator comparator, Iterable> TreeSet ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(Iterator.ofAll(javaStream.iterator())); } public static TreeSet ofAll(Comparator comparator, java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(comparator, Iterator.ofAll(javaStream.iterator())); } @@ -225,7 +210,6 @@ public static TreeSet ofAll(Comparator comparator, java.util.s * @throws NullPointerException if elements is null */ public static TreeSet ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -237,7 +221,6 @@ public static TreeSet ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -249,7 +232,6 @@ public static TreeSet ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -261,7 +243,6 @@ public static TreeSet ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -273,7 +254,6 @@ public static TreeSet ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -285,7 +265,6 @@ public static TreeSet ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -297,7 +276,6 @@ public static TreeSet ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -309,7 +287,6 @@ public static TreeSet ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static TreeSet ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); } @@ -528,7 +505,6 @@ public TreeSet add(T element) { @Override public TreeSet addAll(Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); RedBlackTree that = tree; for (T element : elements) { if (!that.contains(element)) { @@ -555,7 +531,6 @@ public Comparator comparator() { @SuppressWarnings("unchecked") @Override public TreeSet diff(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { return this; } else if (elements instanceof TreeSet) { @@ -578,13 +553,11 @@ public TreeSet distinct() { @Override public TreeSet distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : TreeSet.ofAll(tree.comparator(), iterator().distinctBy(comparator)); } @Override public TreeSet distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); return isEmpty() ? this : TreeSet.ofAll(tree.comparator(), iterator().distinctBy(keyExtractor)); } @@ -612,46 +585,39 @@ public TreeSet dropRight(int n) { @Override public TreeSet dropUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropWhile(predicate.negate()); } @Override public TreeSet dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final TreeSet treeSet = TreeSet.ofAll(tree.comparator(), iterator().dropWhile(predicate)); return (treeSet.length() == length()) ? this : treeSet; } @Override public TreeSet filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final TreeSet treeSet = TreeSet.ofAll(tree.comparator(), iterator().filter(predicate)); return (treeSet.length() == length()) ? this : treeSet; } @Override public TreeSet filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @Override public TreeSet flatMap(Comparator comparator, Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().flatMap(mapper)); } @Override public Set flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? HashSet.empty() : HashSet.ofAll(this).flatMap(mapper); } @Override public U foldRight(U zero, BiFunction f) { - Objects.requireNonNull(f, "f is null"); return iterator().foldRight(zero, f); } @@ -701,7 +667,6 @@ public Option> initOption() { @SuppressWarnings("unchecked") @Override public TreeSet intersect(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (isEmpty()) { return this; } else if (elements instanceof TreeSet) { @@ -763,13 +728,11 @@ public int length() { @Override public TreeSet map(Comparator comparator, Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().map(mapper)); } @Override public Set map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? HashSet.empty() : HashSet.ofAll(this).map(mapper); } @@ -806,7 +769,6 @@ public Tuple2, TreeSet> partition(Predicate predicate) @Override public TreeSet peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -885,7 +847,6 @@ public Iterator> sliding(int size, int step) { @Override public Tuple2, TreeSet> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return iterator().span(predicate).map(i1 -> TreeSet.ofAll(tree.comparator(), i1), i2 -> TreeSet.ofAll(tree.comparator(), i2)); } @@ -928,14 +889,12 @@ public TreeSet takeRight(int n) { @Override public TreeSet takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final TreeSet treeSet = takeWhile(predicate.negate()); return (treeSet.length() == length()) ? this : treeSet; } @Override public TreeSet takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final TreeSet treeSet = TreeSet.ofAll(tree.comparator(), iterator().takeWhile(predicate)); return (treeSet.length() == length()) ? this : treeSet; } @@ -949,7 +908,6 @@ public TreeSet takeWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -961,7 +919,6 @@ public java.util.TreeSet toJavaSet() { @SuppressWarnings("unchecked") @Override public TreeSet union(Set elements) { - Objects.requireNonNull(elements, "elements is null"); if (elements instanceof TreeSet) { final TreeSet that = (TreeSet) elements; return that.isEmpty() ? this : new TreeSet<>(tree.union(that.tree)); @@ -972,21 +929,17 @@ public TreeSet union(Set elements) { @Override public TreeSet> zip(Iterable that) { - Objects.requireNonNull(that, "that is null"); final Comparator> tuple2Comparator = Tuple2.comparator(tree.comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zipWith(that, Tuple::of)); } @Override public TreeSet zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWith(that, mapper)); } @Override public TreeSet> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); final Comparator> tuple2Comparator = Tuple2.comparator(tree.comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zipAll(that, thisElem, thatElem)); } diff --git a/src/main/java/io/vavr/collection/Vector.java b/src/main/java/io/vavr/collection/Vector.java index 1a26e08d9..e435cb2e4 100644 --- a/src/main/java/io/vavr/collection/Vector.java +++ b/src/main/java/io/vavr/collection/Vector.java @@ -124,7 +124,6 @@ public static Vector of(T element) { @SafeVarargs @SuppressWarnings("varargs") public static Vector of(T... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -139,7 +138,6 @@ public static Vector of(T... elements) { * @throws NullPointerException if {@code f} is null */ public static Vector tabulate(int n, Function f) { - Objects.requireNonNull(f, "f is null"); return io.vavr.collection.Collections.tabulate(n, f, empty(), Vector::of); } @@ -153,7 +151,6 @@ public static Vector tabulate(int n, Function Vector fill(int n, Supplier s) { - Objects.requireNonNull(s, "s is null"); return io.vavr.collection.Collections.fill(n, s, empty(), Vector::of); } @@ -182,7 +179,6 @@ public static Vector fill(int n, T element) { */ @SuppressWarnings("unchecked") public static Vector ofAll(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); if (iterable instanceof Traversable && io.vavr.collection.Collections.isEmpty(iterable)) { return empty(); } @@ -205,7 +201,6 @@ public static Vector ofAll(Iterable iterable) { * @return A Vector containing the given elements in the same order. */ public static Vector ofAll(java.util.stream.Stream javaStream) { - Objects.requireNonNull(javaStream, "javaStream is null"); return ofAll(Iterator.ofAll(javaStream.iterator())); } @@ -217,7 +212,6 @@ public static Vector ofAll(java.util.stream.Stream javaStrea * @throws NullPointerException if elements is null */ public static Vector ofAll(boolean... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -229,7 +223,6 @@ public static Vector ofAll(boolean... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(byte... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -241,7 +234,6 @@ public static Vector ofAll(byte... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(char... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -253,7 +245,6 @@ public static Vector ofAll(char... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(double... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -265,7 +256,6 @@ public static Vector ofAll(double... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(float... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -277,7 +267,6 @@ public static Vector ofAll(float... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(int... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -289,7 +278,6 @@ public static Vector ofAll(int... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(long... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -301,7 +289,6 @@ public static Vector ofAll(long... elements) { * @throws NullPointerException if elements is null */ public static Vector ofAll(short... elements) { - Objects.requireNonNull(elements, "elements is null"); return ofAll(BitMappedTrie.ofAll(elements)); } @@ -620,7 +607,6 @@ public static Vector unfold(T seed, Function appendAll(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); if (isEmpty()) { return ofAll(iterable); } @@ -669,14 +655,12 @@ public Vector collect(PartialFunction partialFunc @Override public Vector distinctBy(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); final java.util.Set seen = new java.util.TreeSet<>(comparator); return filter(seen::add); } @Override public Vector distinctBy(Function keyExtractor) { - Objects.requireNonNull(keyExtractor, "keyExtractor is null"); final java.util.Set seen = new java.util.HashSet<>(length()); return filter(t -> seen.add(keyExtractor.apply(t))); } @@ -693,7 +677,6 @@ public Vector dropUntil(Predicate predicate) { @Override public Vector dropWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropUntil(predicate.negate()); } @@ -709,25 +692,21 @@ public Vector dropRightUntil(Predicate predicate) { @Override public Vector dropRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return dropRightUntil(predicate.negate()); } @Override public Vector filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return wrap(trie.filter(predicate)); } @Override public Vector filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Collections.filterNot(this, predicate); } @Override public Vector flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); final Iterator results = iterator().flatMap(mapper); return ofAll(results); } @@ -787,7 +766,6 @@ public Vector init() { @Override public Vector insertAll(int index, Iterable elements) { - Objects.requireNonNull(elements, "elements is null"); if ((index >= 0) && (index <= length())) { final Vector begin = take(index).appendAll(elements); final Vector end = drop(index); @@ -849,7 +827,6 @@ public int lastIndexOf(T element, int end) { @Override public Vector map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(trie.map(mapper)); } @@ -895,7 +872,6 @@ public Vector patch(int from, Iterable that, int replaced) { @Override public Tuple2, Vector> partition(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final ArrayList left = new ArrayList<>(), right = new ArrayList<>(); for (int i = 0; i < length(); i++) { final T t = get(i); @@ -906,7 +882,6 @@ public Tuple2, Vector> partition(Predicate predicate) { @Override public Vector peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (!isEmpty()) { action.accept(head()); } @@ -935,7 +910,6 @@ public Vector> permutations() { @Override public Vector prependAll(Iterable iterable) { - Objects.requireNonNull(iterable, "iterable is null"); if (isEmpty()) { return ofAll(iterable); } @@ -957,7 +931,6 @@ public Vector remove(T element) { @Override public Vector removeFirst(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = 0; i < length(); i++) { if (predicate.test(get(i))) { return removeAt(i); @@ -968,7 +941,6 @@ public Vector removeFirst(Predicate predicate) { @Override public Vector removeLast(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = length() - 1; i >= 0; i--) { if (predicate.test(get(i))) { return removeAt(i); @@ -1105,7 +1077,6 @@ public Vector sorted() { @Override public Vector sorted(Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : toJavaStream().sorted(comparator).collect(collector()); } @@ -1121,7 +1092,6 @@ public Vector sortBy(Comparator comparator, Function, Vector> span(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return Tuple.of(takeWhile(predicate), dropWhile(predicate)); } @@ -1132,14 +1102,12 @@ public Tuple2, Vector> splitAt(int n) { @Override public Tuple2, Vector> splitAt(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); final Vector init = takeWhile(predicate.negate()); return Tuple.of(init, drop(init.size())); } @Override public Tuple2, Vector> splitAtInclusive(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); for (int i = 0; i < length(); i++) { final T value = get(i); if (predicate.test(value)) { @@ -1189,7 +1157,6 @@ public Vector takeUntil(Predicate predicate) { @Override public Vector takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeUntil(predicate.negate()); } @@ -1205,7 +1172,6 @@ public Vector takeRightUntil(Predicate predicate) { @Override public Vector takeRightWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return takeRightUntil(predicate.negate()); } @@ -1218,7 +1184,6 @@ public Vector takeRightWhile(Predicate predicate) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1233,7 +1198,6 @@ public Vector update(int index, T element) { @Override public Vector update(int index, Function updater) { - Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); } @@ -1244,14 +1208,11 @@ public Vector> zip(Iterable that) { @Override public Vector zipWith(Iterable that, BiFunction mapper) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWith(that, mapper)); } @Override public Vector> zipAll(Iterable that, T thisElem, U thatElem) { - Objects.requireNonNull(that, "that is null"); return ofAll(iterator().zipAll(that, thisElem, thatElem)); } @@ -1262,7 +1223,6 @@ public Vector> zipWithIndex() { @Override public Vector zipWithIndex(BiFunction mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return ofAll(iterator().zipWithIndex(mapper)); } diff --git a/src/main/java/io/vavr/concurrent/Future.java b/src/main/java/io/vavr/concurrent/Future.java index 00b7e91ce..746eacafc 100644 --- a/src/main/java/io/vavr/concurrent/Future.java +++ b/src/main/java/io/vavr/concurrent/Future.java @@ -125,7 +125,6 @@ public interface Future extends Iterable, Value { * @throws NullPointerException if exception is null */ static Future failed(Throwable exception) { - Objects.requireNonNull(exception, "exception is null"); return failed(DEFAULT_EXECUTOR, exception); } @@ -139,8 +138,6 @@ static Future failed(Throwable exception) { * @throws NullPointerException if executor or exception is null */ static Future failed(Executor executor, Throwable exception) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(exception, "exception is null"); return FutureImpl.of(executor, Try.failure(exception)); } @@ -174,9 +171,6 @@ static Future> find(Iterable> future * @throws NullPointerException if one of the arguments is null */ static Future> find(Executor executor, Iterable> futures, Predicate predicate) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(futures, "futures is null"); - Objects.requireNonNull(predicate, "predicate is null"); final List> list = List.ofAll(futures); if (list.isEmpty()) { return successful(executor, Option.none()); @@ -229,8 +223,6 @@ static Future firstCompletedOf(Iterable> fu * @throws NullPointerException if executor or futures is null */ static Future firstCompletedOf(Executor executor, Iterable> futures) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(futures, "futures is null"); return run(executor, complete -> futures.forEach(future -> future.onComplete(complete::with))); } @@ -268,9 +260,6 @@ static Future fold(Iterable> futures, U * @throws NullPointerException if executor, futures or f is null. */ static Future fold(Executor executor, Iterable> futures, U zero, BiFunction f) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(futures, "futures is null"); - Objects.requireNonNull(f, "f is null"); if (!futures.iterator().hasNext()) { return successful(executor, zero); } else { @@ -287,7 +276,6 @@ static Future fold(Executor executor, Iterable Future fromJavaFuture(java.util.concurrent.Future future) { - Objects.requireNonNull(future, "future is null"); return of(DEFAULT_EXECUTOR, future::get); } @@ -301,8 +289,6 @@ static Future fromJavaFuture(java.util.concurrent.Future future) { * @throws NullPointerException if executor or future is null */ static Future fromJavaFuture(Executor executor, java.util.concurrent.Future future) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(future, "future is null"); return of(executor, future::get); } @@ -328,8 +314,6 @@ static Future fromCompletableFuture(CompletableFuture future) { * @throws NullPointerException if executor or future is null */ static Future fromCompletableFuture(Executor executor, CompletableFuture future) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(future, "future is null"); if (future.isDone() || future.isCompletedExceptionally() || future.isCancelled()) { return fromTry(Try.of(future::get).recoverWith(error -> Try.failure(error.getCause()))); } else { @@ -361,8 +345,6 @@ static Future fromTry(Try result) { * @throws NullPointerException if executor or result is null */ static Future fromTry(Executor executor, Try result) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(result, "result is null"); return FutureImpl.of(executor, result); } @@ -391,7 +373,6 @@ static Future narrow(Future future) { */ @Deprecated static Future ofSupplier(Supplier computation) { - Objects.requireNonNull(computation, "computation is null"); return of(DEFAULT_EXECUTOR, computation::get); } @@ -407,8 +388,6 @@ static Future ofSupplier(Supplier computation) { */ @Deprecated static Future ofSupplier(Executor executor, Supplier computation) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(computation, "computation is null"); return of(executor, computation::get); } @@ -423,7 +402,6 @@ static Future ofSupplier(Executor executor, Supplier computa */ @Deprecated static Future ofCallable(Callable computation) { - Objects.requireNonNull(computation, "computation is null"); return of(DEFAULT_EXECUTOR, computation::call); } @@ -439,8 +417,6 @@ static Future ofCallable(Callable computation) { */ @Deprecated static Future ofCallable(Executor executor, Callable computation) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(computation, "computation is null"); return of(executor, computation::call); } @@ -454,7 +430,6 @@ static Future ofCallable(Executor executor, Callable computa */ @Deprecated static Future runRunnable(Runnable computation) { - Objects.requireNonNull(computation, "computation is null"); return run(DEFAULT_EXECUTOR, computation::run); } @@ -469,8 +444,6 @@ static Future runRunnable(Runnable computation) { */ @Deprecated static Future runRunnable(Executor executor, Runnable computation) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(computation, "computation is null"); return run(executor, computation::run); } @@ -496,8 +469,6 @@ static Future of(CheckedFunction0 computation) { * @throws NullPointerException if one of executor or computation is null. */ static Future of(Executor executor, CheckedFunction0 computation) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(computation, "computation is null"); return FutureImpl.async(executor, complete -> complete.with(Try.of(computation))); } @@ -610,9 +581,6 @@ static Future reduce(Iterable> futures, BiF * @throws NullPointerException if executor, futures or f is null. */ static Future reduce(Executor executor, Iterable> futures, BiFunction f) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(futures, "futures is null"); - Objects.requireNonNull(f, "f is null"); if (!futures.iterator().hasNext()) { throw new NoSuchElementException("Future.reduce on empty futures"); } else { @@ -640,8 +608,6 @@ static Future run(CheckedRunnable unit) { * @throws NullPointerException if one of executor or unit is null. */ static Future run(Executor executor, CheckedRunnable unit) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(unit, "unit is null"); return of(executor, () -> { unit.run(); return null; @@ -699,8 +665,6 @@ static Future> sequence(Iterable> futur * @throws NullPointerException if executor or futures is null. */ static Future> sequence(Executor executor, Iterable> futures) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(futures, "futures is null"); final Future> zero = successful(executor, Stream.empty()); final BiFunction>, Future, Future>> f = (result, future) -> result.flatMap(seq -> future.map(seq::append)); @@ -728,7 +692,6 @@ static Future successful(T result) { * @throws NullPointerException if executor is null */ static Future successful(Executor executor, T result) { - Objects.requireNonNull(executor, "executor is null"); return FutureImpl.of(executor, Try.success(result)); } @@ -772,9 +735,6 @@ static Future> traverse(Iterable values, Function Future> traverse(Executor executor, Iterable values, Function> mapper) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(values, "values is null"); - Objects.requireNonNull(mapper, "mapper is null"); return sequence(executor, Iterator.ofAll(values).map(mapper)); } @@ -799,7 +759,6 @@ static Future> traverse(Executor executor, Iterable v * @throws NullPointerException if action is null */ default Future andThen(Consumer> action) { - Objects.requireNonNull(action, "action is null"); return run(executor(), complete -> onComplete(t -> { Try.run(() -> action.accept(t)); @@ -880,7 +839,8 @@ default boolean cancel() { * @throws NullPointerException if {@code partialFunction} is null */ default Future collect(PartialFunction partialFunction) { - Objects.requireNonNull(partialFunction, "partialFunction is null"); + // #2711: CRITICAL: without this null check the future might never complete. + Objects.requireNonNull(partialFunction, "partialFunction"); return run(executor(), complete -> onComplete(result -> complete.with(result.collect(partialFunction))) ); @@ -949,7 +909,6 @@ default Future failed() { * @throws NullPointerException if that is null */ default Future fallbackTo(Future that) { - Objects.requireNonNull(that, "that is null"); return run(executor(), complete -> onComplete(t -> { if (t.isSuccess()) { @@ -969,7 +928,6 @@ default Future fallbackTo(Future that) { * @throws NullPointerException if {@code predicate} is null */ default Future filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterTry(predicate::test); } @@ -981,7 +939,6 @@ default Future filter(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ default Future filterTry(CheckedPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return run(executor(), complete -> onComplete(result -> complete.with(result.filterTry(predicate)))); } @@ -1052,7 +1009,6 @@ default boolean isFailure() { * @throws NullPointerException if {@code action} is null. */ default Future onFailure(Consumer action) { - Objects.requireNonNull(action, "action is null"); return onComplete(result -> result.onFailure(action)); } @@ -1064,7 +1020,6 @@ default Future onFailure(Consumer action) { * @throws NullPointerException if {@code action} is null. */ default Future onSuccess(Consumer action) { - Objects.requireNonNull(action, "action is null"); return onComplete(result -> result.onSuccess(action)); } @@ -1082,7 +1037,6 @@ default Future onSuccess(Consumer action) { * @throws NullPointerException if {@code f} is null */ default Future recover(Function f) { - Objects.requireNonNull(f, "f is null"); return transformValue(t -> t.recover(f)); } @@ -1105,8 +1059,6 @@ default Future recover(Function f) { * @throws NullPointerException if {@code f} is null */ default Future recover(Class exceptionType, Function f) { - Objects.requireNonNull(exceptionType, "exceptionType is null"); - Objects.requireNonNull(f, "f is null"); return transformValue(t -> t.recover(exceptionType, f)); } @@ -1124,7 +1076,6 @@ default Future recover(Class exceptionType, Function * @throws NullPointerException if {@code f} is null */ default Future recoverWith(Function> f) { - Objects.requireNonNull(f, "f is null"); return run(executor(), complete -> onComplete(t -> { if (t.isFailure()) { @@ -1146,7 +1097,6 @@ default Future recoverWith(Function U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1159,7 +1109,6 @@ default U transform(Function, ? extends U> f) { * @throws NullPointerException if {@code f} is null */ default Future transformValue(Function, ? extends Try> f) { - Objects.requireNonNull(f, "f is null"); return run(executor(), complete -> onComplete(t -> Try.run(() -> complete.with(f.apply(t))) .onFailure(x -> complete.with(Try.failure(x))) @@ -1179,7 +1128,6 @@ default Future transformValue(Function, ? extends Try Future> zip(Future that) { - Objects.requireNonNull(that, "that is null"); return zipWith(that, Tuple::of); } @@ -1198,8 +1146,6 @@ default Future> zip(Future that) { */ @SuppressWarnings({"deprecation", "unchecked"}) default Future zipWith(Future that, BiFunction combinator) { - Objects.requireNonNull(that, "that is null"); - Objects.requireNonNull(combinator, "combinator is null"); return run(executor(), complete -> onComplete(res1 -> { if (res1.isFailure()) { @@ -1217,12 +1163,10 @@ default Future zipWith(Future that, BiFunction Future flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return flatMapTry(mapper::apply); } default Future flatMapTry(CheckedFunction1> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return run(executor(), complete -> onComplete(result -> result.mapTry(mapper) .onSuccess(future -> future.onComplete(complete::with)) @@ -1239,7 +1183,6 @@ default Future flatMapTry(CheckedFunction1 action) { - Objects.requireNonNull(action, "action is null"); onComplete(result -> result.forEach(action)); } @@ -1303,17 +1246,14 @@ default Iterator iterator() { @Override default Future map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return transformValue(t -> t.map(mapper)); } default Future mapTry(CheckedFunction1 mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return transformValue(t -> t.mapTry(mapper)); } default Future orElse(Future other) { - Objects.requireNonNull(other, "other is null"); return run(executor(), complete -> onComplete(result -> { if (result.isSuccess()) { @@ -1326,7 +1266,6 @@ default Future orElse(Future other) { } default Future orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return run(executor(), complete -> onComplete(result -> { if (result.isSuccess()) { @@ -1340,7 +1279,6 @@ default Future orElse(Supplier> supplier) { @Override default Future peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); onSuccess(action); return this; } diff --git a/src/main/java/io/vavr/concurrent/FutureImpl.java b/src/main/java/io/vavr/concurrent/FutureImpl.java index ba7c62aad..697872c72 100644 --- a/src/main/java/io/vavr/concurrent/FutureImpl.java +++ b/src/main/java/io/vavr/concurrent/FutureImpl.java @@ -93,7 +93,8 @@ final class FutureImpl implements Future { // single constructor private FutureImpl(Executor executor, Option> value, Queue>> actions, Queue waiters, Computation computation) { - this.executor = executor; + // #2711: null check necessary + this.executor = Objects.requireNonNull(executor, "executor"); synchronized (lock) { this.cancelled = false; this.value = value; @@ -179,7 +180,6 @@ public Future await() { @Override public Future await(long timeout, TimeUnit unit) { final long now = System.nanoTime(); - Objects.requireNonNull(unit, "unit is null"); if (timeout < 0) { throw new IllegalArgumentException("negative timeout"); } @@ -324,7 +324,6 @@ public boolean isCompleted() { @SuppressWarnings("unchecked") @Override public Future onComplete(Consumer> action) { - Objects.requireNonNull(action, "action is null"); if (isCompleted()) { perform(action); } else { @@ -361,7 +360,6 @@ public String toString() { * @throws NullPointerException if the given {@code value} is null. */ boolean tryComplete(Try value) { - Objects.requireNonNull(value, "value is null"); if (isCompleted()) { return false; } else { diff --git a/src/main/java/io/vavr/concurrent/Promise.java b/src/main/java/io/vavr/concurrent/Promise.java index 594d5eb5f..1c0e59ef6 100644 --- a/src/main/java/io/vavr/concurrent/Promise.java +++ b/src/main/java/io/vavr/concurrent/Promise.java @@ -93,7 +93,6 @@ public interface Promise { * @throws NullPointerException if exception is null */ static Promise failed(Throwable exception) { - Objects.requireNonNull(exception, "exception is null"); return failed(DEFAULT_EXECUTOR, exception); } @@ -107,8 +106,6 @@ static Promise failed(Throwable exception) { * @throws NullPointerException if executor or exception is null */ static Promise failed(Executor executor, Throwable exception) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(exception, "exception is null"); return Promise. make(executor).failure(exception); } @@ -134,8 +131,6 @@ static Promise fromTry(Try result) { * @throws NullPointerException if executor or result is null */ static Promise fromTry(Executor executor, Try result) { - Objects.requireNonNull(executor, "executor is null"); - Objects.requireNonNull(result, "result is null"); return Promise. make(executor).complete(result); } @@ -159,7 +154,6 @@ static Promise make() { * @throws NullPointerException if executor is null */ static Promise make(Executor executor) { - Objects.requireNonNull(executor, "executor is null"); return new PromiseImpl<>(FutureImpl.of(executor)); } @@ -198,7 +192,6 @@ static Promise successful(T result) { * @throws NullPointerException if executor is null */ static Promise successful(Executor executor, T result) { - Objects.requireNonNull(executor, "executor is null"); return Promise. make(executor).success(result); } diff --git a/src/main/java/io/vavr/control/Either.java b/src/main/java/io/vavr/control/Either.java index 61f00a2b1..938fa4b85 100644 --- a/src/main/java/io/vavr/control/Either.java +++ b/src/main/java/io/vavr/control/Either.java @@ -218,8 +218,6 @@ public final RightProjection right() { * @return A new Either instance */ public final Either bimap(Function leftMapper, Function rightMapper) { - Objects.requireNonNull(leftMapper, "leftMapper is null"); - Objects.requireNonNull(rightMapper, "rightMapper is null"); if (isRight()) { return new Right<>(rightMapper.apply(get())); } else { @@ -248,8 +246,6 @@ public final Either bimap(Function leftMapp * @return A value of type U */ public final U fold(Function leftMapper, Function rightMapper) { - Objects.requireNonNull(leftMapper, "leftMapper is null"); - Objects.requireNonNull(rightMapper, "rightMapper is null"); if (isRight()) { return rightMapper.apply(get()); } else { @@ -286,7 +282,6 @@ public final U fold(Function leftMapper, Function Either, Seq> sequence(Iterable> eithers) { - Objects.requireNonNull(eithers, "eithers is null"); return Iterator.ofAll((Iterable>) eithers) .partition(Either::isLeft) .apply((leftPartition, rightPartition) -> leftPartition.hasNext() @@ -320,8 +315,6 @@ public static Either, Seq> sequence(Iterable Either, Seq> traverse(Iterable values, Function> mapper) { - Objects.requireNonNull(values, "values is null"); - Objects.requireNonNull(mapper, "mapper is null"); return sequence(Iterator.ofAll(values).map(mapper)); } @@ -353,7 +346,6 @@ public static Either, Seq> traverse(Iterable va * @throws NullPointerException if {@code eithers} is null */ public static Either> sequenceRight(Iterable> eithers) { - Objects.requireNonNull(eithers, "eithers is null"); Vector rightValues = Vector.empty(); for (Either either : eithers) { if (either.isRight()) { @@ -387,8 +379,6 @@ public static Either> sequenceRight(Iterable Either> traverseRight(Iterable values, Function> mapper) { - Objects.requireNonNull(values, "values is null"); - Objects.requireNonNull(mapper, "mapper is null"); return sequenceRight(Iterator.ofAll(values).map(mapper)); } @@ -406,7 +396,6 @@ public static Either> traverseRight(Iterable va * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -426,7 +415,6 @@ public final U transform(Function, ? extends U> f) { * {@code other} by applying the Left value. */ public final R getOrElseGet(Function other) { - Objects.requireNonNull(other, "other is null"); if (isRight()) { return get(); } else { @@ -445,7 +433,6 @@ public final R getOrElseGet(Function other) { * @param action an action which consumes a Left value */ public final void orElseRun(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isLeft()) { action.accept(getLeft()); } @@ -470,7 +457,6 @@ public final void orElseRun(Consumer action) { * @throws X if the projected Either is a Left */ public final R getOrElseThrow(Function exceptionFunction) throws X { - Objects.requireNonNull(exceptionFunction, "exceptionFunction is null"); if (isRight()) { return get(); } else { @@ -518,7 +504,6 @@ public final Either swap() { */ @SuppressWarnings("unchecked") public final Either recoverWith(Function> recoveryFunction) { - Objects.requireNonNull(recoveryFunction, "recoveryFunction is null"); if (isLeft()) { return (Either) recoveryFunction.apply(getLeft()); } else { @@ -544,7 +529,6 @@ public final Either recoverWith(Function recover(Function recoveryFunction) { - Objects.requireNonNull(recoveryFunction, "recoveryFunction is null"); if (isLeft()) { return Either.right(recoveryFunction.apply(getLeft())); } else { @@ -572,7 +556,6 @@ public final Either recover(Function recoveryFunct */ @SuppressWarnings("unchecked") public final Either flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isRight()) { return (Either) mapper.apply(get()); } else { @@ -599,7 +582,6 @@ public final Either flatMap(Function Either map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isRight()) { return Either.right(mapper.apply(get())); } else { @@ -625,7 +607,6 @@ public final Either map(Function mapper) { */ @SuppressWarnings("unchecked") public final Either mapLeft(Function leftMapper) { - Objects.requireNonNull(leftMapper, "leftMapper is null"); if (isLeft()) { return Either.left(leftMapper.apply(getLeft())); } else { @@ -644,7 +625,6 @@ public final Either mapLeft(Function leftMappe * @throws NullPointerException if {@code predicate} is null */ public final Option> filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return isLeft() || predicate.test(get()) ? Option.some(this) : Option.none(); } @@ -657,7 +637,6 @@ public final Option> filter(Predicate predicate) { * */ public final Option> filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @@ -681,8 +660,6 @@ public final Option> filterNot(Predicate predicate) { * @throws NullPointerException if {@code predicate} is null */ public final Either filterOrElse(Predicate predicate, Function zero) { - Objects.requireNonNull(predicate, "predicate is null"); - Objects.requireNonNull(zero, "zero is null"); if (isLeft() || predicate.test(get())) { return this; } else { @@ -706,13 +683,11 @@ public final boolean isEmpty() { @SuppressWarnings("unchecked") public final Either orElse(Either other) { - Objects.requireNonNull(other, "other is null"); return isRight() ? this : (Either) other; } @SuppressWarnings("unchecked") public final Either orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isRight() ? this : (Either) supplier.get(); } @@ -764,8 +739,6 @@ public final Iterator iterator() { * @return this instance */ public final Either peek(Consumer leftAction, Consumer rightAction) { - Objects.requireNonNull(leftAction, "leftAction is null"); - Objects.requireNonNull(rightAction, "rightAction is null"); if (isLeft()) { leftAction.accept(getLeft()); @@ -778,7 +751,6 @@ public final Either peek(Consumer leftAction, Consumer peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isRight()) { action.accept(get()); } @@ -786,7 +758,6 @@ public final Either peek(Consumer action) { } public final Either peekLeft(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isLeft()) { action.accept(getLeft()); } @@ -892,13 +863,11 @@ public L get() { @SuppressWarnings("unchecked") public LeftProjection orElse(LeftProjection other) { - Objects.requireNonNull(other, "other is null"); return either.isLeft() ? this : (LeftProjection) other; } @SuppressWarnings("unchecked") public LeftProjection orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return either.isLeft() ? this : (LeftProjection) supplier.get(); } @@ -922,7 +891,6 @@ public L getOrElse(L other) { * {@code other} by applying the Right value. */ public L getOrElseGet(Function other) { - Objects.requireNonNull(other, "other is null"); if (either.isLeft()) { return either.getLeft(); } else { @@ -936,7 +904,6 @@ public L getOrElseGet(Function other) { * @param action an action which consumes a Right value */ public void orElseRun(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (either.isRight()) { action.accept(either.get()); } @@ -952,7 +919,6 @@ public void orElseRun(Consumer action) { * @throws X if the projected Either is a Right */ public L getOrElseThrow(Function exceptionFunction) throws X { - Objects.requireNonNull(exceptionFunction, "exceptionFunction is null"); if (either.isLeft()) { return either.getLeft(); } else { @@ -977,7 +943,6 @@ public Either toEither() { * @return A new Option */ public Option> filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return either.isRight() || predicate.test(either.getLeft()) ? Option.some(this) : Option.none(); } @@ -991,7 +956,6 @@ public Option> filter(Predicate predicate) { */ @SuppressWarnings("unchecked") public LeftProjection flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (either.isLeft()) { return (LeftProjection) mapper.apply(either.getLeft()); } else { @@ -1009,7 +973,6 @@ public LeftProjection flatMap(Function LeftProjection map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (either.isLeft()) { return either.mapLeft((Function) mapper).left(); } else { @@ -1025,7 +988,6 @@ public LeftProjection map(Function mapper) { */ @Override public LeftProjection peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (either.isLeft()) { action.accept(either.getLeft()); } @@ -1041,7 +1003,6 @@ public LeftProjection peek(Consumer action) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1147,13 +1108,11 @@ public R get() { @SuppressWarnings("unchecked") public RightProjection orElse(RightProjection other) { - Objects.requireNonNull(other, "other is null"); return either.isRight() ? this : (RightProjection) other; } @SuppressWarnings("unchecked") public RightProjection orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return either.isRight() ? this : (RightProjection) supplier.get(); } @@ -1184,7 +1143,6 @@ public R getOrElse(R other) { * {@code other} by applying the Left value. */ public R getOrElseGet(Function other) { - Objects.requireNonNull(other, "other is null"); return either.getOrElseGet(other); } @@ -1202,7 +1160,6 @@ public R getOrElseGet(Function other) { * @param action an action which consumes a Left value */ public void orElseRun(Consumer action) { - Objects.requireNonNull(action, "action is null"); either.orElseRun(action); } @@ -1224,7 +1181,6 @@ public void orElseRun(Consumer action) { * @throws X if the projected Either is a Left */ public R getOrElseThrow(Function exceptionFunction) throws X { - Objects.requireNonNull(exceptionFunction, "exceptionFunction is null"); return either.getOrElseThrow(exceptionFunction); } @@ -1245,7 +1201,6 @@ public Either toEither() { * @return A new Option */ public Option> filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return either.isLeft() || predicate.test(either.get()) ? Option.some(this) : Option.none(); } @@ -1259,7 +1214,6 @@ public Option> filter(Predicate predicate) { */ @SuppressWarnings("unchecked") public RightProjection flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (either.isRight()) { return (RightProjection) mapper.apply(either.get()); } else { @@ -1277,7 +1231,6 @@ public RightProjection flatMap(Function RightProjection map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (either.isRight()) { return either.map((Function) mapper).right(); } else { @@ -1293,7 +1246,6 @@ public RightProjection map(Function mapper) { */ @Override public RightProjection peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (either.isRight()) { action.accept(either.get()); } @@ -1309,7 +1261,6 @@ public RightProjection peek(Consumer action) { * @throws NullPointerException if {@code f} is null */ public U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } diff --git a/src/main/java/io/vavr/control/Option.java b/src/main/java/io/vavr/control/Option.java index b549c12da..29fc22a97 100644 --- a/src/main/java/io/vavr/control/Option.java +++ b/src/main/java/io/vavr/control/Option.java @@ -102,7 +102,6 @@ public static Option of(T value) { * @throws NullPointerException if {@code values} is null */ public static Option> sequence(Iterable> values) { - Objects.requireNonNull(values, "values is null"); Vector vector = Vector.empty(); for (Option value : values) { if (value.isEmpty()) { @@ -140,8 +139,6 @@ public static Option> sequence(Iterable * @throws NullPointerException if values or f is null. */ public static Option> traverse(Iterable values, Function> mapper) { - Objects.requireNonNull(values, "values is null"); - Objects.requireNonNull(mapper, "mapper is null"); return sequence(Iterator.ofAll(values).map(mapper)); } @@ -223,7 +220,6 @@ public static Option narrow(Option option) { * @throws NullPointerException if the given {@code supplier} is null */ public static Option when(boolean condition, Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return condition ? some(supplier.get()) : none(); } @@ -268,7 +264,6 @@ public static Option when(boolean condition, T value) { */ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public static Option ofOptional(Optional optional) { - Objects.requireNonNull(optional, "optional is null"); return optional.>map(Option::of).orElseGet(Option::none); } @@ -292,7 +287,6 @@ public static Option ofOptional(Optional optional) { * @throws NullPointerException if {@code partialFunction} is null */ public final Option collect(PartialFunction partialFunction) { - Objects.requireNonNull(partialFunction, "partialFunction is null"); return flatMap(partialFunction.lift()); } @@ -329,7 +323,6 @@ public final Option collect(PartialFunction parti * @return this {@code Option} */ public final Option onEmpty(Runnable action) { - Objects.requireNonNull(action, "action is null"); if (isEmpty()) { action.run(); } @@ -468,7 +461,6 @@ public final T getOrElse(T other) { */ @SuppressWarnings("unchecked") public final Option orElse(Option other) { - Objects.requireNonNull(other, "other is null"); return isEmpty() ? (Option) other : this; } @@ -490,7 +482,6 @@ public final Option orElse(Option other) { */ @SuppressWarnings("unchecked") public final Option orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isEmpty() ? (Option) supplier.get() : this; } @@ -531,7 +522,6 @@ public final T orNull() { */ @Override public final T getOrElse(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isEmpty() ? supplier.get() : get(); } @@ -555,7 +545,6 @@ public final T getOrElse(Supplier supplier) { */ @Override public final T getOrElseThrow(Supplier exceptionSupplier) throws X { - Objects.requireNonNull(exceptionSupplier, "exceptionSupplier is null"); if (isEmpty()) { throw exceptionSupplier.get(); } else { @@ -584,7 +573,6 @@ public final T getOrElseThrow(Supplier exceptionSupplie * @return {@code Some(value)} or {@code None} as specified */ public final Option filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return isEmpty() || predicate.test(get()) ? this : none(); } @@ -609,7 +597,6 @@ public final Option filter(Predicate predicate) { * @return {@code Some(value)} or {@code None} as specified */ public final Option filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @@ -635,7 +622,6 @@ public final Option filterNot(Predicate predicate) { */ @SuppressWarnings("unchecked") public final Option flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? none() : (Option) mapper.apply(get()); } @@ -658,7 +644,6 @@ public final Option flatMap(Function Option map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return isEmpty() ? none() : some(mapper.apply(get())); } @@ -694,8 +679,6 @@ public final U fold(Supplier ifNone, Function peek(Runnable noneAction, Consumer someAction) { - Objects.requireNonNull(noneAction, "noneAction is null"); - Objects.requireNonNull(someAction, "someAction is null"); if (isEmpty()) { noneAction.run(); @@ -724,7 +707,6 @@ public final Option peek(Runnable noneAction, Consumer someAction) */ @Override public final Option peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isDefined()) { action.accept(get()); } @@ -750,7 +732,6 @@ public final Option peek(Consumer action) { * @throws NullPointerException if {@code f} is null */ public final U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } diff --git a/src/main/java/io/vavr/control/Try.java b/src/main/java/io/vavr/control/Try.java index 25eee1293..c24db7de7 100644 --- a/src/main/java/io/vavr/control/Try.java +++ b/src/main/java/io/vavr/control/Try.java @@ -86,7 +86,6 @@ private Try() { * exception occurs calling {@code supplier.apply()}. */ public static Try of(CheckedFunction0 supplier) { - Objects.requireNonNull(supplier, "supplier is null"); try { return new Success<>(supplier.apply()); } catch (Throwable t) { @@ -112,7 +111,6 @@ public static Try of(CheckedFunction0 supplier) { * exception occurs calling {@code supplier.get()}. */ public static Try ofSupplier(Supplier supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return of(supplier::get); } @@ -135,7 +133,6 @@ public static Try ofSupplier(Supplier supplier) { * exception occurs calling {@code callable.call()}. */ public static Try ofCallable(Callable callable) { - Objects.requireNonNull(callable, "callable is null"); return of(callable::call); } @@ -157,7 +154,6 @@ public static Try ofCallable(Callable callable) { * calling {@code runnable.run()}. */ public static Try run(CheckedRunnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); try { runnable.run(); return new Success<>(null); // null represents the absence of an value, i.e. Void @@ -184,7 +180,6 @@ public static Try run(CheckedRunnable runnable) { * calling {@code runnable.run()}. */ public static Try runRunnable(Runnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); return run(runnable::run); } @@ -211,7 +206,6 @@ public static Try runRunnable(Runnable runnable) { * @throws NullPointerException if {@code values} is null */ public static Try> sequence(Iterable> values) { - Objects.requireNonNull(values, "values is null"); Vector vector = Vector.empty(); for (Try value : values) { if (value.isFailure()) { @@ -244,8 +238,6 @@ public static Try> sequence(Iterable> valu * @throws NullPointerException if values or f is null. */ public static Try> traverse(Iterable values, Function> mapper) { - Objects.requireNonNull(values, "values is null"); - Objects.requireNonNull(mapper, "mapper is null"); return sequence(Iterator.ofAll(values).map(mapper)); } @@ -310,7 +302,6 @@ public static Try narrow(Try t) { * @throws NullPointerException if {@code consumer} is null */ public final Try andThen(Consumer consumer) { - Objects.requireNonNull(consumer, "consumer is null"); return andThenTry(consumer::accept); } @@ -333,7 +324,6 @@ public final Try andThen(Consumer consumer) { * @throws NullPointerException if {@code consumer} is null */ public final Try andThenTry(CheckedConsumer consumer) { - Objects.requireNonNull(consumer, "consumer is null"); if (isFailure()) { return this; } else { @@ -355,7 +345,6 @@ public final Try andThenTry(CheckedConsumer consumer) { * @throws NullPointerException if {@code runnable} is null */ public final Try andThen(Runnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); return andThenTry(runnable::run); } @@ -392,7 +381,6 @@ public final Try andThen(Runnable runnable) { * @throws NullPointerException if {@code runnable} is null */ public final Try andThenTry(CheckedRunnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); if (isFailure()) { return this; } else { @@ -425,7 +413,6 @@ public final Try andThenTry(CheckedRunnable runnable) { */ @SuppressWarnings("unchecked") public final Try collect(PartialFunction partialFunction){ - Objects.requireNonNull(partialFunction, "partialFunction is null"); return filter(partialFunction::isDefinedAt).map(partialFunction); } @@ -453,8 +440,6 @@ public final Try failed() { * @throws NullPointerException if {@code predicate} or {@code throwableSupplier} is null */ public final Try filter(Predicate predicate, Supplier throwableSupplier) { - Objects.requireNonNull(predicate, "predicate is null"); - Objects.requireNonNull(throwableSupplier, "throwableSupplier is null"); return filterTry(predicate::test, throwableSupplier); } @@ -468,8 +453,6 @@ public final Try filter(Predicate predicate, Supplier filter(Predicate predicate, Function errorProvider) { - Objects.requireNonNull(predicate, "predicate is null"); - Objects.requireNonNull(errorProvider, "errorProvider is null"); return filterTry(predicate::test, errorProvider::apply); } @@ -481,7 +464,6 @@ public final Try filter(Predicate predicate, Function filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterTry(predicate::test); } @@ -494,7 +476,6 @@ public final Try filter(Predicate predicate) { * @throws NullPointerException if {@code predicate} or {@code throwableSupplier} is null */ public final Try filterNot(Predicate predicate, Supplier throwableSupplier) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate(), throwableSupplier); } @@ -508,7 +489,6 @@ public final Try filterNot(Predicate predicate, Supplier filterNot(Predicate predicate, Function errorProvider) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate(), errorProvider); } @@ -521,7 +501,6 @@ public final Try filterNot(Predicate predicate, Function filterNot(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filter(predicate.negate()); } @@ -538,8 +517,6 @@ public final Try filterNot(Predicate predicate) { * @throws NullPointerException if {@code predicate} or {@code throwableSupplier} is null */ public final Try filterTry(CheckedPredicate predicate, Supplier throwableSupplier) { - Objects.requireNonNull(predicate, "predicate is null"); - Objects.requireNonNull(throwableSupplier, "throwableSupplier is null"); if (isFailure()) { return this; @@ -569,8 +546,6 @@ public final Try filterTry(CheckedPredicate predicate, Supplier filterTry(CheckedPredicate predicate, CheckedFunction1 errorProvider) { - Objects.requireNonNull(predicate, "predicate is null"); - Objects.requireNonNull(errorProvider, "errorProvider is null"); return flatMapTry(t -> predicate.test(t) ? this : failure(errorProvider.apply(t))); } @@ -585,7 +560,6 @@ public final Try filterTry(CheckedPredicate predicate, CheckedFunc * @throws NullPointerException if {@code predicate} is null */ public final Try filterTry(CheckedPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); return filterTry(predicate, () -> new NoSuchElementException("Predicate does not hold for " + get())); } @@ -598,7 +572,6 @@ public final Try filterTry(CheckedPredicate predicate) { * @throws NullPointerException if {@code mapper} is null */ public final Try flatMap(Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return flatMapTry((CheckedFunction1>) mapper::apply); } @@ -612,7 +585,6 @@ public final Try flatMap(Function> */ @SuppressWarnings("unchecked") public final Try flatMapTry(CheckedFunction1> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isFailure()) { return (Failure) this; } else { @@ -711,7 +683,6 @@ public final Iterator iterator() { */ @Override public final Try map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); return mapTry(mapper::apply); } @@ -755,7 +726,6 @@ public final Try mapFailure(Match.Case Try mapTry(CheckedFunction1 mapper) { - Objects.requireNonNull(mapper, "mapper is null"); if (isFailure()) { return (Failure) this; } else { @@ -783,7 +753,6 @@ public final Try mapTry(CheckedFunction1 mapper) * @throws NullPointerException if {@code action} is null */ public final Try onFailure(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isFailure()) { action.accept(getCause()); } @@ -811,8 +780,6 @@ public final Try onFailure(Consumer action) { */ @SuppressWarnings("unchecked") public final Try onFailure(Class exceptionType, Consumer action) { - Objects.requireNonNull(exceptionType, "exceptionType is null"); - Objects.requireNonNull(action, "action is null"); if (isFailure() && exceptionType.isAssignableFrom(getCause().getClass())) { action.accept((X) getCause()); } @@ -835,7 +802,6 @@ public final Try onFailure(Class exceptionType, Cons * @throws NullPointerException if {@code action} is null */ public final Try onSuccess(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isSuccess()) { action.accept(get()); } @@ -844,18 +810,15 @@ public final Try onSuccess(Consumer action) { @SuppressWarnings("unchecked") public final Try orElse(Try other) { - Objects.requireNonNull(other, "other is null"); return isSuccess() ? this : (Try) other; } @SuppressWarnings("unchecked") public final Try orElse(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); return isSuccess() ? this : (Try) supplier.get(); } public final T getOrElseGet(Function other) { - Objects.requireNonNull(other, "other is null"); if (isFailure()) { return other.apply(getCause()); } else { @@ -864,14 +827,12 @@ public final T getOrElseGet(Function other) { } public final void orElseRun(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isFailure()) { action.accept(getCause()); } } public final T getOrElseThrow(Function exceptionProvider) throws X { - Objects.requireNonNull(exceptionProvider, "exceptionProvider is null"); if (isFailure()) { throw exceptionProvider.apply(getCause()); } else { @@ -903,8 +864,6 @@ public final X fold(Function ifFail, Functio * @return this {@code Try} */ public final Try peek(Consumer failureAction, Consumer successAction) { - Objects.requireNonNull(failureAction, "failureAction is null"); - Objects.requireNonNull(successAction, "successAction is null"); if (isFailure()) { failureAction.accept(getCause()); @@ -924,7 +883,6 @@ public final Try peek(Consumer failureAction, Consumer peek(Consumer action) { - Objects.requireNonNull(action, "action is null"); if (isSuccess()) { action.accept(get()); } @@ -957,8 +915,6 @@ public final Try peek(Consumer action) { */ @SuppressWarnings("unchecked") public final Try recover(Class exceptionType, Function f) { - Objects.requireNonNull(exceptionType, "exceptionType is null"); - Objects.requireNonNull(f, "f is null"); if (isFailure()) { final Throwable cause = getCause(); if (exceptionType.isAssignableFrom(cause.getClass())) { @@ -995,8 +951,6 @@ public final Try recover(Class exceptionType, Functi */ @SuppressWarnings("unchecked") public final Try recoverWith(Class exceptionType, Function> f){ - Objects.requireNonNull(exceptionType, "exceptionType is null"); - Objects.requireNonNull(f, "f is null"); if(isFailure()){ final Throwable cause = getCause(); if (exceptionType.isAssignableFrom(cause.getClass())) { @@ -1034,8 +988,6 @@ public final Try recoverWith(Class exceptionType, Fu * @throws NullPointerException if {@code exceptionType} or {@code recovered} is null */ public final Try recoverWith(Class exceptionType, Try recovered){ - Objects.requireNonNull(exceptionType, "exeptionType is null"); - Objects.requireNonNull(recovered, "recovered is null"); return (isFailure() && exceptionType.isAssignableFrom(getCause().getClass())) ? narrow(recovered) : this; @@ -1065,7 +1017,6 @@ public final Try recoverWith(Class exceptionType, T * @throws NullPointerException if {@code exception} is null */ public final Try recover(Class exceptionType, T value) { - Objects.requireNonNull(exceptionType, "exceptionType is null"); return (isFailure() && exceptionType.isAssignableFrom(getCause().getClass())) ? Try.success(value) : this; @@ -1088,7 +1039,6 @@ public final Try recover(Class exceptionType, T valu * @throws NullPointerException if {@code f} is null */ public final Try recover(Function f) { - Objects.requireNonNull(f, "f is null"); if (isFailure()) { return Try.of(() -> f.apply(getCause())); } else { @@ -1115,7 +1065,6 @@ public final Try recover(Function f) { */ @SuppressWarnings("unchecked") public final Try recoverWith(Function> f) { - Objects.requireNonNull(f, "f is null"); if (isFailure()) { try { return (Try) f.apply(getCause()); @@ -1163,7 +1112,6 @@ public final Validation toValidation() { * @throws NullPointerException if the given {@code throwableMapper} is null. */ public final Validation toValidation(Function throwableMapper) { - Objects.requireNonNull(throwableMapper, "throwableMapper is null"); if (isFailure()) { return Validation.invalid(throwableMapper.apply(getCause())); } else { @@ -1180,7 +1128,6 @@ public final Validation toValidation(Function U transform(Function, ? extends U> f) { - Objects.requireNonNull(f, "f is null"); return f.apply(this); } @@ -1192,7 +1139,6 @@ public final U transform(Function, ? extends U> f) { * @throws NullPointerException if {@code runnable} is null */ public final Try andFinally(Runnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); return andFinallyTry(runnable::run); } @@ -1204,7 +1150,6 @@ public final Try andFinally(Runnable runnable) { * @throws NullPointerException if {@code runnable} is null */ public final Try andFinallyTry(CheckedRunnable runnable) { - Objects.requireNonNull(runnable, "runnable is null"); try { runnable.run(); return this; @@ -1302,7 +1247,6 @@ public static final class Failure extends Try implements Serializable { * @throws Throwable if the given {@code cause} is fatal, i.e. non-recoverable */ private Failure(Throwable cause) { - Objects.requireNonNull(cause, "cause is null"); if (isFatal(cause)) { sneakyThrow(cause); } diff --git a/src/main/java/io/vavr/control/Validation.java b/src/main/java/io/vavr/control/Validation.java index f8813acea..9be3053fa 100644 --- a/src/main/java/io/vavr/control/Validation.java +++ b/src/main/java/io/vavr/control/Validation.java @@ -113,7 +113,6 @@ public static Validation valid(T value) { * @throws NullPointerException if error is null */ public static Validation invalid(E error) { - Objects.requireNonNull(error, "error is null"); return new Invalid<>(error); } @@ -136,7 +135,6 @@ public static Validation invalid(E error) { * @throws NullPointerException if either is null */ public static Validation fromEither(Either either) { - Objects.requireNonNull(either, "either is null"); return either.isRight() ? valid(either.get()) : invalid(either.getLeft()); } @@ -158,7 +156,6 @@ public static Validation fromEither(Either either) { * @throws NullPointerException if {@code t} is null */ public static Validation fromTry(Try t) { - Objects.requireNonNull(t, "t is null"); return t.isSuccess() ? valid(t.get()) : invalid(t.getCause()); } @@ -184,7 +181,6 @@ public static Validation fromTry(Try t) { * @throws NullPointerException if values is null */ public static Validation, Seq> sequence(Iterable, ? extends T>> values) { - Objects.requireNonNull(values, "values is null"); List errors = List.empty(); List list = List.empty(); for (Validation, ? extends T> value : values) { @@ -199,7 +195,6 @@ public static Validation, Seq> sequence(Iterable * Usage example : * *
{@code
@@ -252,7 +247,6 @@ public static  Validation, T> all(Traversable U transform(Function, ? extends U> f) {
-        Objects.requireNonNull(f, "f is null");
         return f.apply(this);
     }
 
@@ -276,8 +270,6 @@ public final  U transform(Function, ? extends U> f)
      * @throws NullPointerException if values or f is null.
      */
     public static  Validation, Seq> traverse(Iterable values, Function, ? extends U>> mapper) {
-        Objects.requireNonNull(values, "values is null");
-        Objects.requireNonNull(mapper, "mapper is null");
         return sequence(Iterator.ofAll(values).map(mapper));
     }
 
@@ -323,8 +315,6 @@ public static  Validation narrow(Validation Builder combine(Validation validation1, Validation validation2) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
         return new Builder<>(validation1, validation2);
     }
 
@@ -351,9 +341,6 @@ public static  Builder combine(Validation validatio
      * @throws NullPointerException if validation1, validation2 or validation3 is null
      */
     public static  Builder3 combine(Validation validation1, Validation validation2, Validation validation3) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
         return new Builder3<>(validation1, validation2, validation3);
     }
 
@@ -383,10 +370,6 @@ public static  Builder3 combine(Validation
      * @throws NullPointerException if validation1, validation2, validation3 or validation4 is null
      */
     public static  Builder4 combine(Validation validation1, Validation validation2, Validation validation3, Validation validation4) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
-        Objects.requireNonNull(validation4, "validation4 is null");
         return new Builder4<>(validation1, validation2, validation3, validation4);
     }
 
@@ -420,11 +403,6 @@ public static  Builder4 combine(Validation
      * @throws NullPointerException if validation1, validation2, validation3, validation4 or validation5 is null
      */
     public static  Builder5 combine(Validation validation1, Validation validation2, Validation validation3, Validation validation4, Validation validation5) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
-        Objects.requireNonNull(validation4, "validation4 is null");
-        Objects.requireNonNull(validation5, "validation5 is null");
         return new Builder5<>(validation1, validation2, validation3, validation4, validation5);
     }
 
@@ -460,12 +438,6 @@ public static  Builder5 combine(Va
      * @throws NullPointerException if validation1, validation2, validation3, validation4, validation5 or validation6 is null
      */
     public static  Builder6 combine(Validation validation1, Validation validation2, Validation validation3, Validation validation4, Validation validation5, Validation validation6) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
-        Objects.requireNonNull(validation4, "validation4 is null");
-        Objects.requireNonNull(validation5, "validation5 is null");
-        Objects.requireNonNull(validation6, "validation6 is null");
         return new Builder6<>(validation1, validation2, validation3, validation4, validation5, validation6);
     }
 
@@ -504,13 +476,6 @@ public static  Builder6 co
      * @throws NullPointerException if validation1, validation2, validation3, validation4, validation5, validation6 or validation7 is null
      */
     public static  Builder7 combine(Validation validation1, Validation validation2, Validation validation3, Validation validation4, Validation validation5, Validation validation6, Validation validation7) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
-        Objects.requireNonNull(validation4, "validation4 is null");
-        Objects.requireNonNull(validation5, "validation5 is null");
-        Objects.requireNonNull(validation6, "validation6 is null");
-        Objects.requireNonNull(validation7, "validation7 is null");
         return new Builder7<>(validation1, validation2, validation3, validation4, validation5, validation6, validation7);
     }
 
@@ -552,14 +517,6 @@ public static  Builder7 Builder8 combine(Validation validation1, Validation validation2, Validation validation3, Validation validation4, Validation validation5, Validation validation6, Validation validation7, Validation validation8) {
-        Objects.requireNonNull(validation1, "validation1 is null");
-        Objects.requireNonNull(validation2, "validation2 is null");
-        Objects.requireNonNull(validation3, "validation3 is null");
-        Objects.requireNonNull(validation4, "validation4 is null");
-        Objects.requireNonNull(validation5, "validation5 is null");
-        Objects.requireNonNull(validation6, "validation6 is null");
-        Objects.requireNonNull(validation7, "validation7 is null");
-        Objects.requireNonNull(validation8, "validation8 is null");
         return new Builder8<>(validation1, validation2, validation3, validation4, validation5, validation6, validation7, validation8);
     }
 
@@ -592,7 +549,6 @@ public static  Builder8 orElse(Validation other) {
-        Objects.requireNonNull(other, "other is null");
         return isValid() ? this : (Validation) other;
     }
 
@@ -610,7 +566,6 @@ public final Validation orElse(Validation other)
      */
     @SuppressWarnings("unchecked")
     public final Validation orElse(Supplier> supplier) {
-        Objects.requireNonNull(supplier, "supplier is null");
         return isValid() ? this : (Validation) supplier.get();
     }
 
@@ -644,7 +599,6 @@ public final boolean isEmpty() {
      * provided by {@code other} by applying the error.
      */
     public final T getOrElseGet(Function other) {
-        Objects.requireNonNull(other, "other is null");
         if (isValid()) {
             return get();
         } else {
@@ -685,7 +639,6 @@ public final Either toEither() {
      */
     @Override
     public final void forEach(Consumer action) {
-        Objects.requireNonNull(action, "action is null");
         if (isValid()) {
             action.accept(get());
         }
@@ -708,8 +661,6 @@ public final void forEach(Consumer action) {
      * @throws NullPointerException if one of the given mappers {@code ifInvalid} or {@code ifValid} is null
      */
     public final  U fold(Function ifInvalid, Function ifValid) {
-        Objects.requireNonNull(ifInvalid, "ifInvalid is null");
-        Objects.requireNonNull(ifValid, "ifValid is null");
         return isValid() ? ifValid.apply(get()) : ifInvalid.apply(getError());
     }
 
@@ -732,7 +683,6 @@ public final  U fold(Function ifInvalid, Function T getOrElseThrow(Function exceptionFunction) throws X {
-      Objects.requireNonNull(exceptionFunction, "exceptionFunction is null");
       if (isValid()) {
         return get();
       } else {
@@ -758,7 +708,6 @@ public final Validation swap() {
 
     @Override
     public final  Validation map(Function f) {
-        Objects.requireNonNull(f, "f is null");
         if (isInvalid()) {
             return Validation.invalid(this.getError());
         } else {
@@ -782,8 +731,6 @@ public final  Validation map(Function f) {
      * @throws NullPointerException if invalidMapper or validMapper is null
      */
     public final  Validation bimap(Function errorMapper, Function valueMapper) {
-        Objects.requireNonNull(errorMapper, "errorMapper is null");
-        Objects.requireNonNull(valueMapper, "valueMapper is null");
         if (isInvalid()) {
             final E error = this.getError();
             return Validation.invalid(errorMapper.apply(error));
@@ -803,7 +750,6 @@ public final  Validation bimap(Function
      * @throws NullPointerException if mapping operation f is null
      */
     public final  Validation mapError(Function f) {
-        Objects.requireNonNull(f, "f is null");
         if (isInvalid()) {
             final E error = this.getError();
             return Validation.invalid(f.apply(error));
@@ -813,7 +759,6 @@ public final  Validation mapError(Function f) {
     }
 
     public final  Validation, U> ap(Validation, ? extends Function> validation) {
-        Objects.requireNonNull(validation, "validation is null");
         if (isValid()) {
             if (validation.isValid()) {
                 final Function f = validation.get();
@@ -850,13 +795,11 @@ public final  Builder combine(Validation validation) {
     // -- Implementation of Value
 
     public final Option> filter(Predicate predicate) {
-        Objects.requireNonNull(predicate, "predicate is null");
         return isInvalid() || predicate.test(get()) ? Option.some(this) : Option.none();
     }
 
     @SuppressWarnings("unchecked")
     public final  Validation flatMap(Function> mapper) {
-        Objects.requireNonNull(mapper, "mapper is null");
         return isInvalid() ? (Validation) this : (Validation) mapper.apply(get());
     }
 
@@ -868,8 +811,6 @@ public final  Validation flatMap(Function peek(Consumer invalidAction, Consumer validAction) {
-        Objects.requireNonNull(invalidAction, "invalidAction is null");
-        Objects.requireNonNull(validAction, "validAction is null");
 
         if(isInvalid()) {
             invalidAction.accept(getError());
@@ -882,7 +823,6 @@ public final Validation peek(Consumer invalidAction, Consumer peek(Consumer action) {
-        Objects.requireNonNull(action, "action is null");
 
         if (isValid()) {
             action.accept(get());
@@ -891,7 +831,6 @@ public final Validation peek(Consumer action) {
     }
 
     public final Validation peekError(Consumer action) {
-        Objects.requireNonNull(action, "action is null");
 
         if (isInvalid()) {
             action.accept(getError());
diff --git a/src/test/java/io/vavr/CheckedConsumerTest.java b/src/test/java/io/vavr/CheckedConsumerTest.java
index 23c9ca408..6c7a32bd6 100644
--- a/src/test/java/io/vavr/CheckedConsumerTest.java
+++ b/src/test/java/io/vavr/CheckedConsumerTest.java
@@ -81,9 +81,10 @@ public void shouldApplyThrowingCheckedConsumer() {
     // -- andThen
 
     @Test
-    public void shouldThrowWhenComposingCheckedConsumerUsingAndThenWithNullParameter() {
+    public void shouldThrowWhenComposingCheckedConsumerUsingAndThenWithNullParameterButOnlyUponInvokingTheResultingConsumer() {
         final CheckedConsumer f = t -> {};
-        assertThatThrownBy(() -> f.andThen(null)).isInstanceOf(NullPointerException.class);
+        final CheckedConsumer fAndThenNull = f.andThen(null);
+        assertThatThrownBy(() -> fAndThenNull.accept(null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
diff --git a/src/test/java/io/vavr/JavaCollections.java b/src/test/java/io/vavr/JavaCollections.java
index 95245658a..069342ceb 100644
--- a/src/test/java/io/vavr/JavaCollections.java
+++ b/src/test/java/io/vavr/JavaCollections.java
@@ -35,7 +35,6 @@ private JavaCollections() {
 
     @SuppressWarnings("unchecked")
     static  Map javaMap(Object... pairs) {
-        Objects.requireNonNull(pairs, "pairs is null");
         if ((pairs.length & 1) != 0) {
             throw new IllegalArgumentException("Odd length of key-value pairs list");
         }
@@ -48,7 +47,6 @@ static  Map javaMap(Object... pairs) {
 
     @SuppressWarnings("unchecked")
     static  Set javaSet(T... elements) {
-        Objects.requireNonNull(elements, "elements is null");
         final Set set = new HashSet<>();
         Collections.addAll(set, elements);
         return set;
diff --git a/src/test/java/io/vavr/LazyTest.java b/src/test/java/io/vavr/LazyTest.java
index 8002ef7bd..7980ba7b5 100644
--- a/src/test/java/io/vavr/LazyTest.java
+++ b/src/test/java/io/vavr/LazyTest.java
@@ -90,11 +90,6 @@ public void shouldNotChangeLazy() {
         assertThat(Lazy.of(expected)).isSameAs(expected);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowOnNullSupplier() {
-        Lazy.of(null);
-    }
-
     @Test
     public void shouldMemoizeValues() {
         final Lazy testee = Lazy.of(Math::random);
@@ -219,12 +214,7 @@ public void shouldCreateLazyProxy() {
         assertThat(evaluated[0]).isEqualTo("Yay!");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenCreatingLazyProxyAndSupplierIsNull() {
-        Lazy.val(null, CharSequence.class);
-    }
-
-    @Test(expected = NullPointerException.class)
+    @Test(expected = Exception.class)
     public void shouldThrowWhenCreatingLazyProxyAndTypeIsNull() {
         Lazy.val(() -> "", null);
     }
diff --git a/src/test/java/io/vavr/collection/AbstractMapTest.java b/src/test/java/io/vavr/collection/AbstractMapTest.java
index 2a89a1b0c..afa81b847 100644
--- a/src/test/java/io/vavr/collection/AbstractMapTest.java
+++ b/src/test/java/io/vavr/collection/AbstractMapTest.java
@@ -933,11 +933,13 @@ public void shouldZipNonNilsOfSameSize() {
                 Stream.of(Tuple.of(Tuple.of(0, 0), 5), Tuple.of(Tuple.of(1, 1), 6), Tuple.of(Tuple.of(2, 2), 7)));
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowIfZipWithThatIsNull() {
-        emptyMap().zip(null);
+    @Override
+    @Test
+    public void shouldIgnoreNullIfThereIsNothingToZip() {
+        assertThat(emptyMap().zip(null)).isEmpty();
     }
 
+
     // -- zipWithIndex
 
     @Test
diff --git a/src/test/java/io/vavr/collection/AbstractMultimapTest.java b/src/test/java/io/vavr/collection/AbstractMultimapTest.java
index f06cf6b04..fd1fe8cbe 100644
--- a/src/test/java/io/vavr/collection/AbstractMultimapTest.java
+++ b/src/test/java/io/vavr/collection/AbstractMultimapTest.java
@@ -1063,9 +1063,10 @@ public void shouldZipNonNilsOfSameSize() {
                 Stream.of(Tuple.of(Tuple.of(0, 0), 5), Tuple.of(Tuple.of(1, 1), 6), Tuple.of(Tuple.of(2, 2), 7)));
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowIfZipWithThatIsNull() {
-        emptyMap().zip(null);
+    @Override
+    @Test
+    public void shouldIgnoreNullIfThereIsNothingToZip() {
+        assertThat(emptyMap().zip(null)).isEmpty();
     }
 
     // -- zipWithIndex
diff --git a/src/test/java/io/vavr/collection/AbstractTraversableTest.java b/src/test/java/io/vavr/collection/AbstractTraversableTest.java
index d7ae502c5..df3c12a49 100644
--- a/src/test/java/io/vavr/collection/AbstractTraversableTest.java
+++ b/src/test/java/io/vavr/collection/AbstractTraversableTest.java
@@ -300,10 +300,8 @@ public void shouldCalculateAverageOfFloatPositiveAndNegativeInfinity() {
     // -- collect
 
     @Test
-    public void shouldThrowOnCollectWhenPartialFunctionIsNull() {
-        assertThatThrownBy(() -> empty().collect((PartialFunction) null))
-                .isExactlyInstanceOf(NullPointerException.class)
-                .hasMessage("partialFunction is null");
+    public void shouldIgnoreNullPartialFunctionWhenThereAreNoElementsToCollect() {
+        assertThat(empty().collect((PartialFunction) null)).isEmpty();
     }
 
     @Test
@@ -809,9 +807,14 @@ public void shouldFoldNil() {
         assertThat(this. empty().fold("", (a, b) -> a + b)).isEqualTo("");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenFoldNullOperator() {
-        this. empty().fold(null, null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToFold() {
+        assertThat(this. empty().fold("", null)).isEqualTo("");
+    }
+
+    @Test
+    public void shouldIgnoreNullOperatorAndTolerateNullZeroWhenThereAreNoElementsToFold() {
+        assertThat(this. empty().fold(null, null)).isEqualTo(null);
     }
 
     @Test
@@ -831,9 +834,10 @@ public void shouldFoldLeftNil() {
         assertThat(this. empty().foldLeft("", (xs, x) -> xs + x)).isEqualTo("");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenFoldLeftNullOperator() {
-        this. empty().foldLeft(null, null);
+    @Test
+    public void shouldTolerateNullOperatorInFoldLeftWhenThereIsNoNeedToInvokeIt() {
+        final Object zeroish = new Object();
+        assertThat(this. empty().foldLeft(zeroish, null)).isEqualTo(zeroish);
     }
 
     @Test
@@ -848,9 +852,10 @@ public void shouldFoldRightNil() {
         assertThat(this. empty().foldRight("", (x, xs) -> x + xs)).isEqualTo("");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenFoldRightNullOperator() {
-        this. empty().foldRight(null, null);
+    @Test
+    public void shouldTolerateNullOperatorInFoldRightWhenThereIsNoNeedToInvokeIt() {
+        final Object zeroish = new Object();
+        assertThat(this. empty().foldRight(zeroish, null)).isEqualTo(zeroish);
     }
 
     @Test
@@ -1275,8 +1280,8 @@ public void shouldCalculateMaxOfFloatPositiveAndNegativeInfinity() {
 
     // -- maxBy(Comparator)
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenMaxByWithNullComparator() {
+    @Test
+    public void shouldTolerateNullComparatorInMaxByWhenThereIsNoNeedToInvokeIt() {
         of(1).maxBy((Comparator) null);
     }
 
@@ -1429,8 +1434,8 @@ public void shouldCalculateMinOfFloatPositiveAndNegativeInfinity() {
 
     // -- minBy(Comparator)
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenMinByWithNullComparator() {
+    @Test
+    public void shouldTolerateNullComparatorInMinByWhenThereIsNoNeedToInvokeIt() {
         of(1).minBy((Comparator) null);
     }
 
@@ -1528,9 +1533,9 @@ public void shouldCaclNonemptyOrElseSupplier() {
 
     // -- partition
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenPartitionNilAndPredicateIsNull() {
-        empty().partition(null);
+    @Test
+    public void shouldIgnoreNullPredicateWhenThereAreNoElementsToPartition() {
+        assertThat(empty().partition(null)).isEqualTo(Tuple.of(empty(), empty()));
     }
 
     @Test
@@ -1608,13 +1613,13 @@ public void shouldComputeProductOfBigDecimal() {
     // -- reduceOption
 
     @Test
-    public void shouldThrowWhenReduceOptionNil() {
+    public void shouldAnswerNoneOnReduceOptionOverNoElements() {
         assertThat(this. empty().reduceOption((a, b) -> a + b)).isSameAs(Option.none());
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceOptionNullOperator() {
-        this. empty().reduceOption(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduceOption() {
+        assertThat(this. empty().reduceOption(null)).isSameAs(Option.none());
     }
 
     @Test
@@ -1629,9 +1634,20 @@ public void shouldThrowWhenReduceNil() {
         this. empty().reduce((a, b) -> a + b);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceNullOperator() {
-        this. empty().reduce(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduce() {
+        // empty().reduce(f) should fail the same way, whether f is null or not null.
+        try {
+            this.empty().reduce(null);
+            fail("How did empty().reduce() not throw an exception?!");
+        } catch (Exception caughtWithNullOperator) {
+            try {
+                this.empty().reduce((a, b) -> a + b);
+                fail("How did empty().reduce() not throw an exception?!");
+            } catch (Exception caughtWithValidOperator) {
+                assertThat(caughtWithNullOperator.getClass()).isEqualTo(caughtWithValidOperator.getClass());
+            }
+        }
     }
 
     @Test
@@ -1642,13 +1658,13 @@ public void shouldReduceNonNil() {
     // -- reduceLeftOption
 
     @Test
-    public void shouldThrowWhenReduceLeftOptionNil() {
+    public void shouldAnswerNoneOnReduceLeftOptionOverNoElements() {
         assertThat(this. empty().reduceLeftOption((a, b) -> a + b)).isSameAs(Option.none());
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceLeftOptionNullOperator() {
-        this. empty().reduceLeftOption(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduceLeftOption() {
+        assertThat(this. empty().reduceLeftOption(null)).isSameAs(Option.none());
     }
 
     @Test
@@ -1663,9 +1679,20 @@ public void shouldThrowWhenReduceLeftNil() {
         this. empty().reduceLeft((a, b) -> a + b);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceLeftNullOperator() {
-        this. empty().reduceLeft(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduceLeft() {
+        // empty().reduceLeft(f) should fail the same way, whether f is null or not null.
+        try {
+            this.empty().reduceLeft(null);
+            fail("How did empty().reduceLeft() not throw an exception?!");
+        } catch (Exception caughtWithNullOperator) {
+            try {
+                this.empty().reduceLeft((a, b) -> a + b);
+                fail("How did empty().reduceLeft() not throw an exception?!");
+            } catch (Exception caughtWithValidOperator) {
+                assertThat(caughtWithNullOperator.getClass()).isEqualTo(caughtWithValidOperator.getClass());
+            }
+        }
     }
 
     @Test
@@ -1676,13 +1703,13 @@ public void shouldReduceLeftNonNil() {
     // -- reduceRightOption
 
     @Test
-    public void shouldThrowWhenReduceRightOptionNil() {
+    public void shouldAnswerNoneOnReduceRightOptionOverNoElements() {
         assertThat(this. empty().reduceRightOption((a, b) -> a + b)).isSameAs(Option.none());
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceRightOptionNullOperator() {
-        this. empty().reduceRightOption(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduceRightOption() {
+        assertThat(this. empty().reduceRightOption(null)).isSameAs(Option.none());
     }
 
     @Test
@@ -1697,9 +1724,20 @@ public void shouldThrowWhenReduceRightNil() {
         this. empty().reduceRight((a, b) -> a + b);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenReduceRightNullOperator() {
-        this. empty().reduceRight(null);
+    @Test
+    public void shouldIgnoreNullOperatorWhenThereAreNoElementsToReduceRight() {
+        // empty().reduceRight(f) should fail the same way, whether f is null or not null.
+        try {
+            this.empty().reduceRight(null);
+            fail("How did empty().reduceRight() not throw an exception?!");
+        } catch (Exception caughtWithNullOperator) {
+            try {
+                this.empty().reduceRight((a, b) -> a + b);
+                fail("How did empty().reduceRight() not throw an exception?!");
+            } catch (Exception caughtWithValidOperator) {
+                assertThat(caughtWithNullOperator.getClass()).isEqualTo(caughtWithValidOperator.getClass());
+            }
+        }
     }
 
     @Test
@@ -2461,9 +2499,9 @@ public void shouldZipWithNonNilsOfSameSize() {
         assertThat(actual).isEqualTo(expected);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowIfZipWithThatIsNull() {
-        empty().zip(null);
+    @Test
+    public void shouldIgnoreNullIfThereIsNothingToZip() {
+        assertThat(empty().zip(null)).isEmpty();
     }
 
     // -- zipAll
diff --git a/src/test/java/io/vavr/collection/CharSeqTest.java b/src/test/java/io/vavr/collection/CharSeqTest.java
index f8190177e..a69bec890 100644
--- a/src/test/java/io/vavr/collection/CharSeqTest.java
+++ b/src/test/java/io/vavr/collection/CharSeqTest.java
@@ -943,7 +943,12 @@ public void shouldFoldNil() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenFoldNullOperator() {
-        CharSeq.empty().fold(null, null);
+        CharSeq.of('a').fold(null, null);
+    }
+
+    @Test
+    public void shouldIgnoreFoldNullOperatorWhenNotRequired() {
+        assertThat(CharSeq.empty().fold('0', null)).isEqualTo('0');
     }
 
     @Test
@@ -958,8 +963,8 @@ public void shouldFoldLeftNil() {
         assertThat(CharSeq.empty().foldLeft("", (xs, x) -> xs + x)).isEqualTo("");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowWhenFoldLeftNullOperator() {
+    @Test
+    public void shouldIgnoreNullOperatorWhenEmpty() {
         CharSeq.empty().foldLeft(null, null);
     }
 
@@ -977,7 +982,7 @@ public void shouldFoldRightNil() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenFoldRightNullOperator() {
-        CharSeq.empty().foldRight(null, null);
+        CharSeq.of('a').foldRight(null, null);
     }
 
     @Test
@@ -1224,7 +1229,12 @@ public void shouldMapToCharSeqWhenMapCharsIsUsed() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenPartitionNilAndPredicateIsNull() {
-        CharSeq.empty().partition(null);
+        CharSeq.of('a').partition(null);
+    }
+
+    @Test
+    public void shouldNotThrowWhenPredicateNullNotRequired() {
+        assertThat(CharSeq.empty().partition(null)).isEqualTo(Tuple.of(Array.empty(), Array.empty()));
     }
 
     @Test
@@ -1277,7 +1287,12 @@ public void shouldComputeMaxOfChar() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenMaxByWithNullComparator() {
-        CharSeq.of('1').maxBy((Comparator) null);
+        CharSeq.of('1', '2').maxBy((Comparator) null);
+    }
+
+    @Test
+    public void shouldNotThrowWhenMaxByAndNotRequired() {
+        assertThat(CharSeq.of('1').maxBy((Comparator)null)).isEqualTo(Option.some('1'));
     }
 
     @Test
@@ -1333,7 +1348,12 @@ public void shouldComputeMinOfChar() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenMinByWithNullComparator() {
-        CharSeq.of('1').minBy((Comparator) null);
+        CharSeq.of('1', '2').minBy((Comparator) null);
+    }
+
+    @Test
+    public void shouldIgnoreNullComparatorWhenMinByAndOneElement() {
+        assertThat(CharSeq.of('1').minBy((Comparator) null)).isEqualTo(Option.some('1'));
     }
 
     @Test
@@ -1402,9 +1422,14 @@ public void shouldThrowWhenReduceNil() {
         CharSeq.empty().reduce((a, b) -> a);
     }
 
+    @Test
+    public void shouldNotThrowWhenReduceNullOperatorNotRequired() {
+        assertThat(CharSeq.of('a').reduce(null)).isEqualTo('a');
+    }
+
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenReduceNullOperator() {
-        CharSeq.empty().reduce(null);
+        CharSeq.of('a', 'b').reduce(null);
     }
 
     @Test
@@ -1419,9 +1444,14 @@ public void shouldThrowWhenReduceLeftNil() {
         CharSeq.empty().reduceLeft((a, b) -> a);
     }
 
+    @Test
+    public void shouldNotThrowWhenReduceLeftNullOperatorNotRequired() {
+        CharSeq.of('a').reduceLeft(null);
+    }
+
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenReduceLeftNullOperator() {
-        CharSeq.empty().reduceLeft(null);
+        CharSeq.of('a', 'b').reduceLeft(null);
     }
 
     @Test
@@ -1436,9 +1466,14 @@ public void shouldThrowWhenReduceRightNil() {
         CharSeq.empty().reduceRight((a, b) -> a);
     }
 
+    @Test
+    public void shouldNotThrowWhenReduceRightNullOperatorNotRequired() {
+        assertThat(CharSeq.of('a').reduceRight(null)).isEqualTo('a');
+    }
+
     @Test(expected = NullPointerException.class)
     public void shouldThrowWhenReduceRightNullOperator() {
-        CharSeq.empty().reduceRight(null);
+        CharSeq.of('a', 'b').reduceRight(null);
     }
 
     @Test
diff --git a/src/test/java/io/vavr/collection/HashSetTest.java b/src/test/java/io/vavr/collection/HashSetTest.java
index dd56e7c56..705ef75f2 100644
--- a/src/test/java/io/vavr/collection/HashSetTest.java
+++ b/src/test/java/io/vavr/collection/HashSetTest.java
@@ -252,11 +252,6 @@ public void shouldZipNonNilsOfSameSize() {
         assertThat(actual).isEqualTo(expected);
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowIfZipWithThatIsNull() {
-        empty().zip(null);
-    }
-
     // TODO move to traversable
     // -- zipAll
 
@@ -387,11 +382,6 @@ public void shouldFindLastOfNonNil() {
         assertThat(actual).isIn(List.of(1, 2, 3, 4));
     }
 
-    @Override
-    public void shouldThrowWhenFoldRightNullOperator() {
-        throw new NullPointerException(); // TODO
-    }
-
     @Override
     public void shouldReturnSomeInitWhenCallingInitOptionOnNonNil() {
         // TODO
diff --git a/src/test/java/io/vavr/collection/IntMap.java b/src/test/java/io/vavr/collection/IntMap.java
index be2cb51c5..534244545 100644
--- a/src/test/java/io/vavr/collection/IntMap.java
+++ b/src/test/java/io/vavr/collection/IntMap.java
@@ -99,7 +99,6 @@ public String toString() {
 
     @Override
     public  Seq collect(PartialFunction partialFunction) {
-        Objects.requireNonNull(partialFunction, "partialFunction is null");
         final PartialFunction, R> pf = new PartialFunction, R>() {
             private static final long serialVersionUID = 1L;
             @Override
@@ -168,7 +167,6 @@ public  Seq flatMap(Function> m
 
     @Override
     public  U foldRight(U zero, BiFunction f) {
-        Objects.requireNonNull(f, "f is null");
         return original.foldRight(zero, (e, u) -> f.apply(e._2, u));
     }
 
@@ -245,7 +243,6 @@ public IntMap orElse(Supplier> supplier) {
 
     @Override
     public Tuple2, IntMap> partition(Predicate predicate) {
-        Objects.requireNonNull(predicate, "predicate is null");
         return original.partition(p -> predicate.test(p._2)).map(IntMap::of, IntMap::of);
     }
 
@@ -393,14 +390,11 @@ public  Seq> zip(Iterable that) {
 
     @Override
     public  Seq zipWith(Iterable that, BiFunction mapper) {
-        Objects.requireNonNull(that, "that is null");
-        Objects.requireNonNull(mapper, "mapper is null");
         return Stream.ofAll(iterator().zipWith(that, mapper));
     }
 
     @Override
     public  Seq> zipAll(Iterable that, T thisElem, U thatElem) {
-        Objects.requireNonNull(that, "that is null");
         return Stream.ofAll(iterator().zipAll(that, thisElem, thatElem));
     }
 
@@ -411,7 +405,6 @@ public Seq> zipWithIndex() {
 
     @Override
     public  Seq zipWithIndex(BiFunction mapper) {
-        Objects.requireNonNull(mapper, "mapper is null");
         return Stream.ofAll(iterator().zipWithIndex(mapper));
     }
 }
diff --git a/src/test/java/io/vavr/collection/IntMultimap.java b/src/test/java/io/vavr/collection/IntMultimap.java
index ec8a017ee..d6cf52bd4 100644
--- a/src/test/java/io/vavr/collection/IntMultimap.java
+++ b/src/test/java/io/vavr/collection/IntMultimap.java
@@ -100,7 +100,6 @@ public String toString() {
 
     @Override
     public  Seq collect(PartialFunction partialFunction) {
-        Objects.requireNonNull(partialFunction, "partialFunction is null");
         final PartialFunction, R> pf = new PartialFunction, R>() {
             private static final long serialVersionUID = 1L;
             @Override
@@ -169,7 +168,6 @@ public  Seq flatMap(Function> m
 
     @Override
     public  U foldRight(U zero, BiFunction f) {
-        Objects.requireNonNull(f, "f is null");
         return original.foldRight(zero, (e, u) -> f.apply(e._2, u));
     }
 
@@ -246,7 +244,6 @@ public IntMultimap orElse(Supplier> supplier)
 
     @Override
     public Tuple2, IntMultimap> partition(Predicate predicate) {
-        Objects.requireNonNull(predicate, "predicate is null");
         return original.partition(p -> predicate.test(p._2)).map(IntMultimap::of, IntMultimap::of);
     }
 
@@ -394,14 +391,11 @@ public  Seq> zip(Iterable that) {
 
     @Override
     public  Seq zipWith(Iterable that, BiFunction mapper) {
-        Objects.requireNonNull(that, "that is null");
-        Objects.requireNonNull(mapper, "mapper is null");
         return Stream.ofAll(iterator().zipWith(that, mapper));
     }
 
     @Override
     public  Seq> zipAll(Iterable that, T thisElem, U thatElem) {
-        Objects.requireNonNull(that, "that is null");
         return Stream.ofAll(iterator().zipAll(that, thisElem, thatElem));
     }
 
@@ -412,7 +406,6 @@ public Seq> zipWithIndex() {
 
     @Override
     public  Seq zipWithIndex(BiFunction mapper) {
-        Objects.requireNonNull(mapper, "mapper is null");
         return Stream.ofAll(iterator().zipWithIndex(mapper));
     }
 }
diff --git a/src/test/java/io/vavr/collection/JavaConvertersTest.java b/src/test/java/io/vavr/collection/JavaConvertersTest.java
index d7b41d87c..505c977f4 100644
--- a/src/test/java/io/vavr/collection/JavaConvertersTest.java
+++ b/src/test/java/io/vavr/collection/JavaConvertersTest.java
@@ -240,14 +240,13 @@ public void shouldAddElementAtSizeIndexToNonEmpty() {
 
     // -- addAll(Collection)
 
-    @Test(expected = NullPointerException.class)
     public void shouldThrowNPEWhenAddingAllNullCollectionToEmpty() {
-        empty().addAll(null);
+        ifSupported(() -> empty().addAll(null), NullPointerException.class);
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void shouldThrowNPEWhenAddingAllNullCollectionToNonEmpty() {
-        of('1').addAll(null);
+        ifSupported(() -> of('1').addAll(null), NullPointerException.class);
     }
 
     @Test
@@ -292,14 +291,12 @@ public void shouldReturnTrueIfAddAllNonEmptyToNonEmpty() {
 
     @Test
     public void shouldThrowNPEWhenAddingAllNullCollectionAtFirstIndexToEmpty() {
-        assertThatThrownBy(() -> empty().addAll(0, null))
-                .isInstanceOf(NullPointerException.class);
+        ifSupported(() -> empty().addAll(0, null), NullPointerException.class);
     }
 
     @Test
     public void shouldThrowNPEWhenAddingAllNullCollectionAtFirstIndexToNonEmpty() {
-        assertThatThrownBy(() -> of('1').addAll(0, null))
-                .isInstanceOf(NullPointerException.class);
+        ifSupported(() -> of('1').addAll(0, null), NullPointerException.class);
     }
 
     @Test
@@ -1851,15 +1848,13 @@ public void shouldRemoveNull() {
     // -- removeAll(Collection)
 
     @Test
-    public void shouldThrowNPEWhenCallingRemoveAllNullWhenEmpty() {
-        assertThatThrownBy(() -> empty().removeAll(null))
-                .isInstanceOf(NullPointerException.class);
+    public void shouldNotThrowWhenCallingRemoveAllNullAndEmpty() {
+        ifSupported(() -> empty().removeAll(null));
     }
 
     @Test
     public void shouldThrowNPEWhenCallingRemoveAllNullWhenNotEmpty() {
-        assertThatThrownBy(() -> of('1').removeAll(null))
-                .isInstanceOf(NullPointerException.class);
+        ifSupported(() -> of('1').removeAll(null), NullPointerException.class);
     }
 
     @Test
@@ -1945,23 +1940,25 @@ public void shouldReplaceAllOfNonEmpty() {
     // -- retainAll(Collection)
 
     @Test
-    public void shouldThrowNPEWhenCallingRetainAllNullWhenEmpty() {
-        assertThatThrownBy(() -> empty().retainAll(null))
-                .isInstanceOf(NullPointerException.class);
+    public void shouldIgnoreCollectionWhenCallingRetainAllNullWhenEmpty() {
+        ifSupported(() -> empty().retainAll(null));
     }
 
     @Test
     public void shouldThrowNPEWhenCallingRetainAllNullWhenNotEmpty() {
-        assertThatThrownBy(() -> of('1').retainAll(null))
-                .isInstanceOf(NullPointerException.class);
+        ifSupported(() -> of('1').retainAll(null), NullPointerException.class);
     }
 
     // -- retainAll(Collection) tests
 
     @Test
-    public void shouldThrowWhenRetainAllNull() {
-        assertThatThrownBy(() -> empty().retainAll(null)).isInstanceOf(NullPointerException.class);
-        assertThatThrownBy(() -> of('1').retainAll(null)).isInstanceOf(NullPointerException.class);
+    public void shouldIgnoreCollectionWhenRetainAllNullAndEmpty() {
+        ifSupported(() -> empty().retainAll(null));
+    }
+
+    @Test
+    public void shouldThrowWhenNotEmptyAndRetainAllNull() {
+        ifSupported(() -> of('1').retainAll(null), NullPointerException.class);
     }
 
     @Test
@@ -2279,9 +2276,8 @@ private final void ifSupported(Runnable test, Class... expe
         } catch (Throwable x) {
             if (changePolicy == IMMUTABLE) {
                 if (!(x instanceof UnsupportedOperationException)) {
-                    final boolean isJavaCollection = empty().getClass().getName().startsWith("java.util.");
                     // DEV-NOTE: Java's collections throw UnsupportedOperationException inconsistently
-                    if (!isJavaCollection) {
+                    if (!isJavaCollection()) {
                         Assert.fail("Operation should throw " + UnsupportedOperationException.class.getName() + " but found " + x.getClass().getName() + ":\n" + x.getMessage());
                     }
                 }
@@ -2292,11 +2288,19 @@ private final void ifSupported(Runnable test, Class... expe
                         return;
                     }
                 }
+                if (isJavaCollection() && expectedExceptionTypes.length == 0 && actualType.equals(NullPointerException.class)) {
+                    // DEV-NOTE: specifically for TestCase 7 java.util.ArrayList. Do we need to test java collections at all?
+                    return;
+                }
                 throw x;
             }
         }
     }
 
+    private boolean isJavaCollection() {
+        return empty().getClass().getName().startsWith("java.util.");
+    }
+
     static final class ListFactory {
 
         private final Function> listFactory;
diff --git a/src/test/java/io/vavr/concurrent/FutureTest.java b/src/test/java/io/vavr/concurrent/FutureTest.java
index f60f45586..10df2a6d7 100644
--- a/src/test/java/io/vavr/concurrent/FutureTest.java
+++ b/src/test/java/io/vavr/concurrent/FutureTest.java
@@ -404,7 +404,7 @@ public void shouldCreateAndCompleteAFutureUsingTrivialExecutorServiceAndCallable
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowNPEWhenExecutorIsNullUsingCallable() {
-        Future.ofCallable(null, () -> 1);
+        Future.ofCallable(null, () -> 1).await();
     }
 
     @Test(expected = NullPointerException.class)
@@ -781,7 +781,7 @@ public void shouldCollectEmptyFutureUsingPartialFunction() {
     @Test(expected = NullPointerException.class)
     public void shouldThrowExceptionOnNullCollectPartialFunction() {
         final PartialFunction pf = null;
-        Future.of(zZz(3)).collect(pf);
+        Future.of(zZz(3)).collect(pf).get();
     }
 
     // -- executorService()
diff --git a/src/test/java/io/vavr/control/EitherTest.java b/src/test/java/io/vavr/control/EitherTest.java
index b120ccb68..89c2a88b1 100644
--- a/src/test/java/io/vavr/control/EitherTest.java
+++ b/src/test/java/io/vavr/control/EitherTest.java
@@ -116,11 +116,9 @@ public void shouldFoldRight() {
 
     // -- sequence
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenSequencingNull() {
-        assertThatThrownBy(() -> Either.sequence(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("eithers is null");
+        Either.sequence(null);
     }
 
     @Test
@@ -157,11 +155,9 @@ public void shouldSequenceNonEmptyIterableOfMixedEither() {
 
     // -- sequenceRight
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenSequencingRightNull() {
-        assertThatThrownBy(() -> Either.sequenceRight(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("eithers is null");
+        Either.sequenceRight(null);
     }
 
     @Test
@@ -217,11 +213,9 @@ public void shouldHandleTransformOnLeft() {
 
     // -- traverse
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenTraversingNull() {
-        assertThatThrownBy(() -> Either.traverse(null, null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("values is null");
+        Either.traverse(null, null);
     }
 
     @Test
@@ -259,11 +253,9 @@ public void shouldTraverseNonEmptyIterableOfMixedEither() {
 
     // -- traverseRight
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenTraversingRightNull() {
-        assertThatThrownBy(() -> Either.traverseRight(null, null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("values is null");
+        Either.traverseRight(null, null);
     }
 
     @Test
@@ -434,11 +426,9 @@ public void shouldFilterNotLeft() {
         assertThat(either.filterNot(i -> true).get()).isSameAs(either);
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenNullPredicate() {
-        assertThatThrownBy(() -> Either.left(42).filterNot(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("predicate is null");
+        Either.left(42).filterNot(null);
     }
 
     // -- filterOrElse
diff --git a/src/test/java/io/vavr/control/OptionTest.java b/src/test/java/io/vavr/control/OptionTest.java
index 20e08f4c5..26df2e12e 100644
--- a/src/test/java/io/vavr/control/OptionTest.java
+++ b/src/test/java/io/vavr/control/OptionTest.java
@@ -119,8 +119,8 @@ public void shouldNotExecuteIfFalse() {
         })).isEqualTo(Option.none());
     }
 
-    @Test(expected = NullPointerException.class)
-    public void shouldThrowExceptionOnWhenWithProvider() {
+    @Test
+    public void shouldIgnoreSupplierNullOnWhenWithProvider() {
         assertThat(Option.when(false, (Supplier) null)).isEqualTo(Option.none());
     }
 
@@ -316,15 +316,10 @@ public void shouldBePresentOnIsEmptyWhenValue() {
 
     // -- onEmpty
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowNullPointerExceptionWhenNullOnEmptyActionPassed() {
-        try {
-            final Option none = Option.none();
-            none.onEmpty(null);
-            Assert.fail("No exception was thrown");
-        } catch (NullPointerException exc) {
-            assertThat(exc.getMessage()).isEqualTo("action is null");
-        }
+        final Option none = Option.none();
+        none.onEmpty(null);
     }
 
     @Test
@@ -381,11 +376,9 @@ public void shouldReturnNoneOnFilterNotWhenValueIsNotDefinedAndPredicateNotMatch
         assertThat(Option.none().filterNot(i -> i == 1)).isEqualTo(Option.none());
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void shouldThrowWhenFilterNotPredicateIsNull() {
-        assertThatThrownBy(() -> Option.of(1).filterNot(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("predicate is null");
+        Option.of(1).filterNot(null);
     }
 
     // -- map
diff --git a/src/test/java/io/vavr/control/TryTest.java b/src/test/java/io/vavr/control/TryTest.java
index f01719841..9f653615e 100644
--- a/src/test/java/io/vavr/control/TryTest.java
+++ b/src/test/java/io/vavr/control/TryTest.java
@@ -261,8 +261,8 @@ public void shouldCreateFailureWhenCallingTryOfCheckedFunction0() {
     }
 
     @Test
-    public void shouldThrowNullPointerExceptionWhenCallingTryOfCheckedFunction0() {
-        assertThatThrownBy(() -> Try.of(null)).isInstanceOf(NullPointerException.class).hasMessage("supplier is null");
+    public void shouldReturnFailureWithNPEWhenCallingTryOfCheckedFunction0Null() {
+        assertThat(Try.of(null).getCause()).isInstanceOf(NullPointerException.class);
     }
 
     // -- Try.fold
@@ -292,7 +292,7 @@ public void shouldCreateSuccessWhenCallingTryOfSupplier() {
 
     @Test
     public void shouldThrowNullPointerExceptionWhenCallingTryOfSupplier() {
-        assertThatThrownBy(() -> Try.ofSupplier(null)).isInstanceOf(NullPointerException.class).hasMessage("supplier is null");
+        assertThatThrownBy(() -> Try.ofSupplier(null)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
@@ -318,7 +318,7 @@ public void shouldCreateFailureWhenCallingTryOfCallable() {
 
     @Test
     public void shouldThrowNullPointerExceptionWhenCallingTryOfCallable() {
-        assertThatThrownBy(() -> Try.ofCallable(null)).isInstanceOf(NullPointerException.class).hasMessage("callable is null");
+        assertThatThrownBy(() -> Try.ofCallable(null)).isInstanceOf(NullPointerException.class);
     }
 
     // -- Try.run
@@ -338,7 +338,7 @@ public void shouldCreateFailureWhenCallingTryRunCheckedRunnable() {
 
     @Test
     public void shouldThrowNullPointerExceptionWhenCallingTryRunCheckedRunnable() {
-        assertThatThrownBy(() -> Try.run(null)).isInstanceOf(NullPointerException.class).hasMessage("runnable is null");
+        assertThat(Try.run(null).getCause()).isInstanceOf(NullPointerException.class);
     }
 
     // -- Try.runRunnable
@@ -358,7 +358,7 @@ public void shouldCreateFailureWhenCallingTryRunRunnable() {
 
     @Test
     public void shouldThrowNullPointerExceptionWhenCallingTryRunRunnable() {
-        assertThatThrownBy(() -> Try.runRunnable(null)).isInstanceOf(NullPointerException.class).hasMessage("runnable is null");
+        assertThatThrownBy(() -> Try.runRunnable(null)).isInstanceOf(NullPointerException.class);
     }
 
     // -- Try.withResources
@@ -1089,8 +1089,7 @@ public void shouldFilterNotWithExceptionOnFailure() {
     @Test
     public void failureShouldThrowWhenFilterNotWithNullPredicate() {
         assertThatThrownBy(() -> failure().filterNot(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("predicate is null");
+                .isInstanceOf(NullPointerException.class);
     }
 
     // -- flatMap
@@ -1500,8 +1499,7 @@ public void shouldFilterNotWithExceptionOnSuccess() {
     @Test
     public void successShouldThrowWhenFilterNotWithNullPredicate() {
         assertThatThrownBy(() -> success().filterNot(null))
-                .isInstanceOf(NullPointerException.class)
-                .hasMessage("predicate is null");
+                .isInstanceOf(NullPointerException.class);
     }
 
     // -- flatMap
diff --git a/src/test/java/io/vavr/control/ValidationTest.java b/src/test/java/io/vavr/control/ValidationTest.java
index 9ecb96786..efefa0d58 100644
--- a/src/test/java/io/vavr/control/ValidationTest.java
+++ b/src/test/java/io/vavr/control/ValidationTest.java
@@ -377,7 +377,12 @@ public void shouldThrowWhenGetOrElseThrowWithFunctionOnInvalid() {
 
     @Test(expected = NullPointerException.class)
     public void shouldThrowNullPointerExceptionWhenGetOrElseThrowNullWithFunctionOnValid() {
-      Validation. valid(1).getOrElseThrow((Function) null);
+      Validation. invalid("some error").getOrElseThrow((Function) null);
+    }
+
+    @Test
+    public void shouldIgnoreExceptionSupplierWhenGetOrElseAndNotRequired() {
+        Validation. valid(1).getOrElseThrow((Function) null);
     }
 
     @Test(expected = NullPointerException.class)