Package org.springframework.hateoas
Class CollectionModel<T>
java.lang.Object
org.springframework.hateoas.RepresentationModel<CollectionModel<T>>
org.springframework.hateoas.CollectionModel<T>
- All Implemented Interfaces:
Iterable<T>,org.springframework.core.ResolvableTypeProvider
- Direct Known Subclasses:
CollectionModelMixin,PagedModel,SlicedModel
public class CollectionModel<T>
extends RepresentationModel<CollectionModel<T>>
implements Iterable<T>, org.springframework.core.ResolvableTypeProvider
General helper to easily create a wrapper for a collection of entities.
- Author:
- Oliver Gierke, Greg Turnquist
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an emptyCollectionModelinstance.protectedCollectionModel(Iterable<T> content) protectedCollectionModel(Iterable<T> content, Iterable<Link> links, @Nullable org.springframework.core.ResolvableType fallbackType) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CollectionModel<T>empty()Creates a new empty collection model.static <T> CollectionModel<T>Creates a new empty collection model with the given type defined as fallback type.static <T> CollectionModel<T>Creates a new empty collection model with the given links.static <T> CollectionModel<T>empty(org.springframework.core.ParameterizedTypeReference<T> type) Creates a new empty collection model with the given type defined as fallback type.static <T> CollectionModel<T>empty(org.springframework.core.ResolvableType elementType) Creates a new empty collection model with the given type defined as fallback type.static <T> CollectionModel<T>Creates a new empty collection model with the given links.booleanReturns the underlying elements.@NonNull org.springframework.core.ResolvableTypeinthashCode()iterator()static <T> CollectionModel<T>Creates aCollectionModelinstance with the given content.static <T> CollectionModel<T>s Creates aCollectionModelinstance with the given content andLinks.static <T> CollectionModel<T>Creates aCollectionModelinstance with the given content andLinks (optional).toString()withFallbackType(Class<? super T> type, Class<?>... generics) Declares the given type as fallback element type in case the underlying collection is empty.withFallbackType(org.springframework.core.ParameterizedTypeReference<?> type) Declares the given type as fallback element type in case the underlying collection is empty.withFallbackType(org.springframework.core.ResolvableType type) Declares the given type as fallback element type in case the underlying collection is empty.static <T extends EntityModel<S>,S>
CollectionModel<T>Creates a newCollectionModelinstance by wrapping the given domain class instances into aEntityModel.Methods inherited from class org.springframework.hateoas.RepresentationModel
add, add, add, addAllIf, addIf, getLink, getLink, getLinks, getLinks, getLinks, getRequiredLink, getRequiredLink, hasLink, hasLink, hasLinks, mapLink, mapLinkIf, of, of, removeLinksMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CollectionModel
protected CollectionModel()Creates an emptyCollectionModelinstance. -
CollectionModel
-
CollectionModel
-
-
Method Details
-
empty
Creates a new empty collection model.- Type Parameters:
T-- Returns:
- Since:
- 1.1
-
empty
Creates a new empty collection model with the given type defined as fallback type.- Type Parameters:
T-- Returns:
- Since:
- 1.4
- See Also:
-
empty
public static <T> CollectionModel<T> empty(org.springframework.core.ParameterizedTypeReference<T> type) Creates a new empty collection model with the given type defined as fallback type.- Type Parameters:
T-- Returns:
- Since:
- 1.4
- See Also:
-
empty
Creates a new empty collection model with the given type defined as fallback type.- Type Parameters:
T-- Returns:
- Since:
- 1.4
- See Also:
-
empty
Creates a new empty collection model with the given links.- Type Parameters:
T-- Parameters:
links- must not be null.- Returns:
- Since:
- 1.1
-
empty
Creates a new empty collection model with the given links.- Type Parameters:
T-- Parameters:
links- must not be null.- Returns:
- Since:
- 1.1
-
of
Creates aCollectionModelinstance with the given content.- Parameters:
content- must not be null.- Returns:
- Since:
- 1.1
- See Also:
-
of
Creates aCollectionModelinstance with the given content andLinks (optional).- Parameters:
content- must not be null.links- the links to be added to theCollectionModel.- Returns:
- Since:
- 1.1
- See Also:
-
of
s Creates aCollectionModelinstance with the given content andLinks.- Parameters:
content- must not be null.links- the links to be added to theCollectionModel.- Returns:
- Since:
- 1.1
- See Also:
-
wrap
Creates a newCollectionModelinstance by wrapping the given domain class instances into aEntityModel.- Parameters:
content- must not be null.- Returns:
-
getContent
Returns the underlying elements.- Returns:
- the content will never be null.
-
withFallbackType
Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Parameters:
type- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
-
withFallbackType
public CollectionModel<T> withFallbackType(org.springframework.core.ParameterizedTypeReference<?> type) Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Parameters:
type- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
-
withFallbackType
Declares the given type as fallback element type in case the underlying collection is empty. This allows client components to still apply type matches at runtime.- Parameters:
type- must not be null.- Returns:
- will never be null.
- Since:
- 1.4
-
getResolvableType
public @NonNull org.springframework.core.ResolvableType getResolvableType()- Specified by:
getResolvableTypein interfaceorg.springframework.core.ResolvableTypeProvider
-
iterator
-
toString
- Overrides:
toStringin classRepresentationModel<CollectionModel<T>>
-
equals
- Overrides:
equalsin classRepresentationModel<CollectionModel<T>>
-
hashCode
public int hashCode()- Overrides:
hashCodein classRepresentationModel<CollectionModel<T>>
-