[patch] Add missing @throws to methods using Objects.requireNonNull()
Jürgen Kreileder
jk at blackdown.de
Wed Apr 3 08:51:04 PDT 2013
The following patch adds missing @throws NPE and removes some
superfluous public modifiers on the way:
# HG changeset patch
# User Jürgen Kreileder <jk at blackdown.de>
# Date 1365002857 -7200
# Node ID 2edcdd9d365811a06dc2a271416dee73e1597c8e
# Parent b6327bd4e9a27d6157e772c845ce1909d2dc0a43
* Add @throws for methods using Objects.requireNonNull()
* Remove superfluous public modifiers
diff --git a/src/share/classes/java/util/function/BiConsumer.java
b/src/share/classes/java/util/function/BiConsumer.java
--- a/src/share/classes/java/util/function/BiConsumer.java
+++ b/src/share/classes/java/util/function/BiConsumer.java
@@ -58,8 +58,9 @@
* @param other an additional BiConsumer which will be chained
after this BiConsumer
* @return a BiConsumer which performs in sequence the {@code
apply} method of
* this BiConsumer and the {@code apply} method of the specified
BiConsumer operation
+ * @throws NullPointerException if other is null
*/
- public default BiConsumer<T, U> chain(BiConsumer<? super T, ?
super U> other) {
+ default BiConsumer<T, U> chain(BiConsumer<? super T, ? super U> other) {
Objects.requireNonNull(other);
return (l, r) -> {
diff --git a/src/share/classes/java/util/function/BiPredicate.java
b/src/share/classes/java/util/function/BiPredicate.java
--- a/src/share/classes/java/util/function/BiPredicate.java
+++ b/src/share/classes/java/util/function/BiPredicate.java
@@ -57,8 +57,9 @@
* @param p a predicate which will be logically-ANDed with this predicate.
* @return a new predicate which returns {@code true} only if both
* predicates return {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> p) {
+ default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> p) {
Objects.requireNonNull(p);
return (T t, U u) -> test(t, u) && p.test(t, u);
}
@@ -69,7 +70,7 @@
* @return a new predicate who's result is always the opposite of this
* predicate.
*/
- public default BiPredicate<T, U> negate() {
+ default BiPredicate<T, U> negate() {
return (T t, U u) -> !test(t, u);
}
@@ -82,8 +83,9 @@
* @param p a predicate which will be logically-ORed with this predicate.
* @return a new predicate which returns {@code true} if either predicate
* returns {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> p) {
+ default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> p) {
Objects.requireNonNull(p);
return (T t, U u) -> test(t, u) || p.test(t, u);
}
@@ -95,8 +97,9 @@
* @param p a predicate which will be logically-XORed with this predicate.
* @return a predicate that evaluates to {@code true} if both or neither of
* the component predicates evaluate to {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default BiPredicate<T, U> xor(BiPredicate<? super T, ? super U> p) {
+ default BiPredicate<T, U> xor(BiPredicate<? super T, ? super U> p) {
Objects.requireNonNull(p);
return (T t, U u) -> test(t, u) ^ p.test(t, u);
}
diff --git a/src/share/classes/java/util/function/Consumer.java
b/src/share/classes/java/util/function/Consumer.java
--- a/src/share/classes/java/util/function/Consumer.java
+++ b/src/share/classes/java/util/function/Consumer.java
@@ -43,7 +43,7 @@
*
* @param t the input object
*/
- public void accept(T t);
+ void accept(T t);
/**
* Returns a Consumer which performs in sequence the {@code
apply} methods of
@@ -53,8 +53,9 @@
* @param other an additional Consumer which will be chained
after this Consumer
* @return a Consumer which performs in sequence the {@code
apply} method of
* this Consumer and the {@code apply} method of the specified
Consumer operation
+ * @throws NullPointerException if other is null
*/
- public default Consumer<T> chain(Consumer<? super T> other) {
+ default Consumer<T> chain(Consumer<? super T> other) {
Objects.requireNonNull(other);
return (T t) -> { accept(t); other.accept(t); };
}
diff --git a/src/share/classes/java/util/function/DoublePredicate.java
b/src/share/classes/java/util/function/DoublePredicate.java
--- a/src/share/classes/java/util/function/DoublePredicate.java
+++ b/src/share/classes/java/util/function/DoublePredicate.java
@@ -44,7 +44,7 @@
* @return {@code true} if the input value matches some criteria, otherwise
* {@code false}.
*/
- public boolean test(double value);
+ boolean test(double value);
/**
* Returns a predicate which evaluates to {@code true} only if this
@@ -55,8 +55,9 @@
* @param p a predicate which will be logically-ANDed with this predicate.
* @return a new predicate which returns {@code true} only if both
* predicates return {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default DoublePredicate and(DoublePredicate p) {
+ default DoublePredicate and(DoublePredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) && p.test(value);
}
@@ -67,7 +68,7 @@
* @return a new predicate who's result is always the opposite of this
* predicate.
*/
- public default DoublePredicate negate() {
+ default DoublePredicate negate() {
return (value) -> !test(value);
}
@@ -80,8 +81,9 @@
* @param p a predicate which will be logically-ANDed with this predicate.
* @return a new predicate which returns {@code true} if either predicate
* returns {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default DoublePredicate or(DoublePredicate p) {
+ default DoublePredicate or(DoublePredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) || p.test(value);
}
@@ -93,8 +95,9 @@
* @param p a predicate which will be logically-XORed with this predicate.
* @return a predicate that evaluates to {@code true} if all or none of the
* component predicates evaluate to {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default DoublePredicate xor(DoublePredicate p) {
+ default DoublePredicate xor(DoublePredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) ^ p.test(value);
}
diff --git a/src/share/classes/java/util/function/Functions.java
b/src/share/classes/java/util/function/Functions.java
--- a/src/share/classes/java/util/function/Functions.java
+++ b/src/share/classes/java/util/function/Functions.java
@@ -87,6 +87,7 @@
* @param map provides the mappings from {@code <T>} to {@code <U>}
* @throws IllegalArgumentException for all values of {@code <T>} not
* present in the map
+ * @throws NullPointerException if map is null
*/
public static <R, T> Function<T, R> forMap(Map<? super T, ?
extends R> map) {
Objects.requireNonNull(map);
@@ -112,6 +113,7 @@
* @param mapping provides the mappings from {@code <T>} to {@code <U>}
* @param defaultValue the value returned by {@code apply} method for
* {@code <T>} values not contained in the provided map.
+ * @throws NullPointerException if mapping is null
*/
public static <T, R, RR extends R> Function<T, R> forMap(Map<?
super T, RR> mapping, RR defaultValue) {
Objects.requireNonNull(mapping);
@@ -131,6 +133,7 @@
* @param forFalse value to be returned for {@code false} predicate results
* @return a Function whose {@code apply} method provides results
according to
* the provided predicate.
+ * @throws NullPointerException if predicate is null
*/
public static <T, R> Function<T, R> forPredicate(Predicate<?
super T> predicate, R forTrue, R forFalse) {
Objects.requireNonNull(predicate);
diff --git a/src/share/classes/java/util/function/IntPredicate.java
b/src/share/classes/java/util/function/IntPredicate.java
--- a/src/share/classes/java/util/function/IntPredicate.java
+++ b/src/share/classes/java/util/function/IntPredicate.java
@@ -43,7 +43,7 @@
* @return {@code true} if the input value matches some criteria, otherwise
* {@code false}
*/
- public boolean test(int value);
+ boolean test(int value);
/**
* Returns a predicate which evaluates to {@code true} only if this
@@ -54,8 +54,9 @@
* @param p a predicate which will be logically-ANDed with this predicate.
* @return a new predicate which returns {@code true} only if both
* predicates return {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default IntPredicate and(IntPredicate p) {
+ default IntPredicate and(IntPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) && p.test(value);
}
@@ -66,7 +67,7 @@
* @return a new predicate who's result is always the opposite of this
* predicate.
*/
- public default IntPredicate negate() {
+ default IntPredicate negate() {
return (value) -> !test(value);
}
@@ -79,8 +80,9 @@
* @param p a predicate which will be logically-ORed with this predicate.
* @return a new predicate which returns {@code true} if either predicate
* returns {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default IntPredicate or(IntPredicate p) {
+ default IntPredicate or(IntPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) || p.test(value);
}
@@ -92,8 +94,9 @@
* @param p a predicate which will be logically-XORed with this predicate.
* @return a predicate that evaluates to {@code true} if both or neither of
* the component predicates evaluate to {@code true}
+ * @throws NullPointerException if p is null
*/
- public default IntPredicate xor(IntPredicate p) {
+ default IntPredicate xor(IntPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) ^ p.test(value);
}
diff --git a/src/share/classes/java/util/function/LongPredicate.java
b/src/share/classes/java/util/function/LongPredicate.java
--- a/src/share/classes/java/util/function/LongPredicate.java
+++ b/src/share/classes/java/util/function/LongPredicate.java
@@ -43,7 +43,7 @@
* @return {@code true} if the input value matches some criteria, otherwise
* {@code false}.
*/
- public boolean test(long value);
+ boolean test(long value);
/**
* Returns a predicate which evaluates to {@code true} only if this
@@ -54,8 +54,9 @@
* @param p a predicate which will be logically-ANDed with this predicate.
* @return a new predicate which returns {@code true} only if both
* predicates return {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default LongPredicate and(LongPredicate p) {
+ default LongPredicate and(LongPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) && p.test(value);
}
@@ -66,7 +67,7 @@
* @return a new predicate who's result is always the opposite of this
* predicate.
*/
- public default LongPredicate negate() {
+ default LongPredicate negate() {
return (value) -> !test(value);
}
@@ -79,8 +80,9 @@
* @param p a predicate which will be logically-ORed with this predicate.
* @return a new predicate which returns {@code true} if either predicate
* returns {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default LongPredicate or(LongPredicate p) {
+ default LongPredicate or(LongPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) || p.test(value);
}
@@ -92,8 +94,9 @@
* @param p a predicate which will be logically-XORed with this predicate.
* @return a predicate that evaluates to {@code true} if both or neither of
* the component predicates evaluate to {@code true}.
+ * @throws NullPointerException if p is null
*/
- public default LongPredicate xor(LongPredicate p) {
+ default LongPredicate xor(LongPredicate p) {
Objects.requireNonNull(p);
return (value) -> test(value) ^ p.test(value);
}
diff --git a/src/share/classes/java/util/function/Predicate.java
b/src/share/classes/java/util/function/Predicate.java
--- a/src/share/classes/java/util/function/Predicate.java
+++ b/src/share/classes/java/util/function/Predicate.java
@@ -43,7 +43,7 @@
* @return {@code true} if the input object matches some
criteria, otherwise
* {@code false}
*/
- public boolean test(T t);
+ boolean test(T t);
/**
* Returns a predicate which evaluates to {@code true} only if this
@@ -56,7 +56,7 @@
* predicates return {@code true}.
* @throws NullPointerException if p is null
*/
- public default Predicate<T> and(Predicate<? super T> p) {
+ default Predicate<T> and(Predicate<? super T> p) {
Objects.requireNonNull(p);
return (t) -> test(t) && p.test(t);
}
@@ -67,7 +67,7 @@
* @return a new predicate who's result is always the opposite of this
* predicate.
*/
- public default Predicate<T> negate() {
+ default Predicate<T> negate() {
return (t) -> !test(t);
}
@@ -82,7 +82,7 @@
* returns {@code true}.
* @throws NullPointerException if p is null
*/
- public default Predicate<T> or(Predicate<? super T> p) {
+ default Predicate<T> or(Predicate<? super T> p) {
Objects.requireNonNull(p);
return (t) -> test(t) || p.test(t);
}
==
More information about the lambda-dev
mailing list