Explicit type replaced with diamond operator.

In modern java you do not need to add the explicit type if it can be inferred. To make the code more readable, we removed the explicit type and replaced it with the diamond operator (<>).

Original pull request #2459
This commit is contained in:
Diego Krupitza
2022-02-28 12:37:35 +01:00
committed by Jens Schauder
parent 1f29463cf6
commit f7c5310dc9
20 changed files with 42 additions and 47 deletions

View File

@@ -161,7 +161,7 @@ public class JpaSort extends Sort {
Assert.notNull(paths, "Paths must not be null!");
List<Order> existing = new ArrayList<Order>();
List<Order> existing = new ArrayList<>();
for (Order order : this) {
existing.add(order);
@@ -181,7 +181,7 @@ public class JpaSort extends Sort {
Assert.notEmpty(properties, "Properties must not be empty!");
List<Order> orders = new ArrayList<Order>();
List<Order> orders = new ArrayList<>();
for (Order order : this) {
orders.add(order);
@@ -216,7 +216,7 @@ public class JpaSort extends Sort {
private static List<Order> combine(List<Order> orders, @Nullable Direction direction, List<Path<?, ?>> paths) {
List<Order> result = new ArrayList<Sort.Order>(orders);
List<Order> result = new ArrayList<>(orders);
for (Path<?, ?> path : paths) {
result.add(new Order(direction, path.toString()));
@@ -315,7 +315,7 @@ public class JpaSort extends Sort {
* @return
*/
public <A extends Attribute<S, U>, U> Path<S, U> dot(A attribute) {
return new Path<S, U>(add(attribute));
return new Path<>(add(attribute));
}
/**

View File

@@ -57,7 +57,7 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
static {
Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
Set<Class<? extends Annotation>> annotations = new HashSet<>();
annotations.add(OneToMany.class);
annotations.add(OneToOne.class);
annotations.add(ManyToMany.class);
@@ -65,13 +65,13 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
ASSOCIATION_ANNOTATIONS = Collections.unmodifiableSet(annotations);
annotations = new HashSet<Class<? extends Annotation>>();
annotations = new HashSet<>();
annotations.add(Id.class);
annotations.add(EmbeddedId.class);
ID_ANNOTATIONS = Collections.unmodifiableSet(annotations);
annotations = new HashSet<Class<? extends Annotation>>();
annotations = new HashSet<>();
annotations.add(Column.class);
annotations.add(OrderColumn.class);
@@ -150,7 +150,7 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
@Override
protected Association<JpaPersistentProperty> createAssociation() {
return new Association<JpaPersistentProperty>(this, null);
return new Association<>(this, null);
}
@Override

View File

@@ -144,7 +144,7 @@ public class Jpa21Utils {
*/
static void configureFetchGraphFrom(JpaEntityGraph jpaEntityGraph, EntityGraph<?> entityGraph) {
List<String> attributePaths = new ArrayList<String>(jpaEntityGraph.getAttributePaths());
List<String> attributePaths = new ArrayList<>(jpaEntityGraph.getAttributePaths());
// Sort to ensure that the intermediate entity subgraphs are created accordingly.
Collections.sort(attributePaths);

View File

@@ -47,7 +47,7 @@ public class DefaultJpaContext implements JpaContext {
Assert.notNull(entityManagers, "EntityManagers must not be null!");
Assert.notEmpty(entityManagers, "EntityManagers must not be empty!");
this.entityManagers = new LinkedMultiValueMap<Class<?>, EntityManager>();
this.entityManagers = new LinkedMultiValueMap<>();
for (EntityManager em : entityManagers) {
for (ManagedType<?> managedType : em.getMetamodel().getManagedTypes()) {

View File

@@ -42,7 +42,7 @@ public abstract class JpaEntityInformationSupport<T, ID> extends AbstractEntityI
*/
public JpaEntityInformationSupport(Class<T> domainClass) {
super(domainClass);
this.metadata = new DefaultJpaEntityMetadata<T>(domainClass);
this.metadata = new DefaultJpaEntityMetadata<>(domainClass);
}
/**

View File

@@ -80,12 +80,12 @@ public class Querydsl {
switch (provider) {
case ECLIPSELINK:
return new JPAQuery<T>(em, EclipseLinkTemplates.DEFAULT);
return new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT);
case HIBERNATE:
return new JPAQuery<T>(em, HQLTemplates.DEFAULT);
return new JPAQuery<>(em, HQLTemplates.DEFAULT);
case GENERIC_JPA:
default:
return new JPAQuery<T>(em);
return new JPAQuery<>(em);
}
}

View File

@@ -92,7 +92,7 @@ public class QuerydslJpaRepository<T, ID extends Serializable> extends SimpleJpa
super(entityInformation, entityManager);
this.path = resolver.createPath(entityInformation.getJavaType());
this.builder = new PathBuilder<T>(path.getType(), path.getMetadata());
this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
this.querydsl = new Querydsl(entityManager, builder);
this.entityManager = entityManager;
}

View File

@@ -53,7 +53,7 @@ public final class BeanDefinitionUtils {
static {
List<Class<?>> types = new ArrayList<Class<?>>();
List<Class<?>> types = new ArrayList<>();
types.add(EntityManagerFactory.class);
types.add(AbstractEntityManagerFactoryBean.class);
@@ -96,7 +96,7 @@ public final class BeanDefinitionUtils {
public static Collection<EntityManagerFactoryBeanDefinition> getEntityManagerFactoryBeanDefinitions(
ConfigurableListableBeanFactory beanFactory) {
Set<EntityManagerFactoryBeanDefinition> definitions = new HashSet<EntityManagerFactoryBeanDefinition>();
Set<EntityManagerFactoryBeanDefinition> definitions = new HashSet<>();
for (Class<?> type : EMF_TYPES) {

View File

@@ -31,7 +31,7 @@ public class Child {
Long id;
@ManyToMany(mappedBy = "children")
Set<Parent> parents = new HashSet<Parent>();
Set<Parent> parents = new HashSet<>();
/**
* @param parent

View File

@@ -34,7 +34,7 @@ public class Parent {
static final long serialVersionUID = -89717120680485957L;
@ManyToMany(cascade = CascadeType.ALL)
Set<Child> children = new HashSet<Child>();
Set<Child> children = new HashSet<>();
public Parent add(Child child) {

View File

@@ -135,9 +135,9 @@ public class User {
this.lastname = lastname;
this.emailAddress = emailAddress;
this.active = true;
this.roles = new HashSet<Role>(Arrays.asList(roles));
this.colleagues = new HashSet<User>();
this.attributes = new HashSet<String>();
this.roles = new HashSet<>(Arrays.asList(roles));
this.colleagues = new HashSet<>();
this.attributes = new HashSet<>();
this.createdAt = new Date();
}

View File

@@ -75,7 +75,7 @@ class JavaConfigUserRepositoryTests extends UserRepositoryTests {
QueryMethodEvaluationContextProvider evaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(
applicationContext);
JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<UserRepository, User, Integer>(
JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<>(
UserRepository.class);
factory.setEntityManager(entityManager);
factory.setBeanFactory(applicationContext);

View File

@@ -298,7 +298,7 @@ public class UserRepositoryTests {
@Test
void deleteEmptyCollectionDoesNotDeleteAnything() {
assertDeleteCallDoesNotDeleteAnything(new ArrayList<User>());
assertDeleteCallDoesNotDeleteAnything(new ArrayList<>());
}
@Test

View File

@@ -48,7 +48,7 @@ public class CustomGenericJpaRepositoryFactory extends JpaRepositoryFactory {
JpaEntityInformation<Object, Serializable> entityMetadata = mock(JpaEntityInformation.class);
when(entityMetadata.getJavaType()).thenReturn((Class<Object>) information.getDomainType());
return new CustomGenericJpaRepository<Object, Serializable>(entityMetadata, em);
return new CustomGenericJpaRepository<>(entityMetadata, em);
}
@Override

View File

@@ -91,7 +91,7 @@ public class DefaultJpaContextIntegrationTests {
this.firstEm = firstEmf.createEntityManager();
this.secondEm = secondEmf.createEntityManager();
this.jpaContext = new DefaultJpaContext(new HashSet<EntityManager>(Arrays.asList(firstEm, secondEm)));
this.jpaContext = new DefaultJpaContext(new HashSet<>(Arrays.asList(firstEm, secondEm)));
}
@Test // DATAJPA-669

View File

@@ -44,28 +44,28 @@ public class DefaultJpaEntityMetadataUnitTest {
@Test
void returnsConfiguredType() {
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<Foo>(Foo.class);
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<>(Foo.class);
assertThat(metadata.getJavaType()).isEqualTo(Foo.class);
}
@Test
void returnsSimpleClassNameAsEntityNameByDefault() {
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<Foo>(Foo.class);
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<>(Foo.class);
assertThat(metadata.getEntityName()).isEqualTo(Foo.class.getSimpleName());
}
@Test
void returnsCustomizedEntityNameIfConfigured() {
DefaultJpaEntityMetadata<Bar> metadata = new DefaultJpaEntityMetadata<Bar>(Bar.class);
DefaultJpaEntityMetadata<Bar> metadata = new DefaultJpaEntityMetadata<>(Bar.class);
assertThat(metadata.getEntityName()).isEqualTo("Entity");
}
@Test // DATAJPA-871
void returnsCustomizedEntityNameIfConfiguredViaComposedAnnotation() {
DefaultJpaEntityMetadata<BarWithComposedAnnotation> metadata = new DefaultJpaEntityMetadata<BarWithComposedAnnotation>(
DefaultJpaEntityMetadata<BarWithComposedAnnotation> metadata = new DefaultJpaEntityMetadata<>(
BarWithComposedAnnotation.class);
assertThat(metadata.getEntityName()).isEqualTo("Entity");
}
@@ -78,11 +78,14 @@ public class DefaultJpaEntityMetadataUnitTest {
String entityName();
}
private static class Foo {}
private static class Foo {
}
@Entity(name = "Entity")
static class Bar {}
static class Bar {
}
@CustomEntityAnnotationUsingAliasFor(entityName = "Entity")
private static class BarWithComposedAnnotation {}
private static class BarWithComposedAnnotation {
}
}

View File

@@ -35,7 +35,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.jpa.domain.sample.PersistableWithIdClass;
import org.springframework.data.jpa.domain.sample.PersistableWithIdClassPK;
@@ -62,8 +61,7 @@ class JpaMetamodelEntityInformationUnitTests {
when(first.getName()).thenReturn("first");
when(second.getName()).thenReturn("second");
Set<SingularAttribute<? super PersistableWithIdClass, ?>> attributes = new HashSet<SingularAttribute<? super PersistableWithIdClass, ?>>(
asList(first, second));
Set<SingularAttribute<? super PersistableWithIdClass, ?>> attributes = new HashSet<>(asList(first, second));
when(type.getIdClassAttributes()).thenReturn(attributes);
@@ -77,7 +75,7 @@ class JpaMetamodelEntityInformationUnitTests {
@Test // DATAJPA-50
void doesNotCreateIdIfAllPartialAttributesAreNull() {
JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable> information = new JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable>(
JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable> information = new JpaMetamodelEntityInformation<>(
PersistableWithIdClass.class, metamodel);
PersistableWithIdClass entity = new PersistableWithIdClass(null, null);

View File

@@ -29,7 +29,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.domain.Persistable;
import org.springframework.data.repository.core.EntityInformation;
@@ -61,8 +60,7 @@ class JpaPersistableEntityInformationUnitTests {
@Test
void usesPersistableMethodsForIsNewAndGetId() {
EntityInformation<Foo, Long> entityInformation = new JpaPersistableEntityInformation<Foo, Long>(Foo.class,
metamodel);
EntityInformation<Foo, Long> entityInformation = new JpaPersistableEntityInformation<>(Foo.class, metamodel);
Foo foo = new Foo();
assertThat(entityInformation.isNew(foo)).isFalse();

View File

@@ -16,10 +16,6 @@
package org.springframework.data.jpa.repository.support;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.Example.*;
import static org.springframework.data.domain.ExampleMatcher.*;
import lombok.Data;
import java.sql.Date;
import java.time.LocalDate;
@@ -80,10 +76,10 @@ class QuerydslJpaRepositoryTests {
@BeforeEach
void setUp() {
JpaEntityInformation<User, Integer> information = new JpaMetamodelEntityInformation<User, Integer>(User.class,
JpaEntityInformation<User, Integer> information = new JpaMetamodelEntityInformation<>(User.class,
em.getMetamodel());
repository = new QuerydslJpaRepository<User, Integer>(information, em);
repository = new QuerydslJpaRepository<>(information, em);
dave = repository.save(new User("Dave", "Matthews", "dave@matthews.com"));
carter = repository.save(new User("Carter", "Beauford", "carter@beauford.com"));
oliver = repository.save(new User("Oliver", "matthews", "oliver@matthews.com"));

View File

@@ -84,7 +84,7 @@ class SimpleJpaRepositoryUnitTests {
when(metadata.getQueryHints()).thenReturn(hints);
when(metadata.getQueryHintsForCount()).thenReturn(hints);
repo = new SimpleJpaRepository<User, Integer>(information, em);
repo = new SimpleJpaRepository<>(information, em);
repo.setRepositoryMethodMetadata(metadata);
}