Skip to content

Commit

Permalink
Use diamond operator where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Dec 17, 2024
1 parent 1888868 commit ed1eec4
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ private void fetchLiveInstanceData(boolean force) throws AmazonClientException {
* when fetchLiveInstanceData() is called before pushLiveInstancedata().
*/
if (!i.getTags().isEmpty()) {
tags = new LinkedList<EC2Tag>();
tags = new LinkedList<>();
for (Tag t : i.getTags()) {
tags.add(new EC2Tag(t.getKey(), t.getValue()));
}
Expand All @@ -918,7 +918,7 @@ protected void clearLiveInstancedata() throws AmazonClientException {

/* Now that we have our instance, we can clear the tags on it */
if (!tags.isEmpty()) {
HashSet<Tag> instTags = new HashSet<Tag>();
HashSet<Tag> instTags = new HashSet<>();

for (EC2Tag t : tags) {
instTags.add(new Tag(t.getName(), t.getValue()));
Expand Down Expand Up @@ -946,7 +946,7 @@ protected void pushLiveInstancedata() throws AmazonClientException {

/* Now that we have our instance, we can set tags on it */
if (inst != null && tags != null && !tags.isEmpty()) {
HashSet<Tag> instTags = new HashSet<Tag>();
HashSet<Tag> instTags = new HashSet<>();

for (EC2Tag t : tags) {
instTags.add(new Tag(t.getName(), t.getValue()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ void attemptReattachOrphanOrStoppedNodes(Jenkins jenkinsInstance, SlaveTemplate
private PlannedNode createPlannedNode(final SlaveTemplate t, final EC2AbstractSlave slave) {
return new PlannedNode(
t.getDisplayName(),
Computer.threadPoolForRemoting.submit(new Callable<Node>() {
Computer.threadPoolForRemoting.submit(new Callable<>() {
int retryCount = 0;
private static final int DESCRIBE_LIMIT = 2;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/EC2Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static List<EC2Tag> fromAmazonTags(List<Tag> amazonTags) {
return null;
}

LinkedList<EC2Tag> result = new LinkedList<EC2Tag>();
LinkedList<EC2Tag> result = new LinkedList<>();
for (Tag t : amazonTags) {
result.add(new EC2Tag(t));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class InstanceTypeConverter implements Converter {

private static final Map<String, InstanceType> TYPICAL_INSTANCE_TYPES = new HashMap<String, InstanceType>();
private static final Map<String, InstanceType> TYPICAL_INSTANCE_TYPES = new HashMap<>();

static {
TYPICAL_INSTANCE_TYPES.put("DEFAULT", InstanceType.M1Small);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private DeviceMappingParser() {}

public static List<BlockDeviceMapping> parse(String customDeviceMapping) {

List<BlockDeviceMapping> deviceMappings = new ArrayList<BlockDeviceMapping>();
List<BlockDeviceMapping> deviceMappings = new ArrayList<>();

for (String mapping : customDeviceMapping.split(",")) {
String[] mappingPair = mapping.split("=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testSpotInstanceCount() throws Exception {
when(spotSlaveMock.getSpotRequest()).thenReturn(null);
when(spotSlaveMock.getSpotInstanceRequestId()).thenReturn("sir-id");

List<Instance> instances = new ArrayList<Instance>();
List<Instance> instances = new ArrayList<>();
for (int i = 0; i <= numberOfSpotInstanceRequests; i++) {
instances.add(new Instance()
.withInstanceId("id" + i)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/hudson/plugins/ec2/CloudHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testGetInstanceWithRetryInstanceNotFound() throws Exception {
AmazonServiceException amazonServiceException = new AmazonServiceException("test exception");
amazonServiceException.setErrorCode("InvalidInstanceID.NotFound");

Answer<DescribeInstancesResult> answerWithRetry = new Answer<DescribeInstancesResult>() {
Answer<DescribeInstancesResult> answerWithRetry = new Answer<>() {
private boolean first = true;

@Override
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testGetInstanceWithRetryRequestExpired() throws Exception {
AmazonServiceException amazonServiceException = new AmazonServiceException("test exception");
amazonServiceException.setErrorCode("RequestExpired");

Answer<DescribeInstancesResult> answerWithRetry = new Answer<DescribeInstancesResult>() {
Answer<DescribeInstancesResult> answerWithRetry = new Answer<>() {
private boolean first = true;

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/hudson/plugins/ec2/EC2AbstractSlaveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.amazonaws.services.ec2.model.InstanceType;
import hudson.model.Node;
import hudson.slaves.NodeProperty;
import java.util.ArrayList;
import java.util.List;
import org.junit.Rule;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void testGetLaunchTimeoutInMillisShouldNotOverflow() throws Exception {
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"root",
"java",
"jvm",
Expand Down Expand Up @@ -137,7 +136,7 @@ public void testMaxUsesBackwardCompat() throws Exception {
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"root",
"jvm",
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.security.Permission;
import hudson.slaves.NodeProperty;
import hudson.slaves.OfflineCause;
import java.time.Clock;
import java.time.Duration;
Expand Down Expand Up @@ -231,7 +230,7 @@ private EC2Computer computerWithIdleTime(
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"remote",
"jvm",
false,
Expand Down Expand Up @@ -356,7 +355,7 @@ private EC2Computer computerWithUpTime(
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"remote",
"jvm",
false,
Expand Down Expand Up @@ -502,7 +501,7 @@ private EC2Computer computerWithUsageLimit(final int usageLimit) throws Exceptio
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"remote",
"jvm",
false,
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/hudson/plugins/ec2/SlaveTemplateUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CreateTagsResult createTags(com.amazonaws.services.ec2.model.CreateTagsRe

EC2Tag tag1 = new EC2Tag("name1", "value1");
EC2Tag tag2 = new EC2Tag("name2", "value2");
List<EC2Tag> tags = new ArrayList<EC2Tag>();
List<EC2Tag> tags = new ArrayList<>();
tags.add(tag1);
tags.add(tag2);
String instanceId = "123";
Expand Down Expand Up @@ -98,7 +98,7 @@ protected Object readResolve() {
}
};

ArrayList<Tag> awsTags = new ArrayList<Tag>();
ArrayList<Tag> awsTags = new ArrayList<>();
awsTags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "value1"));
awsTags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "value2"));

Expand Down Expand Up @@ -127,7 +127,7 @@ public CreateTagsResult createTags(com.amazonaws.services.ec2.model.CreateTagsRe

EC2Tag tag1 = new EC2Tag("name1", "value1");
EC2Tag tag2 = new EC2Tag("name2", "value2");
List<EC2Tag> tags = new ArrayList<EC2Tag>();
List<EC2Tag> tags = new ArrayList<>();
tags.add(tag1);
tags.add(tag2);
String instanceId = "123";
Expand Down Expand Up @@ -169,7 +169,7 @@ protected Object readResolve() {
}
};

ArrayList<Tag> awsTags = new ArrayList<Tag>();
ArrayList<Tag> awsTags = new ArrayList<>();
awsTags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "value1"));
awsTags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "value2"));

Expand Down Expand Up @@ -985,7 +985,7 @@ public void testConnectionStrategyDeprecatedFieldsAreExported() {
}

class TestHandler extends Handler {
private final List<LogRecord> records = new LinkedList<LogRecord>();
private final List<LogRecord> records = new LinkedList<>();

@Override
public void close() throws SecurityException {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import hudson.plugins.ec2.InstanceState;
import hudson.plugins.ec2.SlaveTemplate;
import hudson.plugins.ec2.util.ConnectionRule;
import hudson.slaves.NodeProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -365,7 +364,7 @@ private static MockEC2Computer createComputer(String suffix) throws Exception {
null,
"init",
"tmpDir",
new ArrayList<NodeProperty<?>>(),
new ArrayList<>(),
"remote",
"jvm",
false,
Expand Down

0 comments on commit ed1eec4

Please sign in to comment.