/** * Returns the entity if it exists in the set. * * @param entityClass class of entity * @param entityId entity id * @throws IllegalArgumentException if the entity not found */ public <T extends Entity<K>, K> T get(Class<T> entityClass, K entityId) { return optional(entityClass, entityId).orElseThrow(() -> new IllegalArgumentException("Entity not found")); }
/** * Returns the entity wrapped in {@code Optional} if it exists in the set. * * @param prototype a prototype instance whose class and id are used to look up an entity in the set. */ @SuppressWarnings("unchecked") public <T extends Entity> Optional<T> optional(T prototype) { Preconditions.checkNotNullArgument(prototype, "prototype entity is null"); return (Optional<T>) optional(prototype.getClass(), prototype.getId()); }