Skip to content

Commit f7c5310

Browse files
DiegoKrupitzaschauder
authored andcommitted
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
1 parent 1f29463 commit f7c5310

20 files changed

+42
-47
lines changed

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
161161

162162
Assert.notNull(paths, "Paths must not be null!");
163163

164-
List<Order> existing = new ArrayList<Order>();
164+
List<Order> existing = new ArrayList<>();
165165

166166
for (Order order : this) {
167167
existing.add(order);
@@ -181,7 +181,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
181181

182182
Assert.notEmpty(properties, "Properties must not be empty!");
183183

184-
List<Order> orders = new ArrayList<Order>();
184+
List<Order> orders = new ArrayList<>();
185185

186186
for (Order order : this) {
187187
orders.add(order);
@@ -216,7 +216,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
216216

217217
private static List<Order> combine(List<Order> orders, @Nullable Direction direction, List<Path<?, ?>> paths) {
218218

219-
List<Order> result = new ArrayList<Sort.Order>(orders);
219+
List<Order> result = new ArrayList<>(orders);
220220

221221
for (Path<?, ?> path : paths) {
222222
result.add(new Order(direction, path.toString()));
@@ -315,7 +315,7 @@ private Path(List<? extends Attribute<?, ?>> attributes) {
315315
* @return
316316
*/
317317
public <A extends Attribute<S, U>, U> Path<S, U> dot(A attribute) {
318-
return new Path<S, U>(add(attribute));
318+
return new Path<>(add(attribute));
319319
}
320320

321321
/**

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
5757

5858
static {
5959

60-
Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
60+
Set<Class<? extends Annotation>> annotations = new HashSet<>();
6161
annotations.add(OneToMany.class);
6262
annotations.add(OneToOne.class);
6363
annotations.add(ManyToMany.class);
6464
annotations.add(ManyToOne.class);
6565

6666
ASSOCIATION_ANNOTATIONS = Collections.unmodifiableSet(annotations);
6767

68-
annotations = new HashSet<Class<? extends Annotation>>();
68+
annotations = new HashSet<>();
6969
annotations.add(Id.class);
7070
annotations.add(EmbeddedId.class);
7171

7272
ID_ANNOTATIONS = Collections.unmodifiableSet(annotations);
7373

74-
annotations = new HashSet<Class<? extends Annotation>>();
74+
annotations = new HashSet<>();
7575
annotations.add(Column.class);
7676
annotations.add(OrderColumn.class);
7777

@@ -150,7 +150,7 @@ public boolean isTransient() {
150150

151151
@Override
152152
protected Association<JpaPersistentProperty> createAssociation() {
153-
return new Association<JpaPersistentProperty>(this, null);
153+
return new Association<>(this, null);
154154
}
155155

156156
@Override

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Jpa21Utils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static EntityGraph<?> createDynamicEntityGraph(EntityManager em, JpaEnti
144144
*/
145145
static void configureFetchGraphFrom(JpaEntityGraph jpaEntityGraph, EntityGraph<?> entityGraph) {
146146

147-
List<String> attributePaths = new ArrayList<String>(jpaEntityGraph.getAttributePaths());
147+
List<String> attributePaths = new ArrayList<>(jpaEntityGraph.getAttributePaths());
148148

149149
// Sort to ensure that the intermediate entity subgraphs are created accordingly.
150150
Collections.sort(attributePaths);

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/DefaultJpaContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public DefaultJpaContext(Set<EntityManager> entityManagers) {
4747
Assert.notNull(entityManagers, "EntityManagers must not be null!");
4848
Assert.notEmpty(entityManagers, "EntityManagers must not be empty!");
4949

50-
this.entityManagers = new LinkedMultiValueMap<Class<?>, EntityManager>();
50+
this.entityManagers = new LinkedMultiValueMap<>();
5151

5252
for (EntityManager em : entityManagers) {
5353
for (ManagedType<?> managedType : em.getMetamodel().getManagedTypes()) {

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaEntityInformationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public abstract class JpaEntityInformationSupport<T, ID> extends AbstractEntityI
4242
*/
4343
public JpaEntityInformationSupport(Class<T> domainClass) {
4444
super(domainClass);
45-
this.metadata = new DefaultJpaEntityMetadata<T>(domainClass);
45+
this.metadata = new DefaultJpaEntityMetadata<>(domainClass);
4646
}
4747

4848
/**

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
8080

8181
switch (provider) {
8282
case ECLIPSELINK:
83-
return new JPAQuery<T>(em, EclipseLinkTemplates.DEFAULT);
83+
return new JPAQuery<>(em, EclipseLinkTemplates.DEFAULT);
8484
case HIBERNATE:
85-
return new JPAQuery<T>(em, HQLTemplates.DEFAULT);
85+
return new JPAQuery<>(em, HQLTemplates.DEFAULT);
8686
case GENERIC_JPA:
8787
default:
88-
return new JPAQuery<T>(em);
88+
return new JPAQuery<>(em);
8989
}
9090
}
9191

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public QuerydslJpaRepository(JpaEntityInformation<T, ID> entityInformation, Enti
9292
super(entityInformation, entityManager);
9393

9494
this.path = resolver.createPath(entityInformation.getJavaType());
95-
this.builder = new PathBuilder<T>(path.getType(), path.getMetadata());
95+
this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
9696
this.querydsl = new Querydsl(entityManager, builder);
9797
this.entityManager = entityManager;
9898
}

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private BeanDefinitionUtils() {}
5353

5454
static {
5555

56-
List<Class<?>> types = new ArrayList<Class<?>>();
56+
List<Class<?>> types = new ArrayList<>();
5757
types.add(EntityManagerFactory.class);
5858
types.add(AbstractEntityManagerFactoryBean.class);
5959

@@ -96,7 +96,7 @@ public static Iterable<String> getEntityManagerFactoryBeanNames(ListableBeanFact
9696
public static Collection<EntityManagerFactoryBeanDefinition> getEntityManagerFactoryBeanDefinitions(
9797
ConfigurableListableBeanFactory beanFactory) {
9898

99-
Set<EntityManagerFactoryBeanDefinition> definitions = new HashSet<EntityManagerFactoryBeanDefinition>();
99+
Set<EntityManagerFactoryBeanDefinition> definitions = new HashSet<>();
100100

101101
for (Class<?> type : EMF_TYPES) {
102102

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/Child.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class Child {
3131
Long id;
3232

3333
@ManyToMany(mappedBy = "children")
34-
Set<Parent> parents = new HashSet<Parent>();
34+
Set<Parent> parents = new HashSet<>();
3535

3636
/**
3737
* @param parent

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/Parent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Parent {
3434
static final long serialVersionUID = -89717120680485957L;
3535

3636
@ManyToMany(cascade = CascadeType.ALL)
37-
Set<Child> children = new HashSet<Child>();
37+
Set<Child> children = new HashSet<>();
3838

3939
public Parent add(Child child) {
4040

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/User.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public User(String firstname, String lastname, String emailAddress, Role... role
135135
this.lastname = lastname;
136136
this.emailAddress = emailAddress;
137137
this.active = true;
138-
this.roles = new HashSet<Role>(Arrays.asList(roles));
139-
this.colleagues = new HashSet<User>();
140-
this.attributes = new HashSet<String>();
138+
this.roles = new HashSet<>(Arrays.asList(roles));
139+
this.colleagues = new HashSet<>();
140+
this.attributes = new HashSet<>();
141141
this.createdAt = new Date();
142142
}
143143

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/JavaConfigUserRepositoryTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public UserRepository userRepository() throws Exception {
7575
QueryMethodEvaluationContextProvider evaluationContextProvider = new ExtensionAwareQueryMethodEvaluationContextProvider(
7676
applicationContext);
7777

78-
JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<UserRepository, User, Integer>(
78+
JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<>(
7979
UserRepository.class);
8080
factory.setEntityManager(entityManager);
8181
factory.setBeanFactory(applicationContext);

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void deleteCollectionOfEntitiesById() {
298298
@Test
299299
void deleteEmptyCollectionDoesNotDeleteAnything() {
300300

301-
assertDeleteCallDoesNotDeleteAnything(new ArrayList<User>());
301+
assertDeleteCallDoesNotDeleteAnything(new ArrayList<>());
302302
}
303303

304304
@Test

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/custom/CustomGenericJpaRepositoryFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public CustomGenericJpaRepositoryFactory(EntityManager entityManager) {
4848

4949
JpaEntityInformation<Object, Serializable> entityMetadata = mock(JpaEntityInformation.class);
5050
when(entityMetadata.getJavaType()).thenReturn((Class<Object>) information.getDomainType());
51-
return new CustomGenericJpaRepository<Object, Serializable>(entityMetadata, em);
51+
return new CustomGenericJpaRepository<>(entityMetadata, em);
5252
}
5353

5454
@Override

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/DefaultJpaContextIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void createEntityManagers() {
9191
this.firstEm = firstEmf.createEntityManager();
9292
this.secondEm = secondEmf.createEntityManager();
9393

94-
this.jpaContext = new DefaultJpaContext(new HashSet<EntityManager>(Arrays.asList(firstEm, secondEm)));
94+
this.jpaContext = new DefaultJpaContext(new HashSet<>(Arrays.asList(firstEm, secondEm)));
9595
}
9696

9797
@Test // DATAJPA-669

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/DefaultJpaEntityMetadataUnitTest.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ void rejectsNullDomainType() {
4444
@Test
4545
void returnsConfiguredType() {
4646

47-
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<Foo>(Foo.class);
47+
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<>(Foo.class);
4848
assertThat(metadata.getJavaType()).isEqualTo(Foo.class);
4949
}
5050

5151
@Test
5252
void returnsSimpleClassNameAsEntityNameByDefault() {
5353

54-
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<Foo>(Foo.class);
54+
DefaultJpaEntityMetadata<Foo> metadata = new DefaultJpaEntityMetadata<>(Foo.class);
5555
assertThat(metadata.getEntityName()).isEqualTo(Foo.class.getSimpleName());
5656
}
5757

5858
@Test
5959
void returnsCustomizedEntityNameIfConfigured() {
6060

61-
DefaultJpaEntityMetadata<Bar> metadata = new DefaultJpaEntityMetadata<Bar>(Bar.class);
61+
DefaultJpaEntityMetadata<Bar> metadata = new DefaultJpaEntityMetadata<>(Bar.class);
6262
assertThat(metadata.getEntityName()).isEqualTo("Entity");
6363
}
6464

6565
@Test // DATAJPA-871
6666
void returnsCustomizedEntityNameIfConfiguredViaComposedAnnotation() {
6767

68-
DefaultJpaEntityMetadata<BarWithComposedAnnotation> metadata = new DefaultJpaEntityMetadata<BarWithComposedAnnotation>(
68+
DefaultJpaEntityMetadata<BarWithComposedAnnotation> metadata = new DefaultJpaEntityMetadata<>(
6969
BarWithComposedAnnotation.class);
7070
assertThat(metadata.getEntityName()).isEqualTo("Entity");
7171
}
@@ -78,11 +78,14 @@ void returnsCustomizedEntityNameIfConfiguredViaComposedAnnotation() {
7878
String entityName();
7979
}
8080

81-
private static class Foo {}
81+
private static class Foo {
82+
}
8283

8384
@Entity(name = "Entity")
84-
static class Bar {}
85+
static class Bar {
86+
}
8587

8688
@CustomEntityAnnotationUsingAliasFor(entityName = "Entity")
87-
private static class BarWithComposedAnnotation {}
89+
private static class BarWithComposedAnnotation {
90+
}
8891
}

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationUnitTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.mockito.junit.jupiter.MockitoExtension;
3636
import org.mockito.junit.jupiter.MockitoSettings;
3737
import org.mockito.quality.Strictness;
38-
3938
import org.springframework.data.jpa.domain.sample.PersistableWithIdClass;
4039
import org.springframework.data.jpa.domain.sample.PersistableWithIdClassPK;
4140

@@ -62,8 +61,7 @@ void setUp() {
6261

6362
when(first.getName()).thenReturn("first");
6463
when(second.getName()).thenReturn("second");
65-
Set<SingularAttribute<? super PersistableWithIdClass, ?>> attributes = new HashSet<SingularAttribute<? super PersistableWithIdClass, ?>>(
66-
asList(first, second));
64+
Set<SingularAttribute<? super PersistableWithIdClass, ?>> attributes = new HashSet<>(asList(first, second));
6765

6866
when(type.getIdClassAttributes()).thenReturn(attributes);
6967

@@ -77,7 +75,7 @@ void setUp() {
7775
@Test // DATAJPA-50
7876
void doesNotCreateIdIfAllPartialAttributesAreNull() {
7977

80-
JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable> information = new JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable>(
78+
JpaMetamodelEntityInformation<PersistableWithIdClass, Serializable> information = new JpaMetamodelEntityInformation<>(
8179
PersistableWithIdClass.class, metamodel);
8280

8381
PersistableWithIdClass entity = new PersistableWithIdClass(null, null);

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/JpaPersistableEntityInformationUnitTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.mockito.junit.jupiter.MockitoExtension;
3030
import org.mockito.junit.jupiter.MockitoSettings;
3131
import org.mockito.quality.Strictness;
32-
3332
import org.springframework.data.domain.Persistable;
3433
import org.springframework.data.repository.core.EntityInformation;
3534

@@ -61,8 +60,7 @@ void setUp() {
6160
@Test
6261
void usesPersistableMethodsForIsNewAndGetId() {
6362

64-
EntityInformation<Foo, Long> entityInformation = new JpaPersistableEntityInformation<Foo, Long>(Foo.class,
65-
metamodel);
63+
EntityInformation<Foo, Long> entityInformation = new JpaPersistableEntityInformation<>(Foo.class, metamodel);
6664

6765
Foo foo = new Foo();
6866
assertThat(entityInformation.isNew(foo)).isFalse();

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/QuerydslJpaRepositoryTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
package org.springframework.data.jpa.repository.support;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.springframework.data.domain.Example.*;
20-
import static org.springframework.data.domain.ExampleMatcher.*;
21-
22-
import lombok.Data;
2319

2420
import java.sql.Date;
2521
import java.time.LocalDate;
@@ -80,10 +76,10 @@ class QuerydslJpaRepositoryTests {
8076
@BeforeEach
8177
void setUp() {
8278

83-
JpaEntityInformation<User, Integer> information = new JpaMetamodelEntityInformation<User, Integer>(User.class,
79+
JpaEntityInformation<User, Integer> information = new JpaMetamodelEntityInformation<>(User.class,
8480
em.getMetamodel());
8581

86-
repository = new QuerydslJpaRepository<User, Integer>(information, em);
82+
repository = new QuerydslJpaRepository<>(information, em);
8783
dave = repository.save(new User("Dave", "Matthews", "[email protected]"));
8884
carter = repository.save(new User("Carter", "Beauford", "[email protected]"));
8985
oliver = repository.save(new User("Oliver", "matthews", "[email protected]"));

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/SimpleJpaRepositoryUnitTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void setUp() {
8484
when(metadata.getQueryHints()).thenReturn(hints);
8585
when(metadata.getQueryHintsForCount()).thenReturn(hints);
8686

87-
repo = new SimpleJpaRepository<User, Integer>(information, em);
87+
repo = new SimpleJpaRepository<>(information, em);
8888
repo.setRepositoryMethodMetadata(metadata);
8989
}
9090

0 commit comments

Comments
 (0)