Skip to content

Commit 40087e9

Browse files
authored
3.x: remove getValues() from some subjects/processors (#6516)
1 parent a672013 commit 40087e9

File tree

6 files changed

+6
-279
lines changed

6 files changed

+6
-279
lines changed

Diff for: src/main/java/io/reactivex/processors/AsyncProcessor.java

+1-42
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
package io.reactivex.processors;
1414

15-
import java.util.Arrays;
1615
import java.util.concurrent.atomic.AtomicReference;
1716

1817
import org.reactivestreams.*;
@@ -63,7 +62,7 @@
6362
* This {@code AsyncProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()},
6463
* {@link #getThrowable()} and {@link #hasSubscribers()} as well as means to read the very last observed value -
6564
* after this {@code AsyncProcessor} has been completed - in a non-blocking and thread-safe
66-
* manner via {@link #hasValue()}, {@link #getValue()}, {@link #getValues()} or {@link #getValues(Object[])}.
65+
* manner via {@link #hasValue()} or {@link #getValue()}.
6766
* <dl>
6867
* <dt><b>Backpressure:</b></dt>
6968
* <dd>The {@code AsyncProcessor} honors the backpressure of the downstream {@code Subscriber}s and won't emit
@@ -331,46 +330,6 @@ public T getValue() {
331330
return subscribers.get() == TERMINATED ? value : null;
332331
}
333332

334-
/**
335-
* Returns an Object array containing snapshot all values of this processor.
336-
* <p>The method is thread-safe.
337-
* @return the array containing the snapshot of all values of this processor
338-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
339-
*/
340-
@Deprecated
341-
public Object[] getValues() {
342-
T v = getValue();
343-
return v != null ? new Object[] { v } : new Object[0];
344-
}
345-
346-
/**
347-
* Returns a typed array containing a snapshot of all values of this processor.
348-
* <p>The method follows the conventions of Collection.toArray by setting the array element
349-
* after the last value to null (if the capacity permits).
350-
* <p>The method is thread-safe.
351-
* @param array the target array to copy values into if it fits
352-
* @return the given array if the values fit into it or a new array containing all values
353-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
354-
*/
355-
@Deprecated
356-
public T[] getValues(T[] array) {
357-
T v = getValue();
358-
if (v == null) {
359-
if (array.length != 0) {
360-
array[0] = null;
361-
}
362-
return array;
363-
}
364-
if (array.length == 0) {
365-
array = Arrays.copyOf(array, 1);
366-
}
367-
array[0] = v;
368-
if (array.length != 1) {
369-
array[1] = null;
370-
}
371-
return array;
372-
}
373-
374333
static final class AsyncSubscription<T> extends DeferredScalarSubscription<T> {
375334
private static final long serialVersionUID = 5629876084736248016L;
376335

Diff for: src/main/java/io/reactivex/processors/BehaviorProcessor.java

+1-53
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package io.reactivex.processors;
1515

16-
import java.lang.reflect.Array;
1716
import java.util.concurrent.atomic.*;
1817
import java.util.concurrent.locks.*;
1918

@@ -95,8 +94,7 @@
9594
* <p>
9695
* This {@code BehaviorProcessor} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()},
9796
* {@link #getThrowable()} and {@link #hasSubscribers()} as well as means to read the latest observed value
98-
* in a non-blocking and thread-safe manner via {@link #hasValue()}, {@link #getValue()},
99-
* {@link #getValues()} or {@link #getValues(Object[])}.
97+
* in a non-blocking and thread-safe manner via {@link #hasValue()} or {@link #getValue()}.
10098
* <p>
10199
* Note that this processor signals {@code MissingBackpressureException} if a particular {@code Subscriber} is not
102100
* ready to receive {@code onNext} events. To avoid this exception being signaled, use {@link #offer(Object)} to only
@@ -374,56 +372,6 @@ public T getValue() {
374372
return NotificationLite.getValue(o);
375373
}
376374

377-
/**
378-
* Returns an Object array containing snapshot all values of the BehaviorProcessor.
379-
* <p>The method is thread-safe.
380-
* @return the array containing the snapshot of all values of the BehaviorProcessor
381-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
382-
*/
383-
@Deprecated
384-
public Object[] getValues() {
385-
@SuppressWarnings("unchecked")
386-
T[] a = (T[])EMPTY_ARRAY;
387-
T[] b = getValues(a);
388-
if (b == EMPTY_ARRAY) {
389-
return new Object[0];
390-
}
391-
return b;
392-
393-
}
394-
395-
/**
396-
* Returns a typed array containing a snapshot of all values of the BehaviorProcessor.
397-
* <p>The method follows the conventions of Collection.toArray by setting the array element
398-
* after the last value to null (if the capacity permits).
399-
* <p>The method is thread-safe.
400-
* @param array the target array to copy values into if it fits
401-
* @return the given array if the values fit into it or a new array containing all values
402-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
403-
*/
404-
@Deprecated
405-
@SuppressWarnings("unchecked")
406-
public T[] getValues(T[] array) {
407-
Object o = value.get();
408-
if (o == null || NotificationLite.isComplete(o) || NotificationLite.isError(o)) {
409-
if (array.length != 0) {
410-
array[0] = null;
411-
}
412-
return array;
413-
}
414-
T v = NotificationLite.getValue(o);
415-
if (array.length != 0) {
416-
array[0] = v;
417-
if (array.length != 1) {
418-
array[1] = null;
419-
}
420-
} else {
421-
array = (T[])Array.newInstance(array.getClass().getComponentType(), 1);
422-
array[0] = v;
423-
}
424-
return array;
425-
}
426-
427375
@Override
428376
public boolean hasComplete() {
429377
Object o = value.get();

Diff for: src/main/java/io/reactivex/subjects/AsyncSubject.java

+2-45
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313

1414
package io.reactivex.subjects;
1515

16-
import io.reactivex.annotations.Nullable;
17-
import io.reactivex.annotations.NonNull;
18-
import java.util.Arrays;
1916
import java.util.concurrent.atomic.AtomicReference;
2017

2118
import io.reactivex.Observer;
22-
import io.reactivex.annotations.CheckReturnValue;
19+
import io.reactivex.annotations.*;
2320
import io.reactivex.disposables.Disposable;
2421
import io.reactivex.internal.functions.ObjectHelper;
2522
import io.reactivex.internal.observers.DeferredScalarDisposable;
@@ -64,7 +61,7 @@
6461
* This {@code AsyncSubject} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()},
6562
* {@link #getThrowable()} and {@link #hasObservers()} as well as means to read the very last observed value -
6663
* after this {@code AsyncSubject} has been completed - in a non-blocking and thread-safe
67-
* manner via {@link #hasValue()}, {@link #getValue()}, {@link #getValues()} or {@link #getValues(Object[])}.
64+
* manner via {@link #hasValue()} or {@link #getValue()}.
6865
* <dl>
6966
* <dt><b>Scheduler:</b></dt>
7067
* <dd>{@code AsyncSubject} does not operate by default on a particular {@link io.reactivex.Scheduler} and
@@ -321,46 +318,6 @@ public T getValue() {
321318
return subscribers.get() == TERMINATED ? value : null;
322319
}
323320

324-
/**
325-
* Returns an Object array containing snapshot all values of the Subject.
326-
* <p>The method is thread-safe.
327-
* @return the array containing the snapshot of all values of the Subject
328-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
329-
*/
330-
@Deprecated
331-
public Object[] getValues() {
332-
T v = getValue();
333-
return v != null ? new Object[] { v } : new Object[0];
334-
}
335-
336-
/**
337-
* Returns a typed array containing a snapshot of all values of the Subject.
338-
* <p>The method follows the conventions of Collection.toArray by setting the array element
339-
* after the last value to null (if the capacity permits).
340-
* <p>The method is thread-safe.
341-
* @param array the target array to copy values into if it fits
342-
* @return the given array if the values fit into it or a new array containing all values
343-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
344-
*/
345-
@Deprecated
346-
public T[] getValues(T[] array) {
347-
T v = getValue();
348-
if (v == null) {
349-
if (array.length != 0) {
350-
array[0] = null;
351-
}
352-
return array;
353-
}
354-
if (array.length == 0) {
355-
array = Arrays.copyOf(array, 1);
356-
}
357-
array[0] = v;
358-
if (array.length != 1) {
359-
array[1] = null;
360-
}
361-
return array;
362-
}
363-
364321
static final class AsyncDisposable<T> extends DeferredScalarDisposable<T> {
365322
private static final long serialVersionUID = 5629876084736248016L;
366323

Diff for: src/main/java/io/reactivex/subjects/BehaviorSubject.java

+2-59
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313

1414
package io.reactivex.subjects;
1515

16-
import io.reactivex.annotations.CheckReturnValue;
17-
import io.reactivex.annotations.Nullable;
18-
import io.reactivex.annotations.NonNull;
19-
import java.lang.reflect.Array;
2016
import java.util.concurrent.atomic.AtomicReference;
2117
import java.util.concurrent.locks.*;
2218

2319
import io.reactivex.Observer;
20+
import io.reactivex.annotations.*;
2421
import io.reactivex.disposables.Disposable;
2522
import io.reactivex.internal.functions.ObjectHelper;
2623
import io.reactivex.internal.util.*;
@@ -97,8 +94,7 @@
9794
* <p>
9895
* This {@code BehaviorSubject} supports the standard state-peeking methods {@link #hasComplete()}, {@link #hasThrowable()},
9996
* {@link #getThrowable()} and {@link #hasObservers()} as well as means to read the latest observed value
100-
* in a non-blocking and thread-safe manner via {@link #hasValue()}, {@link #getValue()},
101-
* {@link #getValues()} or {@link #getValues(Object[])}.
97+
* in a non-blocking and thread-safe manner via {@link #hasValue()} or {@link #getValue()}.
10298
* <dl>
10399
* <dt><b>Scheduler:</b></dt>
104100
* <dd>{@code BehaviorSubject} does not operate by default on a particular {@link io.reactivex.Scheduler} and
@@ -153,9 +149,6 @@
153149
*/
154150
public final class BehaviorSubject<T> extends Subject<T> {
155151

156-
/** An empty array to avoid allocation in getValues(). */
157-
private static final Object[] EMPTY_ARRAY = new Object[0];
158-
159152
final AtomicReference<Object> value;
160153

161154
final AtomicReference<BehaviorDisposable<T>[]> subscribers;
@@ -326,56 +319,6 @@ public T getValue() {
326319
return NotificationLite.getValue(o);
327320
}
328321

329-
/**
330-
* Returns an Object array containing snapshot all values of the Subject.
331-
* <p>The method is thread-safe.
332-
* @return the array containing the snapshot of all values of the Subject
333-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
334-
*/
335-
@Deprecated
336-
public Object[] getValues() {
337-
@SuppressWarnings("unchecked")
338-
T[] a = (T[])EMPTY_ARRAY;
339-
T[] b = getValues(a);
340-
if (b == EMPTY_ARRAY) {
341-
return new Object[0];
342-
}
343-
return b;
344-
345-
}
346-
347-
/**
348-
* Returns a typed array containing a snapshot of all values of the Subject.
349-
* <p>The method follows the conventions of Collection.toArray by setting the array element
350-
* after the last value to null (if the capacity permits).
351-
* <p>The method is thread-safe.
352-
* @param array the target array to copy values into if it fits
353-
* @return the given array if the values fit into it or a new array containing all values
354-
* @deprecated in 2.1.14; put the result of {@link #getValue()} into an array manually, will be removed in 3.x
355-
*/
356-
@Deprecated
357-
@SuppressWarnings("unchecked")
358-
public T[] getValues(T[] array) {
359-
Object o = value.get();
360-
if (o == null || NotificationLite.isComplete(o) || NotificationLite.isError(o)) {
361-
if (array.length != 0) {
362-
array[0] = null;
363-
}
364-
return array;
365-
}
366-
T v = NotificationLite.getValue(o);
367-
if (array.length != 0) {
368-
array[0] = v;
369-
if (array.length != 1) {
370-
array[1] = null;
371-
}
372-
} else {
373-
array = (T[])Array.newInstance(array.getClass().getComponentType(), 1);
374-
array[0] = v;
375-
}
376-
return array;
377-
}
378-
379322
@Override
380323
public boolean hasComplete() {
381324
Object o = value.get();

0 commit comments

Comments
 (0)