From 4c7dd4939a9d7e8bb03d14d14225494b58fcc91e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 30 Jan 2017 14:01:43 +0100 Subject: [PATCH] DATAES-328 - Replace explicit generics with diamond operator. --- .../core/CriteriaFilterProcessor.java | 8 +- .../core/CriteriaQueryProcessor.java | 8 +- .../core/DefaultResultMapper.java | 6 +- .../core/ElasticsearchTemplate.java | 12 +-- .../elasticsearch/core/FacetedPageImpl.java | 12 +-- .../elasticsearch/core/MappingBuilder.java | 2 +- .../aggregation/impl/AggregatedPageImpl.java | 17 +++- .../core/facet/request/RangeFacetRequest.java | 4 +- .../SimpleElasticsearchMappingContext.java | 2 +- ...SimpleElasticsearchPersistentProperty.java | 4 +- .../core/query/AbstractQuery.java | 6 +- .../elasticsearch/core/query/Criteria.java | 8 +- .../core/query/MoreLikeThisQuery.java | 11 ++- .../core/query/NativeSearchQuery.java | 8 +- .../core/query/NativeSearchQueryBuilder.java | 15 ++-- .../cdi/ElasticsearchRepositoryExtension.java | 4 +- .../AbstractElasticsearchRepository.java | 12 +-- ...ticsearchEntityInformationCreatorImpl.java | 2 +- .../data/elasticsearch/NestedObjectTests.java | 20 ++--- .../data/elasticsearch/core/AliasTests.java | 4 +- .../core/DefaultResultMapperTests.java | 2 +- .../core/ElasticsearchTemplateTests.java | 90 +++++++++---------- .../ElasticsearchTemplateCompletionTests.java | 10 +-- .../core/facet/ArticleEntity.java | 6 +- .../geo/ElasticsearchTemplateGeoTests.java | 6 +- .../core/query/CriteriaQueryTests.java | 38 ++++---- .../data/elasticsearch/entities/Book.java | 4 +- .../data/elasticsearch/entities/Group.java | 18 +++- .../data/elasticsearch/entities/User.java | 18 +++- .../CustomMethodRepositoryTests.java | 4 +- .../SimpleElasticsearchRepositoryTests.java | 2 +- .../UUIDElasticsearchRepositoryTests.java | 2 +- 32 files changed, 203 insertions(+), 162 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/CriteriaFilterProcessor.java b/src/main/java/org/springframework/data/elasticsearch/core/CriteriaFilterProcessor.java index 271747f28..5efa974f8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/CriteriaFilterProcessor.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/CriteriaFilterProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ class CriteriaFilterProcessor { QueryBuilder createFilterFromCriteria(Criteria criteria) { - List fbList = new LinkedList(); + List fbList = new LinkedList<>(); QueryBuilder filter = null; ListIterator chainIterator = criteria.getCriteriaChain().listIterator(); @@ -86,7 +86,7 @@ class CriteriaFilterProcessor { private List createFilterFragmentForCriteria(Criteria chainedCriteria) { Iterator it = chainedCriteria.getFilterCriteriaEntries().iterator(); - List filterList = new LinkedList(); + List filterList = new LinkedList<>(); String fieldName = chainedCriteria.getField().getName(); Assert.notNull(fieldName, "Unknown field"); @@ -235,7 +235,7 @@ class CriteriaFilterProcessor { } private List buildNegationFilter(String fieldName, Iterator it) { - List notFilterList = new LinkedList(); + List notFilterList = new LinkedList<>(); while (it.hasNext()) { Criteria.CriteriaEntry criteriaEntry = it.next(); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/CriteriaQueryProcessor.java b/src/main/java/org/springframework/data/elasticsearch/core/CriteriaQueryProcessor.java index e0207d900..1d743aba2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/CriteriaQueryProcessor.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/CriteriaQueryProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,9 +46,9 @@ class CriteriaQueryProcessor { if (criteria == null) return null; - List shouldQueryBuilderList = new LinkedList(); - List mustNotQueryBuilderList = new LinkedList(); - List mustQueryBuilderList = new LinkedList(); + List shouldQueryBuilderList = new LinkedList<>(); + List mustNotQueryBuilderList = new LinkedList<>(); + List mustQueryBuilderList = new LinkedList<>(); ListIterator chainIterator = criteria.getCriteriaChain().listIterator(); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java b/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java index 7eda3cdcb..d64216906 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java @@ -79,7 +79,7 @@ public class DefaultResultMapper extends AbstractResultMapper { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { long totalHits = response.getHits().totalHits(); - List results = new ArrayList(); + List results = new ArrayList<>(); for (SearchHit hit : response.getHits()) { if (hit != null) { T result = null; @@ -94,7 +94,7 @@ public class DefaultResultMapper extends AbstractResultMapper { } } - return new AggregatedPageImpl(results, pageable, totalHits, response.getAggregations()); + return new AggregatedPageImpl<>(results, pageable, totalHits, response.getAggregations()); } private void populateScriptFields(T result, SearchHit hit) { @@ -160,7 +160,7 @@ public class DefaultResultMapper extends AbstractResultMapper { @Override public LinkedList mapResults(MultiGetResponse responses, Class clazz) { - LinkedList list = new LinkedList(); + LinkedList list = new LinkedList<>(); for (MultiGetItemResponse response : responses.getResponses()) { if (!response.isFailed() && response.getResponse().isExists()) { T result = mapEntity(response.getResponse().getSourceAsString(), clazz); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java index 5492c6ead..6df801547 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java @@ -604,7 +604,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati } BulkResponse bulkResponse = bulkRequest.execute().actionGet(); if (bulkResponse.hasFailures()) { - Map failedDocuments = new HashMap(); + Map failedDocuments = new HashMap<>(); for (BulkItemResponse item : bulkResponse.getItems()) { if (item.isFailed()) failedDocuments.put(item.getId(), item.getFailureMessage()); @@ -624,7 +624,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati } BulkResponse bulkResponse = bulkRequest.execute().actionGet(); if (bulkResponse.hasFailures()) { - Map failedDocuments = new HashMap(); + Map failedDocuments = new HashMap<>(); for (BulkItemResponse item : bulkResponse.getItems()) { if (item.isFailed()) failedDocuments.put(item.getId(), item.getFailureMessage()); @@ -694,19 +694,19 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati String scrollId = scan(searchQuery, scrollTimeInMillis, true); BulkRequestBuilder bulkRequestBuilder = client.prepareBulk(); - List ids = new ArrayList(); + List ids = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = scroll(scrollId, scrollTimeInMillis, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { String id = searchHit.getId(); result.add(id); } if (result.size() > 0) { - return new AggregatedPageImpl((List) result); + return new AggregatedPageImpl<>((List) result); } return null; } @@ -1169,7 +1169,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati } private List extractIds(SearchResponse response) { - List ids = new ArrayList(); + List ids = new ArrayList<>(); for (SearchHit hit : response.getHits()) { if (hit != null) { ids.add(hit.getId()); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/FacetedPageImpl.java b/src/main/java/org/springframework/data/elasticsearch/core/FacetedPageImpl.java index d0a728516..c0c20ba62 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/FacetedPageImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/FacetedPageImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ import org.springframework.data.elasticsearch.core.facet.result.*; public abstract class FacetedPageImpl extends PageImpl implements FacetedPage, AggregatedPage { private List facets; - private Map mapOfFacets = new HashMap(); + private Map mapOfFacets = new HashMap<>(); public FacetedPageImpl(List content) { super(content); @@ -85,10 +85,10 @@ public abstract class FacetedPageImpl extends PageImpl implements FacetedP */ private void processAggregations() { if (facets == null) { - facets = new ArrayList(); + facets = new ArrayList<>(); for (Aggregation agg : getAggregations()) { if (agg instanceof Terms) { - List terms = new ArrayList(); + List terms = new ArrayList<>(); for (Terms.Bucket t : ((Terms) agg).getBuckets()) { terms.add(new Term(t.getKeyAsString(), t.getDocCount())); } @@ -96,7 +96,7 @@ public abstract class FacetedPageImpl extends PageImpl implements FacetedP } if (agg instanceof Range) { List buckets = ((Range) agg).getBuckets(); - List ranges = new ArrayList(); + List ranges = new ArrayList<>(); for (Range.Bucket b : buckets) { ExtendedStats rStats = (ExtendedStats) b.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS); if (rStats != null) { @@ -113,7 +113,7 @@ public abstract class FacetedPageImpl extends PageImpl implements FacetedP addFacet(new StatisticalResult(agg.getName(), stats.getCount(), stats.getMax(), stats.getMin(), stats.getAvg(), stats.getStdDeviation(), stats.getSumOfSquares(), stats.getSum(), stats.getVariance())); } if (agg instanceof Histogram) { - List intervals = new ArrayList(); + List intervals = new ArrayList<>(); for (Histogram.Bucket h : ((Histogram) agg).getBuckets()) { ExtendedStats hStats = (ExtendedStats) h.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS); if (hStats != null) { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java index fc07d8180..3111dbe5c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java @@ -167,7 +167,7 @@ class MappingBuilder { private static java.lang.reflect.Field[] retrieveFields(Class clazz) { // Create list of fields. - List fields = new ArrayList(); + List fields = new ArrayList<>(); // Keep backing up the inheritance hierarchy. Class targetClass = clazz; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java index dbf7e369c..f12bbb046 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/aggregation/impl/AggregatedPageImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.elasticsearch.core.aggregation.impl; import java.util.HashMap; @@ -18,7 +33,7 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage; public class AggregatedPageImpl extends FacetedPageImpl implements AggregatedPage { private Aggregations aggregations; - private Map mapOfAggregations = new HashMap(); + private Map mapOfAggregations = new HashMap<>(); public AggregatedPageImpl(List content) { super(content); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java index 7b1999889..9a1d7b9e2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public class RangeFacetRequest extends AbstractFacetRequest { private String keyField; private String valueField; - private List entries = new ArrayList(); + private List entries = new ArrayList<>(); public RangeFacetRequest(String name) { super(name); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchMappingContext.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchMappingContext.java index 281a5a007..5f537949f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchMappingContext.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchMappingContext.java @@ -37,7 +37,7 @@ public class SimpleElasticsearchMappingContext extends @Override protected SimpleElasticsearchPersistentEntity createPersistentEntity(TypeInformation typeInformation) { - final SimpleElasticsearchPersistentEntity persistentEntity = new SimpleElasticsearchPersistentEntity( + final SimpleElasticsearchPersistentEntity persistentEntity = new SimpleElasticsearchPersistentEntity<>( typeInformation); if (context != null) { persistentEntity.setApplicationContext(context); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index 6e350be75..70d2fbbfb 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -34,8 +34,8 @@ import org.springframework.data.mapping.model.SimpleTypeHolder; public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersistentProperty implements ElasticsearchPersistentProperty { - private static final Set> SUPPORTED_ID_TYPES = new HashSet>(); - private static final Set SUPPORTED_ID_PROPERTY_NAMES = new HashSet(); + private static final Set> SUPPORTED_ID_TYPES = new HashSet<>(); + private static final Set SUPPORTED_ID_PROPERTY_NAMES = new HashSet<>(); static { SUPPORTED_ID_TYPES.add(String.class); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/AbstractQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/AbstractQuery.java index 030ce9b10..8754a7833 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/AbstractQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/AbstractQuery.java @@ -35,9 +35,9 @@ abstract class AbstractQuery implements Query { protected Pageable pageable = DEFAULT_PAGE; protected Sort sort; - protected List indices = new ArrayList(); - protected List types = new ArrayList(); - protected List fields = new ArrayList(); + protected List indices = new ArrayList<>(); + protected List types = new ArrayList<>(); + protected List fields = new ArrayList<>(); protected SourceFilter sourceFilter; protected float minScore; protected Collection ids; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java b/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java index f3e665a82..627b2af9e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,11 +57,11 @@ public class Criteria { private float boost = Float.NaN; private boolean negating = false; - private List criteriaChain = new ArrayList(1); + private List criteriaChain = new ArrayList<>(1); - private Set queryCriteria = new LinkedHashSet(); + private Set queryCriteria = new LinkedHashSet<>(); - private Set filterCriteria = new LinkedHashSet(); + private Set filterCriteria = new LinkedHashSet<>(); public Criteria() { } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/MoreLikeThisQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/MoreLikeThisQuery.java index 0a7f0da0d..3311432e2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/MoreLikeThisQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/MoreLikeThisQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,20 +29,19 @@ import org.springframework.data.domain.Pageable; * @author Rizwan Idrees * @author Mohsin Husen */ - public class MoreLikeThisQuery { private String id; private String indexName; private String type; - private List searchIndices = new ArrayList(); - private List searchTypes = new ArrayList(); - private List fields = new ArrayList(); + private List searchIndices = new ArrayList<>(); + private List searchTypes = new ArrayList<>(); + private List fields = new ArrayList<>(); private String routing; private Float percentTermsToMatch; private Integer minTermFreq; private Integer maxQueryTerms; - private List stopWords = new ArrayList(); + private List stopWords = new ArrayList<>(); private Integer minDocFreq; private Integer maxDocFreq; private Integer minWordLen; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQuery.java index 265468bcf..239eacce6 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery { private QueryBuilder query; private QueryBuilder filter; private List sorts; - private final List scriptFields = new ArrayList(); + private final List scriptFields = new ArrayList<>(); private List facets; private List aggregations; private HighlightBuilder.Field[] highlightFields; @@ -97,7 +97,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery { public void addFacet(FacetRequest facetRequest) { if (facets == null) { - facets = new ArrayList(); + facets = new ArrayList<>(); } facets.add(facetRequest); } @@ -119,7 +119,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery { public void addAggregation(AbstractAggregationBuilder aggregationBuilder) { if (aggregations == null) { - aggregations = new ArrayList(); + aggregations = new ArrayList<>(); } aggregations.add(aggregationBuilder); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQueryBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQueryBuilder.java index 1e159c345..926f9a54b 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQueryBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/NativeSearchQueryBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,15 +34,14 @@ import org.springframework.data.elasticsearch.core.facet.FacetRequest; * @author Mohsin Husen * @author Artur Konczak */ - public class NativeSearchQueryBuilder { private QueryBuilder queryBuilder; private QueryBuilder filterBuilder; - private List scriptFields = new ArrayList(); - private List sortBuilders = new ArrayList(); - private List facetRequests = new ArrayList(); - private List aggregationBuilders = new ArrayList(); + private List scriptFields = new ArrayList<>(); + private List sortBuilders = new ArrayList<>(); + private List facetRequests = new ArrayList<>(); + private List aggregationBuilders = new ArrayList<>(); private HighlightBuilder.Field[] highlightFields; private Pageable pageable; private String[] indices; @@ -161,11 +160,11 @@ public class NativeSearchQueryBuilder { if (sourceFilter != null) { nativeSearchQuery.addSourceFilter(sourceFilter); } - + if(indicesBoost != null) { nativeSearchQuery.setIndicesBoost(indicesBoost); } - + if (!isEmpty(scriptFields)) { nativeSearchQuery.setScriptFields(scriptFields); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java index 8d027c241..83208e279 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/ElasticsearchRepositoryExtension.java @@ -44,7 +44,7 @@ import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; */ public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupport { - private final Map, Bean> elasticsearchOperationsMap = new HashMap, Bean>(); + private final Map, Bean> elasticsearchOperationsMap = new HashMap<>(); @SuppressWarnings("unchecked") void processBean(@Observes ProcessBean processBean) { @@ -78,7 +78,7 @@ public class ElasticsearchRepositoryExtension extends CdiRepositoryExtensionSupp ElasticsearchOperations.class.getName(), qualifiers)); } - return new ElasticsearchRepositoryBean(elasticsearchOperationsBean, qualifiers, repositoryType, beanManager, + return new ElasticsearchRepositoryBean<>(elasticsearchOperationsBean, qualifiers, repositoryType, beanManager, Optional.ofNullable(getCustomImplementationDetector())); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java index 23de735f9..b053c2223 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java @@ -104,7 +104,7 @@ public abstract class AbstractElasticsearchRepository findAll() { int itemCount = (int) this.count(); if (itemCount == 0) { - return new PageImpl(Collections. emptyList()); + return new PageImpl<>(Collections.emptyList()); } return this.findAll(new PageRequest(0, Math.max(1, itemCount))); } @@ -119,7 +119,7 @@ public abstract class AbstractElasticsearchRepository findAll(Sort sort) { int itemCount = (int) this.count(); if (itemCount == 0) { - return new PageImpl(Collections. emptyList()); + return new PageImpl<>(Collections.emptyList()); } SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) .withPageable(new PageRequest(0, itemCount, sort)).build(); @@ -150,7 +150,7 @@ public abstract class AbstractElasticsearchRepository List save(List entities) { Assert.notNull(entities, "Cannot insert 'null' as a List."); Assert.notEmpty(entities, "Cannot insert empty List."); - List queries = new ArrayList(); + List queries = new ArrayList<>(); for (S s : entities) { queries.add(createIndexQuery(s)); } @@ -167,7 +167,7 @@ public abstract class AbstractElasticsearchRepository Iterable save(Iterable entities) { Assert.notNull(entities, "Cannot insert 'null' as a List."); - List queries = new ArrayList(); + List queries = new ArrayList<>(); for (S s : entities) { queries.add(createIndexQuery(s)); } @@ -186,7 +186,7 @@ public abstract class AbstractElasticsearchRepository(Collections. emptyList()); + return new PageImpl<>(Collections.emptyList()); } searchQuery.setPageable(new PageRequest(0, count)); return elasticsearchOperations.queryForPage(searchQuery, getEntityClass()); @@ -311,7 +311,7 @@ public abstract class AbstractElasticsearchRepository stringIdsRepresentation(Iterable ids) { Assert.notNull(ids, "ids can't be null."); - List stringIds = new ArrayList(); + List stringIds = new ArrayList<>(); for (ID id : ids) { stringIds.add(stringIdRepresentation(id)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java index c7a016cd4..401177759 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java @@ -52,6 +52,6 @@ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchE Assert.notNull(persistentEntity, String.format("Unable to obtain mapping metadata for %s!", domainClass)); Assert.notNull(persistentEntity.getIdProperty(), String.format("No id property found for %s!", domainClass)); - return new MappingElasticsearchEntityInformation(persistentEntity); + return new MappingElasticsearchEntityInformation<>(persistentEntity); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java index b20b7d09a..65511c732 100644 --- a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public class NestedObjectTests { @Test public void shouldIndexInitialLevelNestedObject() { - final List cars = new ArrayList(); + final List cars = new ArrayList<>(); final Car saturn = new Car(); saturn.setName("Saturn"); @@ -116,7 +116,7 @@ public class NestedObjectTests { bar.setName("Bar"); bar.setCar(Arrays.asList(car)); - final List indexQueries = new ArrayList(); + final List indexQueries = new ArrayList<>(); final IndexQuery indexQuery1 = new IndexQuery(); indexQuery1.setId(foo.getId()); indexQuery1.setObject(foo); @@ -165,7 +165,7 @@ public class NestedObjectTests { //when elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class); elasticsearchTemplate.bulkIndex(indexQueries); - // then + // then final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class); @@ -253,7 +253,7 @@ public class NestedObjectTests { indexQuery2.setId(person2.getId()); indexQuery2.setObject(person2); - final List indexQueries = new ArrayList(); + final List indexQueries = new ArrayList<>(); indexQueries.add(indexQuery1); indexQueries.add(indexQuery2); @@ -263,7 +263,7 @@ public class NestedObjectTests { @Test public void shouldSearchBooksForPersonInitialLevelNestedType() { - final List cars = new ArrayList(); + final List cars = new ArrayList<>(); final Car saturn = new Car(); saturn.setName("Saturn"); @@ -312,7 +312,7 @@ public class NestedObjectTests { bar.setName("Bar"); bar.setCar(Arrays.asList(car)); - final List indexQueries = new ArrayList(); + final List indexQueries = new ArrayList<>(); final IndexQuery indexQuery1 = new IndexQuery(); indexQuery1.setId(foo.getId()); indexQuery1.setObject(foo); @@ -351,16 +351,16 @@ public class NestedObjectTests { book2.setId(randomNumeric(5)); book2.setName("testBook2"); - final Map> map1 = new HashMap>(); + final Map> map1 = new HashMap<>(); map1.put(1, Arrays.asList("test1", "test2")); - final Map> map2 = new HashMap>(); + final Map> map2 = new HashMap<>(); map2.put(1, Arrays.asList("test3", "test4")); book1.setBuckets(map1); book2.setBuckets(map2); - final List indexQueries = new ArrayList(); + final List indexQueries = new ArrayList<>(); final IndexQuery indexQuery1 = new IndexQuery(); indexQuery1.setId(book1.getId()); indexQuery1.setObject(book1); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/AliasTests.java b/src/test/java/org/springframework/data/elasticsearch/core/AliasTests.java index aa820bc45..7ba009fb1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/AliasTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/AliasTests.java @@ -1,5 +1,5 @@ /* -* Copyright 2014-2016 the original author or authors. +* Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ public class AliasTests { @Before public void before() { - Map settings = new HashMap(); + Map settings = new HashMap<>(); settings.put("index.refresh_interval", "-1"); settings.put("index.number_of_replicas", "0"); settings.put("index.number_of_shards", "2"); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/DefaultResultMapperTests.java b/src/test/java/org/springframework/data/elasticsearch/core/DefaultResultMapperTests.java index 66b8e7e95..63f83e3c9 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/DefaultResultMapperTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/DefaultResultMapperTests.java @@ -187,7 +187,7 @@ public class DefaultResultMapperTests { } private Map createCarFields(String name, String model) { - Map result = new HashMap(); + Map result = new HashMap<>(); result.put("name", new InternalSearchHitField("name", Arrays.asList(name))); result.put("model", new InternalSearchHitField("model", Arrays.asList(model))); return result; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java index 6fe00e009..cdd16c942 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,7 +142,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldReturnObjectsForGivenIdsUsingMultiGet() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId).message("some message") @@ -170,7 +170,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldReturnObjectsForGivenIdsUsingMultiGetWithFields() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId) @@ -198,7 +198,7 @@ public class ElasticsearchTemplateTests { LinkedList sampleEntities = elasticsearchTemplate.multiGet(query, SampleEntity.class, new MultiGetResultMapper() { @Override public LinkedList mapResults(MultiGetResponse responses, Class clazz) { - LinkedList list = new LinkedList(); + LinkedList list = new LinkedList<>(); for (MultiGetItemResponse response : responses.getResponses()) { SampleEntity entity = new SampleEntity(); entity.setId(response.getResponse().getId()); @@ -236,7 +236,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldDoBulkIndex() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId).message("some message") @@ -280,7 +280,7 @@ public class ElasticsearchTemplateTests { UpdateQuery updateQuery = new UpdateQueryBuilder().withId(documentId) .withClass(SampleEntity.class).withIndexRequest(indexRequest).build(); - List queries = new ArrayList(); + List queries = new ArrayList<>(); queries.add(updateQuery); // when @@ -375,7 +375,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldSortResultsGivenSortCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId) @@ -414,7 +414,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldSortResultsGivenMultipleSortCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId) @@ -488,7 +488,7 @@ public class ElasticsearchTemplateTests { elasticsearchTemplate.index(indexQuery); elasticsearchTemplate.refresh(SampleEntity.class); - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("factor", 2); // when SearchQuery searchQuery = new NativeSearchQueryBuilder() @@ -638,11 +638,11 @@ public class ElasticsearchTemplateTests { Page page = elasticsearchTemplate.queryForPage(searchQuery, String.class, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List values = new ArrayList(); + List values = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { values.add((String) searchHit.field("message").value()); } - return new AggregatedPageImpl((List) values); + return new AggregatedPageImpl<>((List) values); } }); // then @@ -731,7 +731,7 @@ public class ElasticsearchTemplateTests { criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); @@ -758,7 +758,7 @@ public class ElasticsearchTemplateTests { .withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); @@ -791,13 +791,13 @@ public class ElasticsearchTemplateTests { criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 5000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { String message = searchHit.getFields().get("message").getValue(); SampleEntity sampleEntity = new SampleEntity(); @@ -807,7 +807,7 @@ public class ElasticsearchTemplateTests { } if (result.size() > 0) { - return new AggregatedPageImpl((List) result); + return new AggregatedPageImpl<>((List) result); } return null; } @@ -843,13 +843,13 @@ public class ElasticsearchTemplateTests { .build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 10000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 10000L, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { String message = searchHit.getFields().get("message").getValue(); SampleEntity sampleEntity = new SampleEntity(); @@ -859,7 +859,7 @@ public class ElasticsearchTemplateTests { } if (result.size() > 0) { - return new AggregatedPageImpl((List) result); + return new AggregatedPageImpl<>((List) result); } return null; } @@ -892,13 +892,13 @@ public class ElasticsearchTemplateTests { criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 5000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List chunk = new ArrayList(); + List chunk = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { if (response.getHits().getHits().length <= 0) { return null; @@ -909,7 +909,7 @@ public class ElasticsearchTemplateTests { chunk.add(user); } if (chunk.size() > 0) { - return new AggregatedPageImpl((List) chunk); + return new AggregatedPageImpl<>((List) chunk); } return null; } @@ -937,13 +937,13 @@ public class ElasticsearchTemplateTests { .withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List chunk = new ArrayList(); + List chunk = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { if (response.getHits().getHits().length <= 0) { return null; @@ -954,7 +954,7 @@ public class ElasticsearchTemplateTests { chunk.add(user); } if (chunk.size() > 0) { - return new AggregatedPageImpl((List) chunk); + return new AggregatedPageImpl<>((List) chunk); } return null; } @@ -985,7 +985,7 @@ public class ElasticsearchTemplateTests { criteriaQuery.setPageable(new PageRequest(0, 10)); String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false, SampleEntity.class); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); @@ -1015,7 +1015,7 @@ public class ElasticsearchTemplateTests { .withPageable(new PageRequest(0, 10)).build(); String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false, SampleEntity.class); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); boolean hasRecords = true; while (hasRecords) { Page page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class); @@ -1047,7 +1047,7 @@ public class ElasticsearchTemplateTests { criteriaQuery.setPageable(new PageRequest(0, 10)); CloseableIterator stream = elasticsearchTemplate.stream(criteriaQuery, SampleEntity.class); - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); while (stream.hasNext()) { sampleEntities.add(stream.next()); } @@ -1055,7 +1055,7 @@ public class ElasticsearchTemplateTests { } private static List createSampleEntitiesWithMessage(String message, int numberOfEntities) { - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); for (int i = 0; i < numberOfEntities; i++) { String documentId = UUID.randomUUID().toString(); SampleEntity sampleEntity = new SampleEntity(); @@ -1074,7 +1074,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldReturnListForGivenCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = SampleEntity.builder().id(documentId) @@ -1249,7 +1249,7 @@ public class ElasticsearchTemplateTests { Page sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List chunk = new ArrayList(); + List chunk = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { if (response.getHits().getHits().length <= 0) { return null; @@ -1261,7 +1261,7 @@ public class ElasticsearchTemplateTests { chunk.add(user); } if (chunk.size() > 0) { - return new AggregatedPageImpl((List) chunk); + return new AggregatedPageImpl<>((List) chunk); } return null; } @@ -1316,14 +1316,14 @@ public class ElasticsearchTemplateTests { Page page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List values = new ArrayList(); + List values = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { SampleEntity sampleEntity = new SampleEntity(); sampleEntity.setId(searchHit.getId()); sampleEntity.setMessage((String) searchHit.getSource().get("message")); values.add(sampleEntity); } - return new AggregatedPageImpl((List) values); + return new AggregatedPageImpl<>((List) values); } }); assertThat(page, is(notNullValue())); @@ -1365,7 +1365,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldReturnDocumentAboveMinimalScoreGivenQuery() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(buildIndex(SampleEntity.builder().id("1").message("ab").build())); indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build())); @@ -1413,7 +1413,7 @@ public class ElasticsearchTemplateTests { @Test public void shouldDoBulkIndexWithoutId() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document SampleEntity sampleEntity1 = new SampleEntity(); sampleEntity1.setMessage("some message"); @@ -1446,14 +1446,14 @@ public class ElasticsearchTemplateTests { @Test public void shouldIndexMapWithIndexNameAndTypeAtRuntime() { //given - Map person1 = new HashMap(); + Map person1 = new HashMap<>(); person1.put("userId", "1"); person1.put("email", "smhdiu@gmail.com"); person1.put("title", "Mr"); person1.put("firstName", "Mohsin"); person1.put("lastName", "Husen"); - Map person2 = new HashMap(); + Map person2 = new HashMap<>(); person2.put("userId", "2"); person2.put("email", "akonczak@gmail.com"); person2.put("title", "Mr"); @@ -1472,7 +1472,7 @@ public class ElasticsearchTemplateTests { indexQuery2.setIndexName(INDEX_NAME); indexQuery2.setType(TYPE_NAME); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(indexQuery1); indexQueries.add(indexQuery2); @@ -1486,12 +1486,12 @@ public class ElasticsearchTemplateTests { Page sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List chunk = new ArrayList(); + List chunk = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { if (response.getHits().getHits().length <= 0) { return null; } - Map person = new HashMap(); + Map person = new HashMap<>(); person.put("userId", searchHit.getSource().get("userId")); person.put("email", searchHit.getSource().get("email")); person.put("title", searchHit.getSource().get("title")); @@ -1500,7 +1500,7 @@ public class ElasticsearchTemplateTests { chunk.add(person); } if (chunk.size() > 0) { - return new AggregatedPageImpl((List) chunk); + return new AggregatedPageImpl<>((List) chunk); } return null; } @@ -2000,14 +2000,14 @@ public class ElasticsearchTemplateTests { Page page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class, new SearchResultMapper() { @Override public AggregatedPage mapResults(SearchResponse response, Class clazz, Pageable pageable) { - List values = new ArrayList(); + List values = new ArrayList<>(); for (SearchHit searchHit : response.getHits()) { String id = String.valueOf(searchHit.getSource().get("id")); String firstName = StringUtils.isNotEmpty((String) searchHit.getSource().get("firstName")) ? (String) searchHit.getSource().get("firstName") : ""; String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : ""; values.add(new ResultAggregator(id, firstName, lastName)); } - return new AggregatedPageImpl((List) values); + return new AggregatedPageImpl<>((List) values); } }); @@ -2051,7 +2051,7 @@ public class ElasticsearchTemplateTests { } private List getIndexQueries(List sampleEntities) { - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); for (SampleEntity sampleEntity : sampleEntities) { indexQueries.add(new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build()); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java index 92c3c5e31..45409ba92 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ public class ElasticsearchTemplateCompletionTests { elasticsearchTemplate.refresh(CompletionEntity.class); elasticsearchTemplate.putMapping(CompletionEntity.class); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(new CompletionEntityBuilder("1").name("Rizwan Idrees").suggest(new String[]{"Rizwan Idrees"}).buildIndex()); indexQueries.add(new CompletionEntityBuilder("2").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex()); indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex()); @@ -81,7 +81,7 @@ public class ElasticsearchTemplateCompletionTests { nonDocumentEntity.setSomeField1("foo"); nonDocumentEntity.setSomeField2("bar"); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Rizwan Idrees").suggest(new String[]{"Rizwan", "Idrees"}, "Rizwan Idrees").buildIndex()); @@ -101,7 +101,7 @@ public class ElasticsearchTemplateCompletionTests { nonDocumentEntity.setSomeField1("Payload"); nonDocumentEntity.setSomeField2("test"); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}, null, Double.MAX_VALUE).buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, Long.MAX_VALUE).buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, "Payload test").buildIndex()); @@ -117,7 +117,7 @@ public class ElasticsearchTemplateCompletionTests { elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class); elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}).buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, null, 0).buildIndex()); indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, null, 1).buildIndex()); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/facet/ArticleEntity.java b/src/test/java/org/springframework/data/elasticsearch/core/facet/ArticleEntity.java index d35b43ec9..93bbd9522 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/facet/ArticleEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/facet/ArticleEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,10 +49,10 @@ public class ArticleEntity { @InnerField(suffix = "sort", type = String, store = true, indexAnalyzer = "keyword") } ) - private List authors = new ArrayList(); + private List authors = new ArrayList<>(); @Field(type = Integer, store = true) - private List publishedYears = new ArrayList(); + private List publishedYears = new ArrayList<>(); private int score; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java index 0ff09d9d8..452e116d1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public class ElasticsearchTemplateGeoTests { elasticsearchTemplate.refresh(AuthorMarkerEntity.class); elasticsearchTemplate.putMapping(AuthorMarkerEntity.class); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(new AuthorMarkerEntityBuilder("1").name("Franck Marchand").location(45.7806d, 3.0875d).buildIndex()); indexQueries.add(new AuthorMarkerEntityBuilder("2").name("Mohsin Husen").location(51.5171d, 0.1062d).buildIndex()); indexQueries.add(new AuthorMarkerEntityBuilder("3").name("Rizwan Idrees").location(51.5171d, 0.1062d).buildIndex()); @@ -69,7 +69,7 @@ public class ElasticsearchTemplateGeoTests { elasticsearchTemplate.refresh(LocationMarkerEntity.class); elasticsearchTemplate.putMapping(LocationMarkerEntity.class); - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); double[] latLonArray = {0.100000, 51.000000}; String lonLatString = "51.000000, 0.100000"; String geohash = "u1044k2bd6u"; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java index 358cdedde..3b7c62e2b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,7 +78,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformOrOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -117,7 +117,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformAndOperationWithinCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); @@ -144,7 +144,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformOrOperationWithinCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); @@ -170,7 +170,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformIsOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); @@ -196,7 +196,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformMultipleIsOperations() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -234,7 +234,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformEndsWithOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -273,7 +273,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformStartsWithOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -312,7 +312,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformContainsOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -350,7 +350,7 @@ public class CriteriaQueryTests { @Test public void shouldExecuteExpression() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -388,7 +388,7 @@ public class CriteriaQueryTests { @Test public void shouldExecuteCriteriaChain() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -427,7 +427,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformIsNotOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -466,7 +466,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformBetweenOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -505,7 +505,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformBetweenOperationWithoutUpperBound() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -545,7 +545,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformBetweenOperationWithoutLowerBound() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -585,7 +585,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformLessThanEqualOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -625,7 +625,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformGreaterThanEquals() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -665,7 +665,7 @@ public class CriteriaQueryTests { @Test public void shouldPerformBoostOperation() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); @@ -704,7 +704,7 @@ public class CriteriaQueryTests { @Test public void shouldReturnDocumentAboveMinimalScoreGivenCriteria() { // given - List indexQueries = new ArrayList(); + List indexQueries = new ArrayList<>(); indexQueries.add(buildIndex(SampleEntity.builder().id("1").message("ab").build())); indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build())); diff --git a/src/test/java/org/springframework/data/elasticsearch/entities/Book.java b/src/test/java/org/springframework/data/elasticsearch/entities/Book.java index 0b48896f7..da64886b0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/entities/Book.java +++ b/src/test/java/org/springframework/data/elasticsearch/entities/Book.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,5 +43,5 @@ public class Book { @Field(type = FieldType.Object) private Author author; @Field(type = FieldType.Nested) - private Map> buckets = new HashMap>(); + private Map> buckets = new HashMap<>(); } diff --git a/src/test/java/org/springframework/data/elasticsearch/entities/Group.java b/src/test/java/org/springframework/data/elasticsearch/entities/Group.java index efc748eaa..6c0cab283 100644 --- a/src/test/java/org/springframework/data/elasticsearch/entities/Group.java +++ b/src/test/java/org/springframework/data/elasticsearch/entities/Group.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.elasticsearch.entities; import java.util.HashSet; @@ -11,7 +26,6 @@ import org.springframework.data.elasticsearch.annotations.FieldType; /** * Created by akonczak on 21/08/2016. */ - @Document(indexName = "groups", type = "group") public class Group { @@ -19,5 +33,5 @@ public class Group { String id; @Field(type = FieldType.Nested, ignoreFields ={"groups"}) - private Set users = new HashSet(); + private Set users = new HashSet<>(); } diff --git a/src/test/java/org/springframework/data/elasticsearch/entities/User.java b/src/test/java/org/springframework/data/elasticsearch/entities/User.java index 17cdff2da..7de214abe 100644 --- a/src/test/java/org/springframework/data/elasticsearch/entities/User.java +++ b/src/test/java/org/springframework/data/elasticsearch/entities/User.java @@ -1,3 +1,18 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.elasticsearch.entities; import java.util.HashSet; @@ -11,12 +26,11 @@ import org.springframework.data.elasticsearch.annotations.FieldType; /** * Created by akonczak on 21/08/2016. */ - @Document(indexName = "users", type = "user") public class User { @Id private String id; @Field(type= FieldType.Nested,ignoreFields={"users"}) - private Set groups = new HashSet(); + private Set groups = new HashSet<>(); } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java index 8206a97cd..ce11efc95 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1194,7 +1194,7 @@ public class CustomMethodRepositoryTests { } private List createSampleEntities(String type, int numberOfEntities) { - List entities = new ArrayList(); + List entities = new ArrayList<>(); for (int i = 0; i < numberOfEntities; i++) { SampleEntity entity = new SampleEntity(); entity.setId(randomNumeric(numberOfEntities)); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java index 11bd72994..c6b0044e0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java @@ -534,7 +534,7 @@ public class SimpleElasticsearchRepositoryTests { } private static List createSampleEntitiesWithMessage(String message, int numberOfEntities) { - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); for (int i = 0; i < numberOfEntities; i++) { String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java index d6affe697..c7d3317e1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java @@ -490,7 +490,7 @@ public class UUIDElasticsearchRepositoryTests { } private static List createSampleEntitiesWithMessage(String message, int numberOfEntities) { - List sampleEntities = new ArrayList(); + List sampleEntities = new ArrayList<>(); for (int i = 0; i < numberOfEntities; i++) { UUID documentId = UUID.randomUUID(); SampleEntityUUIDKeyed sampleEntityUUIDKeyed = new SampleEntityUUIDKeyed();