Skip to content

Use diamond operator where possible #3458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ public Map<String, Parameters> getConnections() {

private Map<String, ServerParameters> resourceToServerParameters() {
try {
Map<String, Map<String, Parameters>> stdioConnection = new ObjectMapper().readValue(
this.serversConfiguration.getInputStream(),
new TypeReference<Map<String, Map<String, Parameters>>>() {
});
Map<String, Map<String, Parameters>> stdioConnection = new ObjectMapper()
.readValue(this.serversConfiguration.getInputStream(), new TypeReference<>() {
});

Map<String, Parameters> mcpServerJsonConfig = stdioConnection.entrySet().iterator().next().getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ MongoDBAtlasVectorStore vectorStore(MongoTemplate mongoTemplate, EmbeddingModel

@Bean
public Converter<MimeType, String> mimeTypeToStringConverter() {
return new Converter<MimeType, String>() {
return new Converter<>() {

@Override
public String convert(MimeType source) {
Expand All @@ -102,7 +102,7 @@ public String convert(MimeType source) {

@Bean
public Converter<String, MimeType> stringToMimeTypeConverter() {
return new Converter<String, MimeType>() {
return new Converter<>() {

@Override
public MimeType convert(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ForkPDFLayoutTextStripper extends PDFTextStripper {
public ForkPDFLayoutTextStripper() throws IOException {
super();
this.previousTextPosition = null;
this.textLineList = new ArrayList<TextLine>();
this.textLineList = new ArrayList<>();
}

/**
Expand All @@ -67,7 +67,7 @@ public void processPage(PDPage page) throws IOException {
this.setCurrentPageWidth(pageRectangle.getWidth() * 1.4);
super.processPage(page);
this.previousTextPosition = null;
this.textLineList = new ArrayList<TextLine>();
this.textLineList = new ArrayList<>();
}
}

Expand Down Expand Up @@ -124,7 +124,7 @@ private void writeLine(final List<TextPosition> textPositionList) {
}

private void iterateThroughTextList(Iterator<TextPosition> textIterator) {
List<TextPosition> textPositionList = new ArrayList<TextPosition>();
List<TextPosition> textPositionList = new ArrayList<>();

while (textIterator.hasNext()) {
TextPosition textPosition = (TextPosition) textIterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
*/
public class PDFLayoutTextStripperByArea extends ForkPDFLayoutTextStripper {

private final List<String> regions = new ArrayList<String>();
private final List<String> regions = new ArrayList<>();

private final Map<String, Rectangle2D> regionArea = new HashMap<String, Rectangle2D>();
private final Map<String, Rectangle2D> regionArea = new HashMap<>();

private final Map<String, ArrayList<List<TextPosition>>> regionCharacterList = new HashMap<String, ArrayList<List<TextPosition>>>();
private final Map<String, ArrayList<List<TextPosition>>> regionCharacterList = new HashMap<>();

private final Map<String, StringWriter> regionText = new HashMap<String, StringWriter>();
private final Map<String, StringWriter> regionText = new HashMap<>();

/**
* Constructor.
Expand Down Expand Up @@ -113,8 +113,8 @@ public void extractRegions(PDPage page) throws IOException {
setStartPage(getCurrentPageNo());
setEndPage(getCurrentPageNo());
// reset the stored text for the region so this class can be reused.
ArrayList<List<TextPosition>> regionCharactersByArticle = new ArrayList<List<TextPosition>>();
regionCharactersByArticle.add(new ArrayList<TextPosition>());
ArrayList<List<TextPosition>> regionCharactersByArticle = new ArrayList<>();
regionCharactersByArticle.add(new ArrayList<>());
this.regionCharacterList.put(regionName, regionCharactersByArticle);
this.regionText.put(regionName, new StringWriter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void readEvents() throws IOException {
String json = new DefaultResourceLoader().getResource("classpath:/sample_events.json")
.getContentAsString(Charset.defaultCharset());

List<StreamEvent> events = new ObjectMapper().readerFor(new TypeReference<List<StreamEvent>>() {
List<StreamEvent> events = new ObjectMapper().readerFor(new TypeReference<>() {

}).readValue(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void listOutputConverterBean() {
List<ActorsFilms> actorsFilms = ChatClient.create(this.chatModel).prompt()
.user("Generate the filmography of 5 movies for Tom Hanks and Bill Murray.")
.call()
.entity(new ParameterizedTypeReference<List<ActorsFilms>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down Expand Up @@ -141,7 +141,7 @@ void mapOutputConverter() {
.user(u -> u.text("Provide me a List of {subject}")
.param("subject", "an array of numbers from 1 to 9 under they key name 'numbers'"))
.call()
.entity(new ParameterizedTypeReference<Map<String, Object>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void listOutputConverterString() {
.user(u -> u.text("List five {subject}")
.param("subject", "ice cream flavors"))
.call()
.entity(new ParameterizedTypeReference<List<String>>() { });
.entity(new ParameterizedTypeReference<>() { });
// @formatter:on

logger.info(collection.toString());
Expand All @@ -102,7 +102,7 @@ void listOutputConverterBean() {
List<ActorsFilms> actorsFilms = ChatClient.create(this.chatModel).prompt()
.user("Generate the filmography of 5 movies for Tom Hanks and Bill Murray.")
.call()
.entity(new ParameterizedTypeReference<List<ActorsFilms>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down Expand Up @@ -135,7 +135,7 @@ void mapOutputConverter() {
.user(u -> u.text("Provide me a List of {subject}")
.param("subject", "an array of numbers from 1 to 9 under they key name 'numbers'"))
.call()
.entity(new ParameterizedTypeReference<Map<String, Object>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ChatResponse call(Prompt prompt) {
String generatedText = generateResponse.getGeneratedText();
AllOfGenerateResponseDetails allOfGenerateResponseDetails = generateResponse.getDetails();
Map<String, Object> detailsMap = this.objectMapper.convertValue(allOfGenerateResponseDetails,
new TypeReference<Map<String, Object>>() {
new TypeReference<>() {

});
Generation generation = new Generation(new AssistantMessage(generatedText, detailsMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void listOutputConverterBean() {
List<ActorsFilms> actorsFilms = ChatClient.create(this.chatModel).prompt()
.user("Generate the filmography of 5 movies for Tom Hanks and Bill Murray.")
.call()
.entity(new ParameterizedTypeReference<List<ActorsFilms>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down Expand Up @@ -156,7 +156,7 @@ void mapOutputConverter() {
.user(u -> u.text("Provide me a List of {subject}")
.param("subject", "an array of numbers from 1 to 9 under they key name 'numbers'"))
.call()
.entity(new ParameterizedTypeReference<Map<String, Object>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OpenAiChatModelTypeReferenceBeanOutputConverterIT extends AbstractIT {
void typeRefOutputConverterRecords() {

BeanOutputConverter<List<ActorsFilmsRecord>> outputConverter = new BeanOutputConverter<>(
new ParameterizedTypeReference<List<ActorsFilmsRecord>>() {
new ParameterizedTypeReference<>() {

});

Expand Down Expand Up @@ -78,7 +78,7 @@ void typeRefOutputConverterRecords() {
void typeRefStreamOutputConverterRecords() {

BeanOutputConverter<List<ActorsFilmsRecord>> outputConverter = new BeanOutputConverter<>(
new ParameterizedTypeReference<List<ActorsFilmsRecord>>() {
new ParameterizedTypeReference<>() {

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void transactionPaymentStatuses(String functionName) {
What is the status of my payment transactions 001, 002 and 003?
""")
.call()
.entity(new ParameterizedTypeReference<List<TransactionStatusResponse>>() {
.entity(new ParameterizedTypeReference<>() {

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void listOutputConverterString() {
.user(u -> u.text("List five {subject}")
.param("subject", "ice cream flavors"))
.call()
.entity(new ParameterizedTypeReference<List<String>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand All @@ -140,7 +140,7 @@ void listOutputConverterBean() {
List<ActorsFilms> actorsFilms = ChatClient.create(this.chatModel).prompt()
.user("Generate the filmography of 5 movies for Tom Hanks and Bill Murray.")
.call()
.entity(new ParameterizedTypeReference<List<ActorsFilms>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down Expand Up @@ -173,7 +173,7 @@ void mapOutputConverter() {
.user(u -> u.text("Provide me a List of {subject}")
.param("subject", "an array of numbers from 1 to 9 under they key name 'numbers'"))
.call()
.entity(new ParameterizedTypeReference<Map<String, Object>>() {
.entity(new ParameterizedTypeReference<>() {
});
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ public DefaultCallResponseSpec(ChatClientRequest chatClientRequest, BaseAdvisorC
@Override
public <T> ResponseEntity<ChatResponse, T> responseEntity(Class<T> type) {
Assert.notNull(type, "type cannot be null");
return doResponseEntity(new BeanOutputConverter<T>(type));
return doResponseEntity(new BeanOutputConverter<>(type));
}

@Override
public <T> ResponseEntity<ChatResponse, T> responseEntity(ParameterizedTypeReference<T> type) {
Assert.notNull(type, "type cannot be null");
return doResponseEntity(new BeanOutputConverter<T>(type));
return doResponseEntity(new BeanOutputConverter<>(type));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void parametrizedResponseEntityTest() {
.prompt()
.user("Tell me about them")
.call()
.responseEntity(new ParameterizedTypeReference<List<MyBean>>() {
.responseEntity(new ParameterizedTypeReference<>() {

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ public String format(Document document, MetadataMode metadataMode) {
protected Map<String, Object> metadataFilter(Map<String, Object> metadata, MetadataMode metadataMode) {

if (metadataMode == MetadataMode.ALL) {
return new HashMap<String, Object>(metadata);
return new HashMap<>(metadata);
}
if (metadataMode == MetadataMode.NONE) {
return new HashMap<String, Object>(Collections.emptyMap());
return new HashMap<>(Collections.emptyMap());
}

Set<String> usableMetadataKeys = new HashSet<>(metadata.keySet());
Expand All @@ -139,7 +139,7 @@ else if (metadataMode == MetadataMode.EMBED) {
usableMetadataKeys.removeAll(this.excludedEmbedMetadataKeys);
}

return new HashMap<String, Object>(metadata.entrySet()
return new HashMap<>(metadata.entrySet()
.stream()
.filter(e -> usableMetadataKeys.contains(e.getKey()))
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<Document> get() {
}

private Document parseJsonNode(JsonNode jsonNode, ObjectMapper objectMapper) {
Map<String, Object> item = objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {
Map<String, Object> item = objectMapper.convertValue(jsonNode, new TypeReference<>() {

});
var sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void shouldNotAcceptNullVariables() {
void shouldNotAcceptVariablesWithNullKeySet() {
NoOpTemplateRenderer renderer = new NoOpTemplateRenderer();
String template = "Hello!";
Map<String, Object> variables = new HashMap<String, Object>();
Map<String, Object> variables = new HashMap<>();
variables.put(null, "Spring AI");

assertThatThrownBy(() -> renderer.apply(template, variables)).isInstanceOf(IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public Flux<ChatResponse> aggregate(Flux<ChatResponse> fluxChatResponse,
ChatGenerationMetadata.NULL);

// Usage
AtomicReference<Integer> metadataUsagePromptTokensRef = new AtomicReference<Integer>(0);
AtomicReference<Integer> metadataUsageGenerationTokensRef = new AtomicReference<Integer>(0);
AtomicReference<Integer> metadataUsageTotalTokensRef = new AtomicReference<Integer>(0);
AtomicReference<Integer> metadataUsagePromptTokensRef = new AtomicReference<>(0);
AtomicReference<Integer> metadataUsageGenerationTokensRef = new AtomicReference<>(0);
AtomicReference<Integer> metadataUsageTotalTokensRef = new AtomicReference<>(0);

AtomicReference<PromptMetadata> metadataPromptMetadataRef = new AtomicReference<>(PromptMetadata.empty());
AtomicReference<RateLimit> metadataRateLimitRef = new AtomicReference<>(new EmptyRateLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Float[] toFloatArray(final float[] array) {

public static List<Float> toList(float[] floats) {

List<Float> output = new ArrayList<Float>();
List<Float> output = new ArrayList<>();
for (float value : floats) {
output.add(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public abstract class ModelOptionsUtils {

private static final List<String> BEAN_MERGE_FIELD_EXCISIONS = List.of("class");

private static final ConcurrentHashMap<Class<?>, List<String>> REQUEST_FIELD_NAMES_PER_CLASS = new ConcurrentHashMap<Class<?>, List<String>>();
private static final ConcurrentHashMap<Class<?>, List<String>> REQUEST_FIELD_NAMES_PER_CLASS = new ConcurrentHashMap<>();

private static final AtomicReference<SchemaGenerator> SCHEMA_GENERATOR_CACHE = new AtomicReference<>();

private static TypeReference<HashMap<String, Object>> MAP_TYPE_REF = new TypeReference<HashMap<String, Object>>() {
private static TypeReference<HashMap<String, Object>> MAP_TYPE_REF = new TypeReference<>() {

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void shouldNotAcceptNullVariables() {
void shouldNotAcceptVariablesWithNullKeySet() {
StTemplateRenderer renderer = StTemplateRenderer.builder().build();
String template = "Hello!";
Map<String, Object> variables = new HashMap<String, Object>();
Map<String, Object> variables = new HashMap<>();
variables.put(null, "Spring AI");

assertThatThrownBy(() -> renderer.apply(template, variables)).isInstanceOf(IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void initializeContainer(String containerName, String databaseName, int

// handle hierarchical partition key
PartitionKeyDefinition subPartitionKeyDefinition = new PartitionKeyDefinition();
List<String> pathsFromCommaSeparatedList = new ArrayList<String>();
List<String> pathsFromCommaSeparatedList = new ArrayList<>();
String[] subPartitionKeyPaths = partitionKeyPath.split(",");
Collections.addAll(pathsFromCommaSeparatedList, subPartitionKeyPaths);
if (subPartitionKeyPaths.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public List<Document> doSimilaritySearch(SearchRequest request) {
final AzureSearchDocument entry = result.getDocument(AzureSearchDocument.class);

Map<String, Object> metadata = (StringUtils.hasText(entry.metadata()))
? JSONObject.parseObject(entry.metadata(), new TypeReference<Map<String, Object>>() {
? JSONObject.parseObject(entry.metadata(), new TypeReference<>() {

}) : Map.of();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public EmbeddingModel embeddingModel() {

@Bean
public Converter<MimeType, String> mimeTypeToStringConverter() {
return new Converter<MimeType, String>() {
return new Converter<>() {

@Override
public String convert(MimeType source) {
Expand All @@ -361,7 +361,7 @@ public String convert(MimeType source) {

@Bean
public Converter<String, MimeType> stringToMimeTypeConverter() {
return new Converter<String, MimeType>() {
return new Converter<>() {

@Override
public MimeType convert(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public EmbeddingModel embeddingModel() {

@Bean
public Converter<MimeType, String> mimeTypeToStringConverter() {
return new Converter<MimeType, String>() {
return new Converter<>() {

@Override
public String convert(MimeType source) {
Expand All @@ -225,7 +225,7 @@ public String convert(MimeType source) {

@Bean
public Converter<String, MimeType> stringToMimeTypeConverter() {
return new Converter<String, MimeType>() {
return new Converter<>() {

@Override
public MimeType convert(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public List<Document> doSimilaritySearch(SearchRequest request) {
public List<Double> embeddingDistance(String query) {
return this.jdbcTemplate.query(
"SELECT embedding " + this.comparisonOperator() + " ? AS distance FROM " + getFullyQualifiedTableName(),
new RowMapper<Double>() {
new RowMapper<>() {

@Override
public Double mapRow(ResultSet rs, int rowNum) throws SQLException {
Expand Down
Loading