Skip to content

Commit cd7c341

Browse files
committed
Polishing.
Reformat code, add contract annotation. See #3452 Original pull request: #3454
1 parent 1a0a882 commit cd7c341

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/main/java/org/springframework/data/web/SlicedResourcesAssembler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.hateoas.server.RepresentationModelAssembler;
4040
import org.springframework.hateoas.server.core.EmbeddedWrapper;
4141
import org.springframework.hateoas.server.core.EmbeddedWrappers;
42+
import org.springframework.lang.CheckReturnValue;
4243
import org.springframework.util.Assert;
4344
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
4445
import org.springframework.web.util.UriComponents;
@@ -100,6 +101,7 @@ public void setForceFirstRel(boolean forceFirstRel) {
100101
* @return will never be {@literal null}.
101102
* @since 3.1
102103
*/
104+
@CheckReturnValue
103105
public SlicedResourcesAssembler<T> withParameter(@Nullable MethodParameter parameter) {
104106
return new SlicedResourcesAssembler<>(pageableResolver, baseUri, parameter);
105107
}
@@ -116,7 +118,7 @@ public SlicedModel<EntityModel<T>> toModel(Slice<T> entity) {
116118
*
117119
* @param slice must not be {@literal null}.
118120
* @param selfLink must not be {@literal null}.
119-
* @return
121+
* @return a {@link SlicedModel}.
120122
*/
121123
public SlicedModel<EntityModel<T>> toModel(Slice<T> slice, Link selfLink) {
122124
return toModel(slice, EntityModel::of, selfLink);
@@ -128,7 +130,7 @@ public SlicedModel<EntityModel<T>> toModel(Slice<T> slice, Link selfLink) {
128130
*
129131
* @param slice must not be {@literal null}.
130132
* @param assembler must not be {@literal null}.
131-
* @return
133+
* @return a {@link SlicedModel}.
132134
*/
133135
public <R extends RepresentationModel<?>> SlicedModel<R> toModel(Slice<T> slice,
134136
RepresentationModelAssembler<T, R> assembler) {
@@ -143,11 +145,13 @@ public <R extends RepresentationModel<?>> SlicedModel<R> toModel(Slice<T> slice,
143145
* @param slice must not be {@literal null}.
144146
* @param assembler must not be {@literal null}.
145147
* @param link must not be {@literal null}.
146-
* @return a {@link SlicedModel} must not be {@literal null}.
148+
* @return a {@link SlicedModel}.
147149
*/
148150
public <R extends RepresentationModel<?>> SlicedModel<R> toModel(Slice<T> slice,
149151
RepresentationModelAssembler<T, R> assembler, Link link) {
152+
150153
Assert.notNull(link, "Link must not be null");
154+
151155
return createModel(slice, assembler, link);
152156
}
153157

@@ -156,7 +160,7 @@ public <R extends RepresentationModel<?>> SlicedModel<R> toModel(Slice<T> slice,
156160
*
157161
* @param slice must not be {@literal null}, content must be empty.
158162
* @param type must not be {@literal null}.
159-
* @return
163+
* @return an empty {@link SlicedModel}.
160164
*/
161165
public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type) {
162166
return toEmptyModel(slice, type, (Link) null);
@@ -168,7 +172,7 @@ public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type) {
168172
* @param slice must not be {@literal null}, content must be empty.
169173
* @param type must not be {@literal null}.
170174
* @param link can be {@literal null}.
171-
* @return a {@link SlicedModel} must not be {@literal null}.
175+
* @return an empty {@link SlicedModel}.
172176
*/
173177
public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, @Nullable Link link) {
174178

@@ -187,7 +191,6 @@ public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, @Nullable Link
187191

188192
@Deprecated
189193
public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, Optional<Link> link) {
190-
Assert.notNull(link, "Link must not be null");
191194
return toEmptyModel(slice, type, link.orElse(null));
192195
}
193196

@@ -201,6 +204,7 @@ public SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, Optional<Link>
201204
*/
202205
protected <R extends RepresentationModel<?>, S> SlicedModel<R> createSlicedModel(List<R> resources,
203206
SliceMetadata metadata, Slice<S> slice) {
207+
204208
Assert.notNull(resources, "Content resources must not be null");
205209
Assert.notNull(metadata, "SliceMetadata must not be null");
206210
Assert.notNull(slice, "Slice must not be null");
@@ -210,6 +214,7 @@ protected <R extends RepresentationModel<?>, S> SlicedModel<R> createSlicedModel
210214

211215
private <S, R extends RepresentationModel<?>> SlicedModel<R> createModel(Slice<S> slice,
212216
RepresentationModelAssembler<S, R> assembler, @Nullable Link link) {
217+
213218
Assert.notNull(slice, "Slice must not be null");
214219
Assert.notNull(assembler, "ResourceAssembler must not be null");
215220

@@ -227,7 +232,6 @@ private <S, R extends RepresentationModel<?>> SlicedModel<R> createModel(Slice<S
227232
private <R> SlicedModel<R> addPaginationLinks(SlicedModel<R> resources, Slice<?> slice, @Nullable Link link) {
228233

229234
UriTemplate base = getUriTemplate(link);
230-
231235
boolean isNavigable = slice.hasPrevious() || slice.hasNext();
232236

233237
if (isNavigable || forceFirstRel) {

src/test/java/org/springframework/data/web/SlicedResourcesAssemblerUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.Map;
25-
2625
import java.util.Optional;
26+
2727
import org.junit.jupiter.api.BeforeEach;
2828
import org.junit.jupiter.api.Test;
29+
2930
import org.springframework.data.domain.AbstractPageRequest;
3031
import org.springframework.data.domain.PageRequest;
3132
import org.springframework.data.domain.Pageable;
@@ -46,7 +47,6 @@
4647
*
4748
* @author Michael Schout
4849
* @author Oliver Drotbohm
49-
* @since 3.1
5050
*/
5151
class SlicedResourcesAssemblerUnitTest {
5252

0 commit comments

Comments
 (0)