Skip to content

Commit a9cd938

Browse files
committed
Merge pull request ReactiveX#2864 from davidmoten/main-warnings
IndexedRingBuffer.getInstance can infer type
2 parents d53c1be + bfad7ea commit a9cd938

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@
4848
*/
4949
public final class IndexedRingBuffer<E> implements Subscription {
5050

51-
private static final ObjectPool<IndexedRingBuffer> POOL = new ObjectPool<IndexedRingBuffer>() {
51+
private static final ObjectPool<IndexedRingBuffer<?>> POOL = new ObjectPool<IndexedRingBuffer<?>>() {
5252

5353
@Override
54-
protected IndexedRingBuffer createObject() {
55-
return new IndexedRingBuffer();
54+
protected IndexedRingBuffer<?> createObject() {
55+
return new IndexedRingBuffer<Object>();
5656
}
5757

5858
};
5959

60-
public final static IndexedRingBuffer getInstance() {
61-
return POOL.borrowObject();
60+
@SuppressWarnings("unchecked")
61+
public final static <T> IndexedRingBuffer<T> getInstance() {
62+
return (IndexedRingBuffer<T>) POOL.borrowObject();
6263
}
6364

6465
private final ElementSection<E> elements = new ElementSection<E>();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
public final class SubscriptionIndexedRingBuffer<T extends Subscription> implements Subscription {
2929

30-
@SuppressWarnings("unchecked")
3130
private volatile IndexedRingBuffer<T> subscriptions = IndexedRingBuffer.getInstance();
3231
private volatile int unsubscribed = 0;
3332
@SuppressWarnings("rawtypes")

src/perf/java/rx/internal/IndexedRingBufferPerf.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class IndexedRingBufferPerf {
2929

3030
@Benchmark
3131
public void indexedRingBufferAdd(IndexedRingBufferInput input) throws InterruptedException, MissingBackpressureException {
32-
@SuppressWarnings("unchecked")
3332
IndexedRingBuffer<Integer> list = IndexedRingBuffer.getInstance();
3433
for (int i = 0; i < input.size; i++) {
3534
list.add(i);
@@ -40,7 +39,6 @@ public void indexedRingBufferAdd(IndexedRingBufferInput input) throws Interrupte
4039

4140
@Benchmark
4241
public void indexedRingBufferAddRemove(IndexedRingBufferInput input) throws InterruptedException, MissingBackpressureException {
43-
@SuppressWarnings("unchecked")
4442
IndexedRingBuffer<Integer> list = IndexedRingBuffer.getInstance();
4543
for (int i = 0; i < input.size; i++) {
4644
list.add(i);

src/test/java/rx/internal/util/IndexedRingBufferTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class IndexedRingBufferTest {
3737

3838
@Test
3939
public void add() {
40-
@SuppressWarnings("unchecked")
4140
IndexedRingBuffer<LSubscription> list = IndexedRingBuffer.getInstance();
4241
list.add(new LSubscription(1));
4342
list.add(new LSubscription(2));
@@ -49,7 +48,6 @@ public void add() {
4948

5049
@Test
5150
public void removeEnd() {
52-
@SuppressWarnings("unchecked")
5351
IndexedRingBuffer<LSubscription> list = IndexedRingBuffer.getInstance();
5452
list.add(new LSubscription(1));
5553
int n2 = list.add(new LSubscription(2));
@@ -67,7 +65,6 @@ public void removeEnd() {
6765

6866
@Test
6967
public void removeMiddle() {
70-
@SuppressWarnings("unchecked")
7168
IndexedRingBuffer<LSubscription> list = IndexedRingBuffer.getInstance();
7269
list.add(new LSubscription(1));
7370
int n2 = list.add(new LSubscription(2));
@@ -82,7 +79,6 @@ public void removeMiddle() {
8279

8380
@Test
8481
public void addRemoveAdd() {
85-
@SuppressWarnings("unchecked")
8682
IndexedRingBuffer<String> list = IndexedRingBuffer.getInstance();
8783
list.add("one");
8884
list.add("two");
@@ -119,7 +115,6 @@ public void addRemoveAdd() {
119115
@Test
120116
public void addThousands() {
121117
String s = "s";
122-
@SuppressWarnings("unchecked")
123118
IndexedRingBuffer<String> list = IndexedRingBuffer.getInstance();
124119
for (int i = 0; i < 10000; i++) {
125120
list.add(s);
@@ -145,7 +140,6 @@ public void addThousands() {
145140

146141
@Test
147142
public void testForEachWithIndex() {
148-
@SuppressWarnings("unchecked")
149143
IndexedRingBuffer<String> buffer = IndexedRingBuffer.getInstance();
150144
buffer.add("zero");
151145
buffer.add("one");
@@ -212,7 +206,6 @@ public Boolean call(String t1) {
212206

213207
@Test
214208
public void testForEachAcrossSections() {
215-
@SuppressWarnings("unchecked")
216209
IndexedRingBuffer<Integer> buffer = IndexedRingBuffer.getInstance();
217210
for (int i = 0; i < 10000; i++) {
218211
buffer.add(i);
@@ -231,7 +224,6 @@ public void testForEachAcrossSections() {
231224
@Test
232225
public void longRunningAddRemoveAddDoesntLeakMemory() {
233226
String s = "s";
234-
@SuppressWarnings("unchecked")
235227
IndexedRingBuffer<String> list = IndexedRingBuffer.getInstance();
236228
for (int i = 0; i < 20000; i++) {
237229
int index = list.add(s);
@@ -242,14 +234,13 @@ public void longRunningAddRemoveAddDoesntLeakMemory() {
242234
list.forEach(newCounterAction(c));
243235
assertEquals(0, c.get());
244236
// System.out.println("Index is: " + list.index.get() + " when it should be no bigger than " + list.SIZE);
245-
assertTrue(list.index.get() < list.SIZE);
237+
assertTrue(list.index.get() < IndexedRingBuffer.SIZE);
246238
// it should actually be 1 since we only did add/remove sequentially
247239
assertEquals(1, list.index.get());
248240
}
249241

250242
@Test
251243
public void testConcurrentAdds() throws InterruptedException {
252-
@SuppressWarnings("unchecked")
253244
final IndexedRingBuffer<Integer> list = IndexedRingBuffer.getInstance();
254245

255246
Scheduler.Worker w1 = Schedulers.computation().createWorker();
@@ -300,7 +291,6 @@ public void call() {
300291

301292
@Test
302293
public void testConcurrentAddAndRemoves() throws InterruptedException {
303-
@SuppressWarnings("unchecked")
304294
final IndexedRingBuffer<Integer> list = IndexedRingBuffer.getInstance();
305295

306296
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());

0 commit comments

Comments
 (0)