/** * Returns true if the list contains the exact instance of the specified object. * * @param list List to search. * @param object Object instance to locate. * @return True if the object was found. */ public static boolean containsInstance(List<?> list, Object object) { return indexOfInstance(list, object) > -1; }
/** * Finds a registered object belonging to the specified class. * * @param clazz Returned object must be assignment-compatible with this class. * @param previousInstance Previous instance returned by this call. Search will start with the * entry that follows this one in the list. If this parameter is null, the search * starts at the beginning. * @return Reference to the discovered object or null if none found. */ public synchronized Object findObject(Class<?> clazz, Object previousInstance) { int i = previousInstance == null ? -1 : MiscUtil.indexOfInstance(registeredObjects, previousInstance); for (i++; i < registeredObjects.size(); i++) { Object object = registeredObjects.get(i); if (clazz.isInstance(object)) { return object; } } return null; }
/** * Remove an object registration from the framework and any relevant subsystems. * * @param object Object to unregister. * @return True if object successfully unregistered. */ public synchronized boolean unregisterObject(Object object) { int i = MiscUtil.indexOfInstance(registeredObjects, object); if (i > -1) { registeredObjects.remove(i); for (IRegisterEvent onRegister : onRegisterList) { onRegister.unregisterObject(object); } if (object instanceof IRegisterEvent) { onRegisterList.remove(object); } return true; } return false; }