/** * Unregisters the given object. * @param object The object to unregister. * @param <T> The type of object. * @throws IllegalArgumentException if an instance of {@link Model} is * provided or if the model could not be unregistered from any * model. */ @SuppressWarnings("unchecked") public <T> void unregister(T object) { checkArgument(!(object instanceof Model), "can not unregister a model"); boolean result = false; final Set<Class<?>> modelSupportedTypes = registry.keySet(); for (final Class<?> modelSupportedType : modelSupportedTypes) { // check if object is from a known type if (modelSupportedType.isAssignableFrom(object.getClass())) { final Collection<Model<?>> assignableModels = registry .get(modelSupportedType); for (final Model<?> m : assignableModels) { result |= ((Model<T>) m).unregister(object); } } } checkArgument(result, "Object %s with type %s can not be unregistered.", object, object.getClass()); }