From e588d366714666284a510bec1cd6a208f1041633 Mon Sep 17 00:00:00 2001 From: Tony Cosentini Date: Wed, 25 Jan 2017 23:08:41 -0800 Subject: [PATCH] Annotate function interfaces. --- .../io/reactivex/annotations/NonNull.java | 30 +++++++++++++++++++ .../io/reactivex/functions/BiConsumer.java | 4 ++- .../io/reactivex/functions/BiFunction.java | 5 +++- .../io/reactivex/functions/BiPredicate.java | 4 ++- .../java/io/reactivex/functions/Consumer.java | 4 ++- .../java/io/reactivex/functions/Function.java | 5 +++- .../io/reactivex/functions/Function3.java | 5 +++- .../io/reactivex/functions/Function4.java | 5 +++- .../io/reactivex/functions/Function5.java | 5 +++- .../io/reactivex/functions/Function6.java | 5 +++- .../io/reactivex/functions/Function8.java | 5 +++- .../io/reactivex/functions/Function9.java | 5 +++- .../io/reactivex/functions/IntFunction.java | 3 ++ .../io/reactivex/functions/Predicate.java | 4 ++- 14 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 src/main/java/io/reactivex/annotations/NonNull.java diff --git a/src/main/java/io/reactivex/annotations/NonNull.java b/src/main/java/io/reactivex/annotations/NonNull.java new file mode 100644 index 0000000000..19a2370007 --- /dev/null +++ b/src/main/java/io/reactivex/annotations/NonNull.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.LOCAL_VARIABLE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Documented +@Target(value = {FIELD, METHOD, PARAMETER, LOCAL_VARIABLE}) +@Retention(value = CLASS) +public @interface NonNull { } + diff --git a/src/main/java/io/reactivex/functions/BiConsumer.java b/src/main/java/io/reactivex/functions/BiConsumer.java index 6b147ae0b0..bd382a1956 100644 --- a/src/main/java/io/reactivex/functions/BiConsumer.java +++ b/src/main/java/io/reactivex/functions/BiConsumer.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that accepts two values (of possibly different types). * @param the first value type @@ -26,5 +28,5 @@ public interface BiConsumer { * @param t2 the second value * @throws Exception on error */ - void accept(T1 t1, T2 t2) throws Exception; + void accept(@NonNull T1 t1, @NonNull T2 t2) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/BiFunction.java b/src/main/java/io/reactivex/functions/BiFunction.java index fd442bf970..f67a03bdb8 100644 --- a/src/main/java/io/reactivex/functions/BiFunction.java +++ b/src/main/java/io/reactivex/functions/BiFunction.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -28,5 +30,6 @@ public interface BiFunction { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/BiPredicate.java b/src/main/java/io/reactivex/functions/BiPredicate.java index d1c2ca979c..390e1640ec 100644 --- a/src/main/java/io/reactivex/functions/BiPredicate.java +++ b/src/main/java/io/reactivex/functions/BiPredicate.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that returns true or false for the given input values. * @param the first value @@ -27,5 +29,5 @@ public interface BiPredicate { * @return the boolean result * @throws Exception on error */ - boolean test(T1 t1, T2 t2) throws Exception; + boolean test(@NonNull T1 t1, @NonNull T2 t2) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Consumer.java b/src/main/java/io/reactivex/functions/Consumer.java index ff10bbb244..deb4ae8047 100644 --- a/src/main/java/io/reactivex/functions/Consumer.java +++ b/src/main/java/io/reactivex/functions/Consumer.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that accepts a single value. * @param the value type @@ -23,5 +25,5 @@ public interface Consumer { * @param t the value * @throws Exception on error */ - void accept(T t) throws Exception; + void accept(@NonNull T t) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function.java b/src/main/java/io/reactivex/functions/Function.java index 81753aca61..2aece7dc1b 100644 --- a/src/main/java/io/reactivex/functions/Function.java +++ b/src/main/java/io/reactivex/functions/Function.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface that takes a value and returns another value, possibly with a * different type and allows throwing a checked exception. @@ -27,5 +29,6 @@ public interface Function { * @return the output value * @throws Exception on error */ - R apply(T t) throws Exception; + @NonNull + R apply(@NonNull T t) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function3.java b/src/main/java/io/reactivex/functions/Function3.java index cebb0d518a..2f4836c763 100644 --- a/src/main/java/io/reactivex/functions/Function3.java +++ b/src/main/java/io/reactivex/functions/Function3.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -29,5 +31,6 @@ public interface Function3 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function4.java b/src/main/java/io/reactivex/functions/Function4.java index 9a48c4cadf..3db600d9d4 100644 --- a/src/main/java/io/reactivex/functions/Function4.java +++ b/src/main/java/io/reactivex/functions/Function4.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -31,5 +33,6 @@ public interface Function4 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3, T4 t4) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function5.java b/src/main/java/io/reactivex/functions/Function5.java index 56f43b3dbc..bcdaac3721 100644 --- a/src/main/java/io/reactivex/functions/Function5.java +++ b/src/main/java/io/reactivex/functions/Function5.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -33,5 +35,6 @@ public interface Function5 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function6.java b/src/main/java/io/reactivex/functions/Function6.java index b7abf46a45..29d7ceb34a 100644 --- a/src/main/java/io/reactivex/functions/Function6.java +++ b/src/main/java/io/reactivex/functions/Function6.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -35,5 +37,6 @@ public interface Function6 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5, @NonNull T6 t6) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function8.java b/src/main/java/io/reactivex/functions/Function8.java index 5ba6d54b94..5374d27968 100644 --- a/src/main/java/io/reactivex/functions/Function8.java +++ b/src/main/java/io/reactivex/functions/Function8.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -39,5 +41,6 @@ public interface Function8 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5, @NonNull T6 t6, @NonNull T7 t7, @NonNull T8 t8) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Function9.java b/src/main/java/io/reactivex/functions/Function9.java index eb81a58dba..29c5605b74 100644 --- a/src/main/java/io/reactivex/functions/Function9.java +++ b/src/main/java/io/reactivex/functions/Function9.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that computes a value based on multiple input values. * @param the first value type @@ -41,5 +43,6 @@ public interface Function9 { * @return the result value * @throws Exception on error */ - R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) throws Exception; + @NonNull + R apply(@NonNull T1 t1, @NonNull T2 t2, @NonNull T3 t3, @NonNull T4 t4, @NonNull T5 t5, @NonNull T6 t6, @NonNull T7 t7, @NonNull T8 t8, @NonNull T9 t9) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/IntFunction.java b/src/main/java/io/reactivex/functions/IntFunction.java index c0606aa099..aef60e1bd7 100644 --- a/src/main/java/io/reactivex/functions/IntFunction.java +++ b/src/main/java/io/reactivex/functions/IntFunction.java @@ -12,6 +12,8 @@ */ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that takes a primitive value and return value of type T. * @param the returned value type @@ -23,5 +25,6 @@ public interface IntFunction { * @return the result Object * @throws Exception on error */ + @NonNull T apply(int i) throws Exception; } diff --git a/src/main/java/io/reactivex/functions/Predicate.java b/src/main/java/io/reactivex/functions/Predicate.java index 3d2dea1a68..17bc3cff63 100644 --- a/src/main/java/io/reactivex/functions/Predicate.java +++ b/src/main/java/io/reactivex/functions/Predicate.java @@ -13,6 +13,8 @@ package io.reactivex.functions; +import io.reactivex.annotations.NonNull; + /** * A functional interface (callback) that returns true or false for the given input value. * @param the first value @@ -24,5 +26,5 @@ public interface Predicate { * @return the boolean result * @throws Exception on error */ - boolean test(T t) throws Exception; + boolean test(@NonNull T t) throws Exception; }