@@ -89,6 +89,7 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
8989 transient private boolean removeFromTargetBox ;
9090 transient private Comparator <TARGET > comparator ;
9191
92+ @ SuppressWarnings ("unchecked" ) // RelationInfo cast: ? is at least Object.
9293 public ToMany (Object sourceEntity , RelationInfo <?, TARGET > relationInfo ) {
9394 //noinspection ConstantConditions Annotation does not enforce non-null.
9495 if (sourceEntity == null ) {
@@ -378,6 +379,7 @@ public synchronized TARGET remove(int location) {
378379 return removed ;
379380 }
380381
382+ @ SuppressWarnings ("unchecked" ) // Cast to TARGET: If removed, must be of type TARGET.
381383 @ Override
382384 public synchronized boolean remove (Object object ) {
383385 ensureEntitiesWithTrackingLists ();
@@ -473,6 +475,7 @@ public Object[] toArray() {
473475 @ Nonnull
474476 public <T > T [] toArray (T [] array ) {
475477 ensureEntities ();
478+ //noinspection SuspiciousToArrayCall Caller must pass T that is supertype of TARGET.
476479 return entities .toArray (array );
477480 }
478481
@@ -571,9 +574,10 @@ public void applyChangesToDb() {
571574 */
572575 @ Beta
573576 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 )) {
577581 return true ;
578582 }
579583 }
@@ -588,12 +592,13 @@ public boolean hasA(QueryFilter<TARGET> filter) {
588592 */
589593 @ Beta
590594 public boolean hasAll (QueryFilter <TARGET > filter ) {
591- Object [] objects = toArray ();
595+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
596+ TARGET [] objects = (TARGET []) toArray ();
592597 if (objects .length == 0 ) {
593598 return false ;
594599 }
595- for (Object target : objects ) {
596- if (!filter .keep (( TARGET ) target )) {
600+ for (TARGET target : objects ) {
601+ if (!filter .keep (target )) {
597602 return false ;
598603 }
599604 }
@@ -604,12 +609,12 @@ public boolean hasAll(QueryFilter<TARGET> filter) {
604609 @ Beta
605610 public TARGET getById (long id ) {
606611 ensureEntities ();
607- Object [] objects = entities .toArray ();
612+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
613+ TARGET [] objects = (TARGET []) entities .toArray ();
608614 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 ;
613618 }
614619 }
615620 return null ;
@@ -619,12 +624,12 @@ public TARGET getById(long id) {
619624 @ Beta
620625 public int indexOfId (long id ) {
621626 ensureEntities ();
622- Object [] objects = entities .toArray ();
627+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
628+ TARGET [] objects = (TARGET []) entities .toArray ();
623629 IdGetter <TARGET > idGetter = relationInfo .targetInfo .getIdGetter ();
624630 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 ) {
628633 return index ;
629634 }
630635 index ++;
@@ -780,6 +785,7 @@ private boolean prepareToOneBacklinkEntitiesForDb(long entityId, IdGetter<TARGET
780785 * For internal use only; do not use in your app.
781786 * Convention: {@link #internalCheckApplyToDbRequired()} must be called before this call as it prepares .
782787 */
788+ @ SuppressWarnings ("unchecked" ) // Can't toArray(new TARGET[0]).
783789 @ Internal
784790 public void internalApplyToDb (Cursor <?> sourceCursor , Cursor <TARGET > targetCursor ) {
785791 TARGET [] toRemoveFromDb ;
0 commit comments