Skip to content

Commit

Permalink
refactor: use diamond operator
Browse files Browse the repository at this point in the history
Co-authored-by: Moderne <team@moderne.io>
  • Loading branch information
gregorriegler and TeamModerne committed Jun 16, 2021
1 parent dc65995 commit 0c84c9b
Show file tree
Hide file tree
Showing 34 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ public String getStatusPageUrl() {
*/
@JsonIgnore
public Set<String> getHealthCheckUrls() {
Set<String> healthCheckUrlSet = new LinkedHashSet<String>();
Set<String> healthCheckUrlSet = new LinkedHashSet<>();
if (this.isUnsecurePortEnabled && healthCheckUrl != null && !healthCheckUrl.isEmpty()) {
healthCheckUrlSet.add(healthCheckUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractAzToRegionMapper implements AzToRegionMapper {
Multimaps.newListMultimap(new HashMap<String, Collection<String>>(), new Supplier<List<String>>() {
@Override
public List<String> get() {
return new ArrayList<String>();
return new ArrayList<>();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public List<String> getEurekaServerServiceUrls(String myZone) {
return Arrays.asList(serviceUrls.split(URL_SEPARATOR));
}

return new ArrayList<String>();
return new ArrayList<>();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class DiscoveryClient implements EurekaClient {
private final Provider<HealthCheckHandler> healthCheckHandlerProvider;
private final Provider<HealthCheckCallback> healthCheckCallbackProvider;
private final PreRegistrationHandler preRegistrationHandler;
private final AtomicReference<Applications> localRegionApps = new AtomicReference<Applications>();
private final AtomicReference<Applications> localRegionApps = new AtomicReference<>();
private final Lock fetchRegistryUpdateLock = new ReentrantLock();
// monotonically increasing generation counter to ensure stale threads do not reset registry to an older version
private final AtomicLong fetchRegistryGeneration;
Expand Down Expand Up @@ -354,7 +354,7 @@ public synchronized BackupRegistry get() {

fetchRegistryGeneration = new AtomicLong(0);

remoteRegionsToFetch = new AtomicReference<String>(clientConfig.fetchRegistryForRemoteRegions());
remoteRegionsToFetch = new AtomicReference<>(clientConfig.fetchRegistryForRemoteRegions());
remoteRegionsRef = new AtomicReference<>(remoteRegionsToFetch.get() == null ? null : remoteRegionsToFetch.get().split(","));

if (config.shouldFetchRegistry()) {
Expand Down Expand Up @@ -403,7 +403,7 @@ public synchronized BackupRegistry get() {

heartbeatExecutor = new ThreadPoolExecutor(
1, clientConfig.getHeartbeatExecutorThreadPoolSize(), 0, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new SynchronousQueue<>(),
new ThreadFactoryBuilder()
.setNameFormat("DiscoveryClient-HeartbeatExecutor-%d")
.setDaemon(true)
Expand All @@ -412,7 +412,7 @@ public synchronized BackupRegistry get() {

cacheRefreshExecutor = new ThreadPoolExecutor(
1, clientConfig.getCacheRefreshExecutorThreadPoolSize(), 0, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new SynchronousQueue<>(),
new ThreadFactoryBuilder()
.setNameFormat("DiscoveryClient-CacheRefreshExecutor-%d")
.setDaemon(true)
Expand Down Expand Up @@ -635,7 +635,7 @@ public Set<String> getAllKnownRegions() {
String localRegion = instanceRegionChecker.getLocalRegion();
if (!remoteRegionVsApps.isEmpty()) {
Set<String> regions = remoteRegionVsApps.keySet();
Set<String> toReturn = new HashSet<String>(regions);
Set<String> toReturn = new HashSet<>(regions);
toReturn.add(localRegion);
return toReturn;
} else {
Expand Down Expand Up @@ -775,7 +775,7 @@ public List<InstanceInfo> getInstancesByVipAddress(String vipAddress, boolean se
public List<InstanceInfo> getInstancesByVipAddressAndAppName(
String vipAddress, String appName, boolean secure) {

List<InstanceInfo> result = new ArrayList<InstanceInfo>();
List<InstanceInfo> result = new ArrayList<>();
if (vipAddress == null && appName == null) {
throw new IllegalArgumentException(
"Supplied VIP Address and application name cannot both be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InstanceInfoReplicator implements Runnable {
.setDaemon(true)
.build());

this.scheduledPeriodicRef = new AtomicReference<Future>();
this.scheduledPeriodicRef = new AtomicReference<>();

this.started = new AtomicBoolean(false);
this.rateLimiter = new RateLimiter(TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public PropertyBasedAzToRegionMapper(EurekaClientConfig clientConfig) {

@Override
protected Set<String> getZonesForARegion(String region) {
return new HashSet<String>(Arrays.asList(clientConfig.getAvailabilityZones(region)));
return new HashSet<>(Arrays.asList(clientConfig.getAvailabilityZones(region)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws
}
}

Set<String> cnamesSet = new TreeSet<String>();
Set<String> cnamesSet = new TreeSet<>();
if (txtRecord == null || txtRecord.trim().isEmpty()) {
return cnamesSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static List<String> getServiceUrlsFromDNS(EurekaClientConfig clientConfig
// list of available zones
Map<String, List<String>> zoneDnsNamesMap = getZoneBasedDiscoveryUrlsFromRegion(clientConfig, region);
Set<String> availableZones = zoneDnsNamesMap.keySet();
List<String> zones = new ArrayList<String>(availableZones);
List<String> zones = new ArrayList<>(availableZones);
if (zones.isEmpty()) {
throw new RuntimeException("No available zones configured for the instanceZone " + instanceZone);
}
Expand Down Expand Up @@ -136,10 +136,10 @@ public static List<String> getServiceUrlsFromDNS(EurekaClientConfig clientConfig
}

// Now get the eureka urls for all the zones in the order and return it
List<String> serviceUrls = new ArrayList<String>();
List<String> serviceUrls = new ArrayList<>();
for (String zone : zones) {
for (String zoneCname : zoneDnsNamesMap.get(zone)) {
List<String> ec2Urls = new ArrayList<String>(getEC2DiscoveryUrlsFromZone(zoneCname, DiscoveryUrlType.CNAME));
List<String> ec2Urls = new ArrayList<>(getEC2DiscoveryUrlsFromZone(zoneCname, DiscoveryUrlType.CNAME));
// Rearrange the list to distribute the load in case of multiple servers
if (ec2Urls.size() > 1) {
randomizer.randomize(ec2Urls);
Expand Down Expand Up @@ -188,7 +188,7 @@ public static List<String> getServiceUrlsFromDNS(EurekaClientConfig clientConfig
* @return The list of all eureka service urls for the eureka client to talk to
*/
public static List<String> getServiceUrlsFromConfig(EurekaClientConfig clientConfig, String instanceZone, boolean preferSameZone) {
List<String> orderedUrls = new ArrayList<String>();
List<String> orderedUrls = new ArrayList<>();
String region = getRegion(clientConfig);
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
if (availZones == null || availZones.length == 0) {
Expand Down Expand Up @@ -284,7 +284,7 @@ public static Set<String> getEC2DiscoveryUrlsFromZone(String dnsName, DiscoveryU
if (DiscoveryUrlType.CNAME.equals(type)) {
return ec2UrlsForZone;
}
eipsForZone = new TreeSet<String>();
eipsForZone = new TreeSet<>();
for (String cname : ec2UrlsForZone) {
String[] tokens = cname.split("\\.");
String ec2HostName = tokens[0];
Expand Down Expand Up @@ -319,7 +319,7 @@ public static Map<String, List<String>> getZoneBasedDiscoveryUrlsFromRegion(Eure
discoveryDnsName = "txt." + region + "." + clientConfig.getEurekaServerDNSName();

logger.debug("The region url to be looked up is {} :", discoveryDnsName);
Set<String> zoneCnamesForRegion = new TreeSet<String>(DnsResolver.getCNamesFromTxtRecord(discoveryDnsName));
Set<String> zoneCnamesForRegion = new TreeSet<>(DnsResolver.getCNamesFromTxtRecord(discoveryDnsName));
Map<String, List<String>> zoneCnameMapForRegion = new TreeMap<String, List<String>>();
for (String zoneCname : zoneCnamesForRegion) {
String zone = null;
Expand All @@ -336,7 +336,7 @@ public static Map<String, List<String>> getZoneBasedDiscoveryUrlsFromRegion(Eure
}
List<String> zoneCnamesSet = zoneCnameMapForRegion.get(zone);
if (zoneCnamesSet == null) {
zoneCnamesSet = new ArrayList<String>();
zoneCnamesSet = new ArrayList<>();
zoneCnameMapForRegion.put(zone, zoneCnamesSet);
}
zoneCnamesSet.add(zoneCname);
Expand Down
8 changes: 4 additions & 4 deletions eureka-client/src/main/java/com/netflix/discovery/shared/Application.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public String toString() {
private final Map<String, InstanceInfo> instancesMap;

public Application() {
instances = new LinkedHashSet<InstanceInfo>();
instances = new LinkedHashSet<>();
instancesMap = new ConcurrentHashMap<String, InstanceInfo>();
shuffledInstances = new AtomicReference<List<InstanceInfo>>();
shuffledInstances = new AtomicReference<>();
}

public Application(String name) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public List<InstanceInfo> getInstances() {
@JsonIgnore
public List<InstanceInfo> getInstancesAsIsFromEureka() {
synchronized (instances) {
return new ArrayList<InstanceInfo>(this.instances);
return new ArrayList<>(this.instances);
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ private void _shuffleAndStoreInstances(boolean filterUpInstances, boolean indexB
@Nullable InstanceRegionChecker instanceRegionChecker) {
List<InstanceInfo> instanceInfoList;
synchronized (instances) {
instanceInfoList = new ArrayList<InstanceInfo>(instances);
instanceInfoList = new ArrayList<>(instances);
}
boolean remoteIndexingActive = indexByRemoteRegions && null != instanceRegionChecker && null != clientConfig
&& null != remoteRegionsRegistry;
Expand Down
8 changes: 4 additions & 4 deletions eureka-client/src/main/java/com/netflix/discovery/shared/Applications.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Applications {
private static class VipIndexSupport {
final AbstractQueue<InstanceInfo> instances = new ConcurrentLinkedQueue<>();
final AtomicLong roundRobinIndex = new AtomicLong(0);
final AtomicReference<List<InstanceInfo>> vipList = new AtomicReference<List<InstanceInfo>>(Collections.emptyList());
final AtomicReference<List<InstanceInfo>> vipList = new AtomicReference<>(Collections.emptyList());

public AtomicLong getRoundRobinIndex() {
return roundRobinIndex;
Expand Down Expand Up @@ -103,7 +103,7 @@ public Applications() {
public Applications(@JsonProperty("appsHashCode") String appsHashCode,
@JsonProperty("versionDelta") Long versionDelta,
@JsonProperty("application") List<Application> registeredApplications) {
this.applications = new ConcurrentLinkedQueue<Application>();
this.applications = new ConcurrentLinkedQueue<>();
this.appNameApplicationMap = new ConcurrentHashMap<String, Application>();
this.virtualHostNameAppMap = new ConcurrentHashMap<String, VipIndexSupport>();
this.secureVirtualHostNameAppMap = new ConcurrentHashMap<String, VipIndexSupport>();
Expand Down Expand Up @@ -134,7 +134,7 @@ public void addApplication(Application app) {
*/
@JsonProperty("application")
public List<Application> getRegisteredApplications() {
return new ArrayList<Application>(this.applications);
return new ArrayList<>(this.applications);
}

/**
Expand Down Expand Up @@ -358,7 +358,7 @@ private void shuffleAndFilterInstances(Map<String, VipIndexSupport> srcMap, bool
filteredInstances = vipInstances.stream().filter(ii -> ii.getStatus() == InstanceStatus.UP)
.collect(Collectors.toCollection(() -> new ArrayList<>(vipInstances.size())));
} else {
filteredInstances = new ArrayList<InstanceInfo>(vipInstances);
filteredInstances = new ArrayList<>(vipInstances);
}
Collections.shuffle(filteredInstances, shuffleRandom);
vipIndexSupport.vipList.set(filteredInstances);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public AsyncResolver(String name,

this.threadPoolExecutor = new ThreadPoolExecutor(
1, executorThreadPoolSize, 0, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(), // use direct handoff
new SynchronousQueue<>(), // use direct handoff
new ThreadFactoryBuilder()
.setNameFormat("AsyncResolver-" + name + "-executor-%d")
.setDaemon(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static ClusterResolver<EurekaEndpoint> fromURL(String regionName, URL ser
int defaultPort = isSecure ? 443 : 80;
int port = serviceUrl.getPort() == -1 ? defaultPort : serviceUrl.getPort();

return new StaticClusterResolver<EurekaEndpoint>(
return new StaticClusterResolver<>(
regionName,
new DefaultEndpoint(serviceUrl.getHost(), port, isSecure, serviceUrl.getPath())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public static EurekaHttpResponseBuilder<Void> anEurekaHttpResponse(int statusCod
}

public static <T> EurekaHttpResponseBuilder<T> anEurekaHttpResponse(int statusCode, Class<T> entityType) {
return new EurekaHttpResponseBuilder<T>(statusCode);
return new EurekaHttpResponseBuilder<>(statusCode);
}

public static <T> EurekaHttpResponseBuilder<T> anEurekaHttpResponse(int statusCode, T entity) {
return new EurekaHttpResponseBuilder<T>(statusCode).entity(entity);
return new EurekaHttpResponseBuilder<>(statusCode).entity(entity);
}

public static class EurekaHttpResponseBuilder<T> {
Expand Down Expand Up @@ -128,7 +128,7 @@ public EurekaHttpResponseBuilder<T> headers(Map<String, String> headers) {
}

public EurekaHttpResponse<T> build() {
return new EurekaHttpResponse<T>(this);
return new EurekaHttpResponse<>(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static Applications deepCopyApplications(Applications source) {
public static Applications mergeApplications(Applications first, Applications second) {
Set<String> firstNames = selectApplicationNames(first);
Set<String> secondNames = selectApplicationNames(second);
Set<String> allNames = new HashSet<String>(firstNames);
Set<String> allNames = new HashSet<>(firstNames);
allNames.addAll(secondNames);

Applications merged = new Applications();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setUp() throws Exception {
@Test
public void testStatusChangeEvent() throws Exception {
final CountDownLatch eventLatch = new CountDownLatch(1);
final List<StatusChangeEvent> receivedEvents = new ArrayList<StatusChangeEvent>();
final List<StatusChangeEvent> receivedEvents = new ArrayList<>();
EventBus eventBus = discoveryClientResource.getEventBus();
eventBus.registerSubscriber(new Object() {
@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public void before() {

@Test
public void testHealthCheckCallbackGuiceProvider() {
args.setHealthCheckCallbackProvider(new GuiceProvider<HealthCheckCallback>());
args.setHealthCheckCallbackProvider(new GuiceProvider<>());
}

@Test
public void testHealthCheckCallbackJavaxProvider() {
args.setHealthCheckCallbackProvider(new JavaxProvider<HealthCheckCallback>());
args.setHealthCheckCallbackProvider(new JavaxProvider<>());
}

@Test
public void testHealthCheckHandlerGuiceProvider() {
args.setHealthCheckHandlerProvider(new GuiceProvider<HealthCheckHandler>());
args.setHealthCheckHandlerProvider(new GuiceProvider<>());
}

@Test
public void testHealthCheckHandlerJavaxProvider() {
args.setHealthCheckHandlerProvider(new JavaxProvider<HealthCheckHandler>());
args.setHealthCheckHandlerProvider(new JavaxProvider<>());
}

private class JavaxProvider<T> implements Provider<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MockRemoteEurekaServer extends ExternalResource {
private final AtomicBoolean sentRegistry = new AtomicBoolean();

public final BlockingQueue<String> registrationStatusesQueue = new LinkedBlockingQueue<>();
public final List<String> registrationStatuses = new ArrayList<String>();
public final List<String> registrationStatuses = new ArrayList<>();

public final AtomicLong registerCount = new AtomicLong(0);
public final AtomicLong heartbeatCount = new AtomicLong(0);
Expand Down Expand Up @@ -327,4 +327,4 @@ protected void sleep(int seconds) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void setUp() {
3, // maxPoolSize
0, // keepAliveTime
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>()); // use direct handoff
new SynchronousQueue<>()); // use direct handoff

testTaskStartCounter = new AtomicLong(0);
testTaskSuccessfulCounter = new AtomicLong(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class CodecLoadTester {

private final List<InstanceInfo> instanceInfoList = new ArrayList<InstanceInfo>();
private final List<Application> applicationList = new ArrayList<Application>();
private final List<InstanceInfo> instanceInfoList = new ArrayList<>();
private final List<Application> applicationList = new ArrayList<>();
private final Applications applications;

private final EntityBodyConverter xstreamCodec = new EntityBodyConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void setUp() throws IOException {
when(transportConfig.getSessionedClientReconnectIntervalSeconds()).thenReturn(10);

writeServer = new SimpleEurekaHttpServer(writeRequestHandler);
clusterResolver = new StaticClusterResolver<EurekaEndpoint>("regionA", new DefaultEndpoint("localhost", writeServer.getServerPort(), false, "/v2/"));
clusterResolver = new StaticClusterResolver<>("regionA", new DefaultEndpoint("localhost", writeServer.getServerPort(), false, "/v2/"));

readServer = new SimpleEurekaHttpServer(readRequestHandler);
readServerURI = "http://localhost:" + readServer.getServerPort();
Expand Down Expand Up @@ -302,4 +302,4 @@ public boolean await(long timeout, TimeUnit unit) throws Exception {
return latch.await(timeout, unit);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public Set<String> getRemoteRegionAppWhitelist(@Nullable String regionName) {
} else {
String appWhiteListStr = appWhiteListProp.get();
String[] whitelistEntries = appWhiteListStr.split(",");
return new HashSet<String>(Arrays.asList(whitelistEntries));
return new HashSet<>(Arrays.asList(whitelistEntries));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ private static HttpServletRequest addGzipAcceptEncoding(HttpServletRequest reque
@Override
public Enumeration<String> getHeaders(String name) {
if (HttpHeaders.ACCEPT_ENCODING.equals(name)) {
return new EnumWrapper<String>("gzip");
return new EnumWrapper<>("gzip");
}
return super.getHeaders(name);
}

@Override
public Enumeration<String> getHeaderNames() {
return new EnumWrapper<String>(super.getHeaderNames(), HttpHeaders.ACCEPT_ENCODING);
return new EnumWrapper<>(super.getHeaderNames(), HttpHeaders.ACCEPT_ENCODING);
}

@Override
Expand Down
Loading

0 comments on commit 0c84c9b

Please sign in to comment.