/** * Returns the object with the given id and stored in the given collection if it's contained in the * {@link ObjectPath}. * * @param id must not be {@literal null}. * @param collection must not be {@literal null} or empty. * @return * @deprecated use {@link #getPathItem(Object, String, Class)}. */ @Nullable @Deprecated Object getPathItem(Object id, String collection) { Assert.notNull(id, "Id must not be null!"); Assert.hasText(collection, "Collection name must not be null!"); for (ObjectPath current = this; current != null; current = current.parent) { Object object = current.getObject(); if (object == null || current.getIdValue() == null) { continue; } if (collection.equals(current.getCollection()) && id.equals(current.getIdValue())) { return object; } } return null; }
/** * Get the object with given {@literal id}, stored in the {@literal collection} that is assignable to the given * {@literal type} or {@literal null} if no match found. * * @param id must not be {@literal null}. * @param collection must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return {@literal null} when no match found. * @since 2.0 */ @Nullable <T> T getPathItem(Object id, String collection, Class<T> type) { Assert.notNull(id, "Id must not be null!"); Assert.hasText(collection, "Collection name must not be null!"); Assert.notNull(type, "Type must not be null!"); for (ObjectPath current = this; current != null; current = current.parent) { Object object = current.getObject(); if (object == null || current.getIdValue() == null) { continue; } if (collection.equals(current.getCollection()) && id.equals(current.getIdValue()) && ClassUtils.isAssignable(type, object.getClass())) { return type.cast(object); } } return null; }
/** * Returns the object with the given id and stored in the given collection if it's contained in the * {@link ObjectPath}. * * @param id must not be {@literal null}. * @param collection must not be {@literal null} or empty. * @return * @deprecated use {@link #getPathItem(Object, String, Class)}. */ @Nullable @Deprecated Object getPathItem(Object id, String collection) { Assert.notNull(id, "Id must not be null!"); Assert.hasText(collection, "Collection name must not be null!"); for (ObjectPath current = this; current != null; current = current.parent) { Object object = current.getObject(); if (object == null || current.getIdValue() == null) { continue; } if (collection.equals(current.getCollection()) && id.equals(current.getIdValue())) { return object; } } return null; }
/** * Get the object with given {@literal id}, stored in the {@literal collection} that is assignable to the given * {@literal type} or {@literal null} if no match found. * * @param id must not be {@literal null}. * @param collection must not be {@literal null} or empty. * @param type must not be {@literal null}. * @return {@literal null} when no match found. * @since 2.0 */ @Nullable <T> T getPathItem(Object id, String collection, Class<T> type) { Assert.notNull(id, "Id must not be null!"); Assert.hasText(collection, "Collection name must not be null!"); Assert.notNull(type, "Type must not be null!"); for (ObjectPath current = this; current != null; current = current.parent) { Object object = current.getObject(); if (object == null || current.getIdValue() == null) { continue; } if (collection.equals(current.getCollection()) && id.equals(current.getIdValue()) && ClassUtils.isAssignable(type, object.getClass())) { return type.cast(object); } } return null; }