Skip to content

Commit

Permalink
[spring-projects#1300] Fix several test switching generics order
Browse files Browse the repository at this point in the history
  • Loading branch information
Patouche committed Jun 3, 2020
1 parent cb39ff5 commit fd132c9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.function.Supplier;

/**
* General helper to easily create a wrapper for a collection of entities.
*
* @author Oliver Gierke
* @author Greg Turnquist
*/
public class AbstractCollectionModel<S extends AbstractCollectionModel<S,T>, T> extends RepresentationModel<S> implements Iterable<T> {
public class AbstractCollectionModel<T, S extends AbstractCollectionModel<T, S>> extends RepresentationModel<S> implements Iterable<T> {

private final Collection<T> content;

Expand Down Expand Up @@ -98,7 +96,7 @@ public boolean equals(@Nullable Object obj) {
return false;
}

AbstractCollectionModel<?, ?> that = (AbstractCollectionModel<?,?>) obj;
AbstractCollectionModel<?, ?> that = (AbstractCollectionModel<?, ?>) obj;
return Objects.equals(this.content, that.content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* General helper to easily create a wrapper for a collection of entities.
*
* @author Oliver Gierke
* @author Greg Turnquist
*/
public class CollectionModel<T> extends AbstractCollectionModel<CollectionModel<T>, T> implements Iterable<T> {
public class CollectionModel<T> extends AbstractCollectionModel<T, CollectionModel<T>> implements Iterable<T> {

/**
* Creates an empty {@link CollectionModel} instance.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/springframework/hateoas/PagedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Oliver Gierke
* @author Greg Turnquist
*/
public class PagedModel<T> extends AbstractCollectionModel<PagedModel<T>, T> {
public class PagedModel<T> extends AbstractCollectionModel<T, PagedModel<T>> {

public static PagedModel<?> NO_PAGE = new PagedModel<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ private CollectionJsonPagedResourcesDeserializer(JavaType contentType) {
}
}

private static List<CollectionJsonItem<Object>> resourcesToCollectionJsonItems(AbstractCollectionModel<?,?> resources) {
private static List<CollectionJsonItem<Object>> resourcesToCollectionJsonItems(AbstractCollectionModel<?, ?> resources) {

return resources.getContent().stream().map(content -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty
/**
* Serializer for {@link CollectionModel}
*/
static class HalFormsCollectionModelSerializer extends ContainerSerializer<AbstractCollectionModel<?,?>>
static class HalFormsCollectionModelSerializer extends ContainerSerializer<AbstractCollectionModel<?, ?>>
implements ContextualSerializer {

private static final long serialVersionUID = -3601146866067500734L;
Expand Down Expand Up @@ -243,7 +243,7 @@ static class HalFormsCollectionModelSerializer extends ContainerSerializer<Abstr
*/
@Override
@SuppressWarnings("null")
public void serialize(AbstractCollectionModel<?,?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {
public void serialize(AbstractCollectionModel<?, ?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {

EmbeddedMapper mapper = configuration.isApplyPropertyNamingStrategy() //
? embeddedMapper.with(provider.getConfig().getPropertyNamingStrategy()) //
Expand Down Expand Up @@ -298,7 +298,7 @@ public JsonSerializer<?> getContentSerializer() {
*/
@Override
@SuppressWarnings("null")
public boolean hasSingleElement(AbstractCollectionModel<?,?> resources) {
public boolean hasSingleElement(AbstractCollectionModel<?, ?> resources) {
return resources.getContent().size() == 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static List<UberData> extractLinksAndContent(EntityModel<?> resource) {
* @param resources
* @return
*/
private static List<UberData> extractLinksAndCollectionContent(AbstractCollectionModel<?,?> resources) {
private static List<UberData> extractLinksAndCollectionContent(AbstractCollectionModel<?, ?> resources) {

List<UberData> data = extractLinks(resources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public boolean supports(ResolvableType type, Object value) {
* @return
*/

static boolean isValueTypeMatch(@Nullable AbstractCollectionModel<?,?> collectionModel, ResolvableType target) {
static boolean isValueTypeMatch(@Nullable AbstractCollectionModel<?, ?> collectionModel, ResolvableType target) {

if (collectionModel == null) {
return false;
Expand Down Expand Up @@ -413,7 +413,7 @@ static boolean isValueTypeMatch(@Nullable AbstractCollectionModel<?,?> collectio
}

Object element = content.iterator().next();
ResolvableType resourceType = superType.getGeneric(1);
ResolvableType resourceType = superType.getGeneric(0);

if (element instanceof EntityModel) {
return EntityModelProcessorWrapper.isValueTypeMatch((EntityModel<?>) element, resourceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ void handleTemplatedLinksOnDeserialization() throws IOException {
assertThat(deserialized).isEqualTo(original);
}

private static AbstractCollectionModel<?, EntityModel<Employee>> setupAnnotatedPagedResources() {
private static AbstractCollectionModel<EntityModel<Employee>, ?> setupAnnotatedPagedResources() {

return setupAnnotatedPagedResources(2, 4);
}

@NotNull
private static AbstractCollectionModel<?, EntityModel<Employee>> setupAnnotatedPagedResources(int size, int totalElements) {
private static AbstractCollectionModel<EntityModel<Employee>, ?> setupAnnotatedPagedResources(int size, int totalElements) {

List<EntityModel<Employee>> content = new ArrayList<>();
Employee employee = new Employee("Frodo", "ring bearer");
Expand Down

0 comments on commit fd132c9

Please sign in to comment.