Skip to content

Commit 4d652ab

Browse files
Merge pull request #1747 from akarnokd/Cleanup_Utility_Classes
Cleanup: final and utility classes
2 parents 0f7890e + 0920f23 commit 4d652ab

25 files changed

+59
-25
lines changed

src/main/java/rx/Notification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229462.aspx">the Microsoft Rx equivalent</a>
2222
*/
23-
public class Notification<T> {
23+
public final class Notification<T> {
2424

2525
private final Kind kind;
2626
private final Throwable throwable;

src/main/java/rx/exceptions/Exceptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @warn javadoc class description missing
2323
*/
24-
public class Exceptions {
24+
public final class Exceptions {
2525
private Exceptions() {
2626

2727
}

src/main/java/rx/exceptions/OnErrorThrowable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* recover more information from an {@code OnErrorThrowable} than is found in a typical {@code Throwable}, such
2222
* as the item the {@code Observable} was trying to emit at the time the error was encountered.
2323
*/
24-
public class OnErrorThrowable extends RuntimeException {
24+
public final class OnErrorThrowable extends RuntimeException {
2525

2626
private static final long serialVersionUID = -569558213262703934L;
2727

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
package rx.functions;
1717

18-
public class Functions {
18+
public final class Functions {
19+
private Functions() {
20+
throw new IllegalStateException("No instances!");
21+
}
1922

2023
/**
2124
* Converts a {@link Func0} to a {@link FuncN} to allow heterogeneous handling of functions with different

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
* <img width="640" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.mostRecent.png" alt="">
3030
*/
3131
public final class BlockingOperatorMostRecent {
32-
32+
private BlockingOperatorMostRecent() {
33+
throw new IllegalStateException("No instances!");
34+
}
3335
/**
3436
* Returns an {@code Iterable} that always returns the item most recently emitted by the {@code Observable}.
3537
*
@@ -58,7 +60,7 @@ public Iterator<T> iterator() {
5860
};
5961
}
6062

61-
private static class MostRecentObserver<T> extends Subscriber<T> {
63+
private static final class MostRecentObserver<T> extends Subscriber<T> {
6264
final NotificationLite<T> nl = NotificationLite.instance();
6365
volatile Object value;
6466

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
* <img width="640" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.next.png" alt="">
3434
*/
3535
public final class BlockingOperatorNext {
36+
private BlockingOperatorNext() {
37+
throw new IllegalStateException("No instances!");
38+
}
3639

3740
/**
3841
* Returns an {@code Iterable} that blocks until the {@code Observable} emits another item, then returns

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
* The toFuture operation throws an exception if the Observable emits more than one item. If the
3636
* Observable may emit more than item, use <code>toList().toFuture()</code>.
3737
*/
38-
public class BlockingOperatorToFuture {
39-
38+
public final class BlockingOperatorToFuture {
39+
private BlockingOperatorToFuture() {
40+
throw new IllegalStateException("No instances!");
41+
}
4042
/**
4143
* Returns a Future that expects a single item from the observable.
4244
*

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
*
3535
* @see <a href="https://github.com/ReactiveX/RxJava/issues/50">Issue #50</a>
3636
*/
37-
public class BlockingOperatorToIterator {
37+
public final class BlockingOperatorToIterator {
38+
private BlockingOperatorToIterator() {
39+
throw new IllegalStateException("No instances!");
40+
}
3841

3942
/**
4043
* Returns an iterator that iterates all values of the observable.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @param <T>
4949
* the type of the items to be buffered
5050
*/
51-
public class BufferUntilSubscriber<T> extends Subject<T, T> {
51+
public final class BufferUntilSubscriber<T> extends Subject<T, T> {
5252

5353
/**
5454
* @warn create() undescribed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
* This is blocking so the {@code Subscription} returned when calling
3535
* {@code Observable.unsafeSubscribe(Observer)} does nothing.
3636
*/
37-
public class OnSubscribeToObservableFuture {
37+
public final class OnSubscribeToObservableFuture {
38+
private OnSubscribeToObservableFuture() {
39+
throw new IllegalStateException("No instances!");
40+
}
41+
3842
/* package accessible for unit tests */static class ToObservableFuture<T> implements OnSubscribe<T> {
3943
private final Future<? extends T> that;
4044
private final long time;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Subscriber<? super T> call(Subscriber<? super T> subscriber) {
7777
return timeoutSubscriber;
7878
}
7979

80-
/* package-private */static class TimeoutSubscriber<T> extends
80+
/* package-private */static final class TimeoutSubscriber<T> extends
8181
Subscriber<T> {
8282

8383
private final SerialSubscription serial;

src/main/java/rx/internal/util/IndexedRingBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* @param <E>
4848
*/
49-
public class IndexedRingBuffer<E> implements Subscription {
49+
public final class IndexedRingBuffer<E> implements Subscription {
5050

5151
private static final ObjectPool<IndexedRingBuffer> POOL = new ObjectPool<IndexedRingBuffer>() {
5252

src/main/java/rx/internal/util/unsafe/Pow2.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
package rx.internal.util.unsafe;
1818

19-
public class Pow2 {
19+
public final class Pow2 {
20+
private Pow2() {
21+
throw new IllegalStateException("No instances!");
22+
}
2023

2124
/**
2225
* Find the next larger positive power of two value up from the given value. If value is a power of two then

src/main/java/rx/internal/util/unsafe/UnsafeAccess.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* otherwise NPEs will happen in environments without "suc.misc.Unsafe" such as Android.
2525
*/
2626
public final class UnsafeAccess {
27+
private UnsafeAccess() {
28+
throw new IllegalStateException("No instances!");
29+
}
2730

2831
public static final Unsafe UNSAFE;
2932
static {

src/main/java/rx/observables/BlockingObservable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* @param <T>
5151
* the type of item emitted by the {@code BlockingObservable}
5252
*/
53-
public class BlockingObservable<T> {
53+
public final class BlockingObservable<T> {
5454

5555
private final Observable<? extends T> o;
5656

src/main/java/rx/observers/Observers.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
/**
2424
* Helper methods and utilities for creating and working with {@link Observer} objects.
2525
*/
26-
public class Observers {
26+
public final class Observers {
27+
private Observers() {
28+
throw new IllegalStateException("No instances!");
29+
}
2730

2831
private static final Observer<Object> EMPTY = new Observer<Object>() {
2932

src/main/java/rx/schedulers/NewThreadScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Schedules work on a new thread.
2424
*/
25-
public class NewThreadScheduler extends Scheduler {
25+
public final class NewThreadScheduler extends Scheduler {
2626

2727
private static final String THREAD_NAME_PREFIX = "RxNewThreadScheduler-";
2828
private static final RxThreadFactory THREAD_FACTORY = new RxThreadFactory(THREAD_NAME_PREFIX);

src/main/java/rx/schedulers/TestScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class TestScheduler extends Scheduler {
3434
private final Queue<TimedAction> queue = new PriorityQueue<TimedAction>(11, new CompareActionsByTime());
3535
private static long counter = 0;
3636

37-
private static class TimedAction {
37+
private static final class TimedAction {
3838

3939
private final long time;
4040
private final Action0 action;

src/main/java/rx/schedulers/TrampolineScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public boolean isUnsubscribed() {
110110

111111
}
112112

113-
private static class TimedAction implements Comparable<TimedAction> {
113+
private static final class TimedAction implements Comparable<TimedAction> {
114114
final Action0 action;
115115
final Long execTime;
116116
final int count; // In case if time between enqueueing took less than 1ms

src/main/java/rx/subscriptions/Subscriptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* Helper methods and utilities for creating and working with {@link Subscription} objects
2727
*/
2828
public final class Subscriptions {
29+
private Subscriptions() {
30+
throw new IllegalStateException("No instances!");
31+
}
2932
/**
3033
* Returns a {@link Subscription} that does nothing.
3134
*

src/test/java/rx/EventStream.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
/**
2828
* Utility for retrieving a mock eventstream for testing.
2929
*/
30-
public class EventStream {
31-
30+
public final class EventStream {
31+
private EventStream() {
32+
throw new IllegalStateException("No instances!");
33+
}
3234
public static Observable<Event> getEventStream(final String type, final int numInstances) {
3335
return Observable.create(new OnSubscribe<Event>() {
3436

src/test/java/rx/exceptions/OnNextValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* There is an added danger that if there is a bug in the toString method it will cause inconsistent exception creation. If the object throws an exception while rendering a string it will actually end up not seeing the real exception.
2626
*/
2727
public final class OnNextValueTest {
28-
private static class BadToString {
28+
private static final class BadToString {
2929

3030
private final boolean throwDuringToString;
3131

src/test/java/rx/internal/operators/OperatorSubscribeOnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Worker createWorker() {
133133
return new SlowInner(actual.createWorker());
134134
}
135135

136-
private class SlowInner extends Worker {
136+
private final class SlowInner extends Worker {
137137

138138
private final Scheduler.Worker actualInner;
139139

src/test/java/rx/test/OperatorTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Common utility functions for testing operator implementations.
2222
*/
23-
public class OperatorTester {
23+
public final class OperatorTester {
2424
/*
2525
* This is purposefully package-only so it does not leak into the public API outside of this package.
2626
*

src/test/java/rx/util/AssertObservable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import rx.functions.Func1;
2121
import rx.functions.Func2;
2222

23-
public class AssertObservable {
23+
public final class AssertObservable {
24+
private AssertObservable() {
25+
throw new IllegalStateException("No instances!");
26+
}
2427
/**
2528
* Asserts that two Observables are equal. If they are not, an {@link AssertionError} is thrown
2629
* with the given message. If <code>expecteds</code> and <code>actuals</code> are

0 commit comments

Comments
 (0)