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>
,ResolvableTypeProvider
- Direct Known Subclasses:
CollectionModelMixin
,PagedModel
,SlicedModel
,VndErrors
public class CollectionModel<T>
extends RepresentationModel<CollectionModel<T>>
implements Iterable<T>, ResolvableTypeProvider
General helper to easily create a wrapper for a collection of entities.
- Author:
- Oliver Gierke, Greg Turnquist
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates an emptyCollectionModel
instance.protected
CollectionModel
(Iterable<T> content) protected
CollectionModel
(Iterable<T> content, Iterable<Link> links, 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
(ParameterizedTypeReference<T> type) Creates a new empty collection model with the given type defined as fallback type.static <T> CollectionModel<T>
empty
(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.boolean
Returns the underlying elements.int
hashCode()
iterator()
static <T> CollectionModel<T>
Creates aCollectionModel
instance with the given content.static <T> CollectionModel<T>
s Creates aCollectionModel
instance with the given content andLink
s.static <T> CollectionModel<T>
Creates aCollectionModel
instance with the given content andLink
s (optional).toString()
withFallbackType
(Class<? super T> type, Class<?>... generics) Declares the given type as fallback element type in case the underlying collection is empty.Declares the given type as fallback element type in case the underlying collection is empty.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 newCollectionModel
instance 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, removeLinks
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CollectionModel
protected CollectionModel()Creates an emptyCollectionModel
instance. -
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
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 aCollectionModel
instance with the given content.- Parameters:
content
- must not be null.- Returns:
- Since:
- 1.1
- See Also:
-
of
Creates aCollectionModel
instance with the given content andLink
s (optional).- Parameters:
content
- must not be null.links
- the links to be added to theCollectionModel
.- Returns:
- Since:
- 1.1
- See Also:
-
of
s Creates aCollectionModel
instance with the given content andLink
s.- Parameters:
content
- must not be null.links
- the links to be added to theCollectionModel
.- Returns:
- Since:
- 1.1
- See Also:
-
wrap
Creates a newCollectionModel
instance 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
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
- Specified by:
getResolvableType
in interfaceResolvableTypeProvider
-
iterator
-
toString
- Overrides:
toString
in classRepresentationModel<CollectionModel<T>>
-
equals
- Overrides:
equals
in classRepresentationModel<CollectionModel<T>>
-
hashCode
public int hashCode()- Overrides:
hashCode
in classRepresentationModel<CollectionModel<T>>
-