Skip to content

Commit 002405a

Browse files
Merge pull request #1809 from benjchristensen/1797-utility-functions
Remove Utility Functions from Public API
2 parents 7aadeb9 + 56b9fea commit 002405a

12 files changed

+221
-199
lines changed

src/main/java/rx/Observable.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
*/
1313
package rx;
1414

15-
import static rx.functions.Functions.alwaysFalse;
16-
1715
import java.util.*;
1816
import java.util.concurrent.*;
1917

2018
import rx.exceptions.*;
2119
import rx.functions.*;
2220
import rx.internal.operators.*;
2321
import rx.internal.util.ScalarSynchronousObservable;
22+
import rx.internal.util.UtilityFunctions;
23+
2424
import rx.observables.*;
2525
import rx.observers.SafeSubscriber;
2626
import rx.plugins.*;
@@ -4030,7 +4030,7 @@ public final <T2> Observable<T2> dematerialize() {
40304030
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229764.aspx">MSDN: Observable.distinct</a>
40314031
*/
40324032
public final Observable<T> distinct() {
4033-
return lift(new OperatorDistinct<T, T>(Functions.<T>identity()));
4033+
return lift(new OperatorDistinct<T, T>(UtilityFunctions.<T>identity()));
40344034
}
40354035

40364036
/**
@@ -4070,7 +4070,7 @@ public final <U> Observable<T> distinct(Func1<? super T, ? extends U> keySelecto
40704070
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229494.aspx">MSDN: Observable.distinctUntilChanged</a>
40714071
*/
40724072
public final Observable<T> distinctUntilChanged() {
4073-
return lift(new OperatorDistinctUntilChanged<T, T>(Functions.<T>identity()));
4073+
return lift(new OperatorDistinctUntilChanged<T, T>(UtilityFunctions.<T>identity()));
40744074
}
40754075

40764076
/**
@@ -4854,7 +4854,7 @@ public final <T2, D1, D2, R> Observable<R> groupJoin(Observable<T2> right, Func1
48544854
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229242.aspx">MSDN: Observable.IgnoreElements</a>
48554855
*/
48564856
public final Observable<T> ignoreElements() {
4857-
return filter(alwaysFalse());
4857+
return filter(UtilityFunctions.alwaysFalse());
48584858
}
48594859

48604860
/**
@@ -4874,7 +4874,7 @@ public final Observable<T> ignoreElements() {
48744874
* @see <a href= "http://msdn.microsoft.com/en-us/library/hh229905.aspx">MSDN: Observable.Any</a>
48754875
*/
48764876
public final Observable<Boolean> isEmpty() {
4877-
return lift(new OperatorAny<T>(Functions.alwaysTrue(), true));
4877+
return lift(new OperatorAny<T>(UtilityFunctions.alwaysTrue(), true));
48784878
}
48794879

48804880
/**
@@ -8481,7 +8481,7 @@ public final Observable<List<T>> toList() {
84818481
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229137.aspx">MSDN: Observable.ToDictionary</a>
84828482
*/
84838483
public final <K> Observable<Map<K, T>> toMap(Func1<? super T, ? extends K> keySelector) {
8484-
return lift(new OperatorToMap<T, K, T>(keySelector, Functions.<T>identity()));
8484+
return lift(new OperatorToMap<T, K, T>(keySelector, UtilityFunctions.<T>identity()));
84858485
}
84868486

84878487
/**
@@ -8558,7 +8558,7 @@ public final <K, V> Observable<Map<K, V>> toMap(Func1<? super T, ? extends K> ke
85588558
* @see <a href="http://msdn.microsoft.com/en-us/library/hh212098.aspx">MSDN: Observable.ToLookup</a>
85598559
*/
85608560
public final <K> Observable<Map<K, Collection<T>>> toMultimap(Func1<? super T, ? extends K> keySelector) {
8561-
return lift(new OperatorToMultimap<T, K, T>(keySelector, Functions.<T>identity()));
8561+
return lift(new OperatorToMultimap<T, K, T>(keySelector, UtilityFunctions.<T>identity()));
85628562
}
85638563

85648564
/**

src/main/java/rx/functions/Functions.java

Lines changed: 14 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ private Functions() {
2121
}
2222

2323
/**
24-
* Converts a {@link Func0} to a {@link FuncN} to allow heterogeneous handling of functions with different
25-
* arities.
24+
* Converts a {@link Func0} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
2625
*
2726
* @param f
2827
* the {@code Func0} to convert
@@ -43,8 +42,7 @@ public R call(Object... args) {
4342
}
4443

4544
/**
46-
* Converts a {@link Func1} to a {@link FuncN} to allow heterogeneous handling of functions with different
47-
* arities.
45+
* Converts a {@link Func1} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
4846
*
4947
* @param f
5048
* the {@code Func1} to convert
@@ -66,8 +64,7 @@ public R call(Object... args) {
6664
}
6765

6866
/**
69-
* Converts a {@link Func2} to a {@link FuncN} to allow heterogeneous handling of functions with different
70-
* arities.
67+
* Converts a {@link Func2} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
7168
*
7269
* @param f
7370
* the {@code Func2} to convert
@@ -89,8 +86,7 @@ public R call(Object... args) {
8986
}
9087

9188
/**
92-
* Converts a {@link Func3} to a {@link FuncN} to allow heterogeneous handling of functions with different
93-
* arities.
89+
* Converts a {@link Func3} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
9490
*
9591
* @param f
9692
* the {@code Func3} to convert
@@ -112,8 +108,7 @@ public R call(Object... args) {
112108
}
113109

114110
/**
115-
* Converts a {@link Func4} to a {@link FuncN} to allow heterogeneous handling of functions with different
116-
* arities.
111+
* Converts a {@link Func4} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
117112
*
118113
* @param f
119114
* the {@code Func4} to convert
@@ -135,8 +130,7 @@ public R call(Object... args) {
135130
}
136131

137132
/**
138-
* Converts a {@link Func5} to a {@link FuncN} to allow heterogeneous handling of functions with different
139-
* arities.
133+
* Converts a {@link Func5} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
140134
*
141135
* @param f
142136
* the {@code Func5} to convert
@@ -158,8 +152,7 @@ public R call(Object... args) {
158152
}
159153

160154
/**
161-
* Converts a {@link Func6} to a {@link FuncN} to allow heterogeneous handling of functions with different
162-
* arities.
155+
* Converts a {@link Func6} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
163156
*
164157
* @param f
165158
* the {@code Func6} to convert
@@ -181,8 +174,7 @@ public R call(Object... args) {
181174
}
182175

183176
/**
184-
* Converts a {@link Func7} to a {@link FuncN} to allow heterogeneous handling of functions with different
185-
* arities.
177+
* Converts a {@link Func7} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
186178
*
187179
* @param f
188180
* the {@code Func7} to convert
@@ -204,8 +196,7 @@ public R call(Object... args) {
204196
}
205197

206198
/**
207-
* Converts a {@link Func8} to a {@link FuncN} to allow heterogeneous handling of functions with different
208-
* arities.
199+
* Converts a {@link Func8} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
209200
*
210201
* @param f
211202
* the {@code Func8} to convert
@@ -227,8 +218,7 @@ public R call(Object... args) {
227218
}
228219

229220
/**
230-
* Converts a {@link Func9} to a {@link FuncN} to allow heterogeneous handling of functions with different
231-
* arities.
221+
* Converts a {@link Func9} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
232222
*
233223
* @param f
234224
* the {@code Func9} to convert
@@ -250,8 +240,7 @@ public R call(Object... args) {
250240
}
251241

252242
/**
253-
* Converts an {@link Action0} to a {@link FuncN} to allow heterogeneous handling of functions with
254-
* different arities.
243+
* Converts an {@link Action0} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
255244
*
256245
* @param f
257246
* the {@code Action0} to convert
@@ -273,8 +262,7 @@ public Void call(Object... args) {
273262
}
274263

275264
/**
276-
* Converts an {@link Action1} to a {@link FuncN} to allow heterogeneous handling of functions with
277-
* different arities.
265+
* Converts an {@link Action1} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
278266
*
279267
* @param f
280268
* the {@code Action1} to convert
@@ -297,8 +285,7 @@ public Void call(Object... args) {
297285
}
298286

299287
/**
300-
* Converts an {@link Action2} to a {@link FuncN} to allow heterogeneous handling of functions with
301-
* different arities.
288+
* Converts an {@link Action2} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
302289
*
303290
* @param f
304291
* the {@code Action2} to convert
@@ -321,8 +308,7 @@ public Void call(Object... args) {
321308
}
322309

323310
/**
324-
* Converts an {@link Action3} to a {@link FuncN} to allow heterogeneous handling of functions with
325-
* different arities.
311+
* Converts an {@link Action3} to a {@link FuncN} to allow heterogeneous handling of functions with different arities.
326312
*
327313
* @param f
328314
* the {@code Action3} to convert
@@ -344,134 +330,4 @@ public Void call(Object... args) {
344330
};
345331
}
346332

347-
/**
348-
* Returns a function that always returns {@code true}.
349-
*
350-
* @return a {@link Func1} that accepts an Object and returns the Boolean {@code true}
351-
*/
352-
public static <T> Func1<? super T, Boolean> alwaysTrue() {
353-
return AlwaysTrue.INSTANCE;
354-
}
355-
356-
/**
357-
* Returns a function that always returns {@code false}.
358-
*
359-
* @return a {@link Func1} that accepts an Object and returns the Boolean {@code false}
360-
*/
361-
public static <T> Func1<? super T, Boolean> alwaysFalse() {
362-
return AlwaysFalse.INSTANCE;
363-
}
364-
365-
/**
366-
* Returns a function that always returns the Object it is passed.
367-
*
368-
* @return a {@link Func1} that accepts an Object and returns the same Object
369-
*/
370-
public static <T> Func1<T, T> identity() {
371-
return new Func1<T, T>() {
372-
@Override
373-
public T call(T o) {
374-
return o;
375-
}
376-
};
377-
}
378-
379-
private enum AlwaysTrue implements Func1<Object, Boolean> {
380-
INSTANCE;
381-
382-
@Override
383-
public Boolean call(Object o) {
384-
return true;
385-
}
386-
}
387-
388-
private enum AlwaysFalse implements Func1<Object, Boolean> {
389-
INSTANCE;
390-
391-
@Override
392-
public Boolean call(Object o) {
393-
return false;
394-
}
395-
}
396-
397-
/**
398-
* Returns a function that merely returns {@code null}, without side effects.
399-
*
400-
* @return a function that returns {@code null}
401-
*/
402-
@SuppressWarnings("unchecked")
403-
public static <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R> NullFunction<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R> returnNull() {
404-
return NULL_FUNCTION;
405-
}
406-
407-
@SuppressWarnings("rawtypes")
408-
private static final NullFunction NULL_FUNCTION = new NullFunction();
409-
410-
private static final class NullFunction<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R> implements
411-
Func0<R>,
412-
Func1<T0, R>,
413-
Func2<T0, T1, R>,
414-
Func3<T0, T1, T2, R>,
415-
Func4<T0, T1, T2, T3, R>,
416-
Func5<T0, T1, T2, T3, T4, R>,
417-
Func6<T0, T1, T2, T3, T4, T5, R>,
418-
Func7<T0, T1, T2, T3, T4, T5, T6, R>,
419-
Func8<T0, T1, T2, T3, T4, T5, T6, T7, R>,
420-
Func9<T0, T1, T2, T3, T4, T5, T6, T7, T8, R>,
421-
FuncN<R> {
422-
@Override
423-
public R call() {
424-
return null;
425-
}
426-
427-
@Override
428-
public R call(T0 t1) {
429-
return null;
430-
}
431-
432-
@Override
433-
public R call(T0 t1, T1 t2) {
434-
return null;
435-
}
436-
437-
@Override
438-
public R call(T0 t1, T1 t2, T2 t3) {
439-
return null;
440-
}
441-
442-
@Override
443-
public R call(T0 t1, T1 t2, T2 t3, T3 t4) {
444-
return null;
445-
}
446-
447-
@Override
448-
public R call(T0 t1, T1 t2, T2 t3, T3 t4, T4 t5) {
449-
return null;
450-
}
451-
452-
@Override
453-
public R call(T0 t1, T1 t2, T2 t3, T3 t4, T4 t5, T5 t6) {
454-
return null;
455-
}
456-
457-
@Override
458-
public R call(T0 t1, T1 t2, T2 t3, T3 t4, T4 t5, T5 t6, T6 t7) {
459-
return null;
460-
}
461-
462-
@Override
463-
public R call(T0 t1, T1 t2, T2 t3, T3 t4, T4 t5, T5 t6, T6 t7, T7 t8) {
464-
return null;
465-
}
466-
467-
@Override
468-
public R call(T0 t1, T1 t2, T2 t3, T3 t4, T4 t5, T5 t6, T6 t7, T7 t8, T8 t9) {
469-
return null;
470-
}
471-
472-
@Override
473-
public R call(Object... args) {
474-
return null;
475-
}
476-
}
477333
}

src/main/java/rx/internal/operators/OperatorSequenceEqual.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import rx.Observable;
2222
import rx.functions.Func1;
2323
import rx.functions.Func2;
24-
import rx.functions.Functions;
24+
import rx.internal.util.UtilityFunctions;
2525

2626
/**
2727
* Returns an {@link Observable} that emits a single {@code Boolean} value that indicates whether two source
@@ -84,6 +84,6 @@ public Boolean call(Object t1, Object t2) {
8484
return equality.call((T)t1, (T)t2);
8585
}
8686

87-
}).all(Functions.<Boolean> identity());
87+
}).all(UtilityFunctions.<Boolean> identity());
8888
}
8989
}

0 commit comments

Comments
 (0)