@@ -89,6 +89,7 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
89
89
transient private boolean removeFromTargetBox ;
90
90
transient private Comparator <TARGET > comparator ;
91
91
92
+ @ SuppressWarnings ("unchecked" ) // RelationInfo cast: ? is at least Object.
92
93
public ToMany (Object sourceEntity , RelationInfo <?, TARGET > relationInfo ) {
93
94
//noinspection ConstantConditions Annotation does not enforce non-null.
94
95
if (sourceEntity == null ) {
@@ -378,6 +379,7 @@ public synchronized TARGET remove(int location) {
378
379
return removed ;
379
380
}
380
381
382
+ @ SuppressWarnings ("unchecked" ) // Cast to TARGET: If removed, must be of type TARGET.
381
383
@ Override
382
384
public synchronized boolean remove (Object object ) {
383
385
ensureEntitiesWithTrackingLists ();
@@ -473,6 +475,7 @@ public Object[] toArray() {
473
475
@ Nonnull
474
476
public <T > T [] toArray (T [] array ) {
475
477
ensureEntities ();
478
+ //noinspection SuspiciousToArrayCall Caller must pass T that is supertype of TARGET.
476
479
return entities .toArray (array );
477
480
}
478
481
@@ -571,9 +574,10 @@ public void applyChangesToDb() {
571
574
*/
572
575
@ Beta
573
576
public boolean hasA (QueryFilter <TARGET > filter ) {
574
- Object [] objects = toArray ();
575
- for (Object target : objects ) {
576
- if (filter .keep ((TARGET ) target )) {
577
+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
578
+ TARGET [] objects = (TARGET []) toArray ();
579
+ for (TARGET target : objects ) {
580
+ if (filter .keep (target )) {
577
581
return true ;
578
582
}
579
583
}
@@ -588,12 +592,13 @@ public boolean hasA(QueryFilter<TARGET> filter) {
588
592
*/
589
593
@ Beta
590
594
public boolean hasAll (QueryFilter <TARGET > filter ) {
591
- Object [] objects = toArray ();
595
+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
596
+ TARGET [] objects = (TARGET []) toArray ();
592
597
if (objects .length == 0 ) {
593
598
return false ;
594
599
}
595
- for (Object target : objects ) {
596
- if (!filter .keep (( TARGET ) target )) {
600
+ for (TARGET target : objects ) {
601
+ if (!filter .keep (target )) {
597
602
return false ;
598
603
}
599
604
}
@@ -604,12 +609,12 @@ public boolean hasAll(QueryFilter<TARGET> filter) {
604
609
@ Beta
605
610
public TARGET getById (long id ) {
606
611
ensureEntities ();
607
- Object [] objects = entities .toArray ();
612
+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
613
+ TARGET [] objects = (TARGET []) entities .toArray ();
608
614
IdGetter <TARGET > idGetter = relationInfo .targetInfo .getIdGetter ();
609
- for (Object target : objects ) {
610
- TARGET candidate = (TARGET ) target ;
611
- if (idGetter .getId (candidate ) == id ) {
612
- return candidate ;
615
+ for (TARGET target : objects ) {
616
+ if (idGetter .getId (target ) == id ) {
617
+ return target ;
613
618
}
614
619
}
615
620
return null ;
@@ -619,12 +624,12 @@ public TARGET getById(long id) {
619
624
@ Beta
620
625
public int indexOfId (long id ) {
621
626
ensureEntities ();
622
- Object [] objects = entities .toArray ();
627
+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
628
+ TARGET [] objects = (TARGET []) entities .toArray ();
623
629
IdGetter <TARGET > idGetter = relationInfo .targetInfo .getIdGetter ();
624
630
int index = 0 ;
625
- for (Object target : objects ) {
626
- TARGET candidate = (TARGET ) target ;
627
- if (idGetter .getId (candidate ) == id ) {
631
+ for (TARGET target : objects ) {
632
+ if (idGetter .getId (target ) == id ) {
628
633
return index ;
629
634
}
630
635
index ++;
@@ -780,6 +785,7 @@ private boolean prepareToOneBacklinkEntitiesForDb(long entityId, IdGetter<TARGET
780
785
* For internal use only; do not use in your app.
781
786
* Convention: {@link #internalCheckApplyToDbRequired()} must be called before this call as it prepares .
782
787
*/
788
+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
783
789
@ Internal
784
790
public void internalApplyToDb (Cursor <?> sourceCursor , Cursor <TARGET > targetCursor ) {
785
791
TARGET [] toRemoveFromDb ;
0 commit comments