Package org.springframework.hateoas
Class SlicedModel<T>
java.lang.Object
org.springframework.hateoas.RepresentationModel<CollectionModel<T>>
org.springframework.hateoas.CollectionModel<T>
org.springframework.hateoas.SlicedModel<T>
- All Implemented Interfaces:
Iterable<T>,ResolvableTypeProvider
DTO to implement binding response representations of Slice collections.
- Since:
- 2.1
- Author:
- Michael Schout, Oliver Drotbohm
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classValue object for slice metadata. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor to allow instantiation by reflection.protectedSlicedModel(Collection<T> content, SlicedModel.SliceMetadata metadata) protectedSlicedModel(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links) protectedSlicedModel(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links, ResolvableType fallbackType) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SlicedModel<T>empty()Creates an emptySlicedModel.static <T> SlicedModel<T>Creates an emptySlicedModelwith the given fallback type.static <T> SlicedModel<T>Creates an emptySlicedModelwith the given links.static <T> SlicedModel<T>empty(ParameterizedTypeReference<T> fallbackElementType) Creates an emptySlicedModelwith the given fallback type.static <T> SlicedModel<T>empty(ResolvableType fallbackElementType) Creates an emptySlicedModelwith the given fallback type.static <T> SlicedModel<T>Creates an emptySlicedModelwith the given links.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadata.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata, Iterable<Link> links) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand links.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata, ResolvableType fallbackType) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.static <T> SlicedModel<T>empty(SlicedModel.SliceMetadata metadata, Link... links) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand links.booleanReturns the pagination metadata.Returns theLinkpointing to the next slice (if set).Returns theLinkpointing to the previous slice (if set).inthashCode()static <T> SlicedModel<T>of(Collection<T> content, SlicedModel.SliceMetadata metadata) static <T> SlicedModel<T>of(Collection<T> content, SlicedModel.SliceMetadata metadata, Iterable<Link> links) static <T> SlicedModel<T>of(Collection<T> content, SlicedModel.SliceMetadata metadata, Link... links) 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>
SlicedModel<T>wrap(Iterable<S> content, SlicedModel.SliceMetadata metadata) Factory method to easily create aSlicedModelinstance from a set of entities and pagination metadata.Methods inherited from class org.springframework.hateoas.CollectionModel
empty, getContent, getResolvableType, iterator, of, of, of, wrapMethods 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
-
Field Details
-
NO_SLICE
-
-
Constructor Details
-
SlicedModel
protected SlicedModel()Default constructor to allow instantiation by reflection. -
SlicedModel
-
SlicedModel
protected SlicedModel(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) -
SlicedModel
protected SlicedModel(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links, @Nullable ResolvableType fallbackType)
-
-
Method Details
-
empty
Creates an emptySlicedModel.- Type Parameters:
T- the payload type.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModelwith the given fallback type.- Type Parameters:
T- the payload type.- Parameters:
fallbackElementType- must not be null.generics- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModelwith the given fallback type.- Type Parameters:
T- the payload type.- Parameters:
fallbackElementType- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModelwith the given fallback type.- Type Parameters:
T- the payload type.- Parameters:
fallbackElementType- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
Creates an emptySlicedModelwith the given links.- Type Parameters:
T- the payload type.- Parameters:
links- must not be null.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModelwith the given links.- Type Parameters:
T- the payload type.- Parameters:
links- must not be null.- Returns:
- will never be null.
-
empty
Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadata.- Type Parameters:
T- the payload type.- Parameters:
metadata- can be null.- Returns:
- will never be null.
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, Class<?> fallbackType, Class<?>... generics) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.- Type Parameters:
T- the payload type.- Parameters:
metadata- can be null.fallbackType- must not be null.generics- must not be null.- Returns:
- will never be null.
- See Also:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, ParameterizedTypeReference<T> fallbackType) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.- Type Parameters:
T- the payload type.- Parameters:
metadata- can be null.- Returns:
- will never be null.
- See Also:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, ResolvableType fallbackType) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand fallback type.- Type Parameters:
T-- Parameters:
metadata- can be null.fallbackType- must not be null.- Returns:
- See Also:
-
empty
Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand links.- Type Parameters:
T-- Parameters:
metadata- can be null.links- must not be null.- Returns:
-
empty
public static <T> SlicedModel<T> empty(@Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) Creates an emptySlicedModelwith the givenSlicedModel.SliceMetadataand links.- Type Parameters:
T- the payload type.- Parameters:
metadata- can be null.links- must not be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata) - Type Parameters:
T- the payload type.- Parameters:
content- must not be null.metadata- can be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Link... links) - Type Parameters:
T- the payload type.- Parameters:
content- must not be null.metadata- can be null.links- must not be null.- Returns:
- will never be null.
-
of
public static <T> SlicedModel<T> of(Collection<T> content, @Nullable SlicedModel.SliceMetadata metadata, Iterable<Link> links) - Type Parameters:
T- the payload type.- Parameters:
content- must not be null.metadata- can be null.links- must not be null.- Returns:
- will never be null.
-
wrap
public static <T extends EntityModel<S>,S> SlicedModel<T> wrap(Iterable<S> content, SlicedModel.SliceMetadata metadata) Factory method to easily create aSlicedModelinstance from a set of entities and pagination metadata.- Type Parameters:
T- the nestedEntityModeltype.S- the actual payload type.- Parameters:
content- must not be null.metadata-- Returns:
- will never be null.
-
getMetadata
Returns the pagination metadata.- Returns:
- the metadata can be null.
-
getNextLink
Returns theLinkpointing to the next slice (if set).- Returns:
- will never be null.
-
getPreviousLink
Returns theLinkpointing to the previous slice (if set).- Returns:
- will never be null.
-
withFallbackType
Description copied from class:CollectionModelDeclares 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.- Overrides:
withFallbackTypein classCollectionModel<T>- Parameters:
type- must not be null.- Returns:
- will never be null.
-
withFallbackType
Description copied from class:CollectionModelDeclares 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.- Overrides:
withFallbackTypein classCollectionModel<T>- Parameters:
type- must not be null.- Returns:
- will never be null.
-
withFallbackType
Description copied from class:CollectionModelDeclares 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.- Overrides:
withFallbackTypein classCollectionModel<T>- Parameters:
type- must not be null.- Returns:
- will never be null.
-
toString
- Overrides:
toStringin classCollectionModel<T>
-
equals
- Overrides:
equalsin classCollectionModel<T>
-
hashCode
public int hashCode()- Overrides:
hashCodein classCollectionModel<T>
-