Skip to content

Commit

Permalink
Annotate function interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycosentini committed Jan 27, 2017
1 parent f53e029 commit e588d36
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 12 deletions.
30 changes: 30 additions & 0 deletions src/main/java/io/reactivex/annotations/NonNull.java
Original file line number Diff line number Diff line change
@@ -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 { }

4 changes: 3 additions & 1 deletion src/main/java/io/reactivex/functions/BiConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -26,5 +28,5 @@ public interface BiConsumer<T1, T2> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/BiFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -28,5 +30,6 @@ public interface BiFunction<T1, T2, R> {
* @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;
}
4 changes: 3 additions & 1 deletion src/main/java/io/reactivex/functions/BiPredicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value
Expand All @@ -27,5 +29,5 @@ public interface BiPredicate<T1, T2> {
* @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;
}
4 changes: 3 additions & 1 deletion src/main/java/io/reactivex/functions/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package io.reactivex.functions;

import io.reactivex.annotations.NonNull;

/**
* A functional interface (callback) that accepts a single value.
* @param <T> the value type
Expand All @@ -23,5 +25,5 @@ public interface Consumer<T> {
* @param t the value
* @throws Exception on error
*/
void accept(T t) throws Exception;
void accept(@NonNull T t) throws Exception;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,5 +29,6 @@ public interface Function<T, R> {
* @return the output value
* @throws Exception on error
*/
R apply(T t) throws Exception;
@NonNull
R apply(@NonNull T t) throws Exception;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -29,5 +31,6 @@ public interface Function3<T1, T2, T3, R> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function4.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -31,5 +33,6 @@ public interface Function4<T1, T2, T3, T4, R> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function5.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -33,5 +35,6 @@ public interface Function5<T1, T2, T3, T4, T5, R> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function6.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -35,5 +37,6 @@ public interface Function6<T1, T2, T3, T4, T5, T6, R> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function8.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand All @@ -39,5 +41,6 @@ public interface Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> {
* @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;
}
5 changes: 4 additions & 1 deletion src/main/java/io/reactivex/functions/Function9.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T1> the first value type
Expand Down Expand Up @@ -41,5 +43,6 @@ public interface Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> {
* @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;
}
3 changes: 3 additions & 0 deletions src/main/java/io/reactivex/functions/IntFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> the returned value type
Expand All @@ -23,5 +25,6 @@ public interface IntFunction<T> {
* @return the result Object
* @throws Exception on error
*/
@NonNull
T apply(int i) throws Exception;
}
4 changes: 3 additions & 1 deletion src/main/java/io/reactivex/functions/Predicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> the first value
Expand All @@ -24,5 +26,5 @@ public interface Predicate<T> {
* @return the boolean result
* @throws Exception on error
*/
boolean test(T t) throws Exception;
boolean test(@NonNull T t) throws Exception;
}

0 comments on commit e588d36

Please sign in to comment.