Skip to content

Commit d132061

Browse files
committed
ObjectIndex: eliminate warnings
1 parent b44dc31 commit d132061

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/main/java/org/scijava/object/ObjectIndex.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ public boolean isEmpty() {
149149
@Override
150150
public boolean contains(final Object o) {
151151
if (!getBaseClass().isAssignableFrom(o.getClass())) return false;
152-
return get(getType((E)o)).contains(o);
152+
@SuppressWarnings("unchecked")
153+
final E typedObj = (E) o;
154+
final Class<?> type = getType(typedObj);
155+
return get(type).contains(o);
153156
}
154157

155158
@Override
@@ -267,16 +270,22 @@ protected boolean remove(final Object o, final boolean batch) {
267270
new HashMap<Class<?>, List<E>[]>();
268271

269272
protected synchronized List<E>[] retrieveListsForType(final Class<?> type) {
270-
List<E>[] result = type2Lists.get(type);
271-
if (result != null) return result;
273+
final List<E>[] lists = type2Lists.get(type);
274+
if (lists != null) return lists;
272275

273-
final Collection<List<E>> lists = new ArrayList<List<E>>();
276+
final ArrayList<List<E>> listOfLists = new ArrayList<List<E>>();
274277
for (final Class<?> c : getTypes(type)) {
275-
lists.add(retrieveList(c));
278+
listOfLists.add(retrieveList(c));
276279
}
277-
result = lists.toArray(new List[lists.size()]);
278-
type2Lists.put(type, result);
279-
return result;
280+
// convert list of lists to array of lists
281+
@SuppressWarnings("rawtypes")
282+
final List[] arrayOfRawLists =
283+
listOfLists.toArray(new List[listOfLists.size()]);
284+
@SuppressWarnings({ "unchecked" })
285+
final List<E>[] arrayOfLists = arrayOfRawLists;
286+
type2Lists.put(type, arrayOfLists);
287+
288+
return arrayOfLists;
280289
}
281290

282291
/** Adds an object to type lists beneath the given type hierarchy. */
@@ -294,8 +303,8 @@ protected boolean remove(final Object o, final Class<?> type,
294303
final boolean batch)
295304
{
296305
boolean result = false;
297-
for (final List<?> list : retrieveListsForType(type)) {
298-
if (removeFromList(o, (List<E>) list, batch)) result = true;
306+
for (final List<E> list : retrieveListsForType(type)) {
307+
if (removeFromList(o, list, batch)) result = true;
299308
}
300309
return result;
301310
}

0 commit comments

Comments
 (0)