Skip to content

Commit

Permalink
refactor: use diamond operator
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorriegler committed Jun 16, 2021
1 parent dc65995 commit a4b2f98
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 37 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 @@ -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 @@ -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 @@ -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 @@ -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 Down
Empty file.
2 changes: 1 addition & 1 deletion 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
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 @@ -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
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 @@ -89,7 +89,7 @@ public class RateLimitingFilter implements Filter {

private static final Logger logger = LoggerFactory.getLogger(RateLimitingFilter.class);

private static final Set<String> DEFAULT_PRIVILEGED_CLIENTS = new HashSet<String>(
private static final Set<String> DEFAULT_PRIVILEGED_CLIENTS = new HashSet<>(
Arrays.asList(EurekaClientIdentity.DEFAULT_CLIENT_NAME, EurekaServerIdentity.DEFAULT_SERVER_NAME)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class AwsAsgUtil implements AsgClient {

private static final String accountId = getAccountId();

private Map<String, Credentials> stsCredentials = new HashMap<String, Credentials>();
private Map<String, Credentials> stsCredentials = new HashMap<>();

private final ExecutorService cacheReloadExecutor = new ThreadPoolExecutor(
1, 10, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
Expand Down Expand Up @@ -422,7 +422,7 @@ public void run() {
* @return the set of ASG cacheKeys (asgName + accountId).
*/
private Set<CacheKey> getCacheKeys() {
Set<CacheKey> cacheKeys = new HashSet<CacheKey>();
Set<CacheKey> cacheKeys = new HashSet<>();
Applications apps = registry.getApplicationsFromLocalRegionOnly();
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo instanceInfo : app.getInstances()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private Collection<String> getEIPsForZoneFromConfig(String myZone) {
* @return collection of EIPs.
*/
private Collection<String> getEIPsFromServiceUrls(List<String> ec2Urls) {
List<String> returnedUrls = new ArrayList<String>();
List<String> returnedUrls = new ArrayList<>();
String region = clientConfig.getRegion();
String regionPhrase = "";
if (!US_EAST_1.equals(region)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public abstract class AbstractInstanceRegistry implements InstanceRegistry {
// CircularQueues here for debugging/statistics purposes only
private final CircularQueue<Pair<Long, String>> recentRegisteredQueue;
private final CircularQueue<Pair<Long, String>> recentCanceledQueue;
private ConcurrentLinkedQueue<RecentlyChangedItem> recentlyChangedQueue = new ConcurrentLinkedQueue<RecentlyChangedItem>();
private ConcurrentLinkedQueue<RecentlyChangedItem> recentlyChangedQueue = new ConcurrentLinkedQueue<>();

private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
private final Lock read = readWriteLock.readLock();
Expand All @@ -99,7 +99,7 @@ public abstract class AbstractInstanceRegistry implements InstanceRegistry {
private Timer evictionTimer = new Timer("Eureka-EvictionTimer", true);
private final MeasuredRate renewsLastMin;

private final AtomicReference<EvictionTask> evictionTaskRef = new AtomicReference<EvictionTask>();
private final AtomicReference<EvictionTask> evictionTaskRef = new AtomicReference<>();

protected String[] allKnownRemoteRegions = EMPTY_STR_ARRAY;
protected volatile int numberOfRenewsPerMinThreshold;
Expand Down Expand Up @@ -228,7 +228,7 @@ public void register(InstanceInfo registrant, int leaseDuration, boolean isRepli
}
logger.debug("No previous lease information found; it is new registration");
}
Lease<InstanceInfo> lease = new Lease<InstanceInfo>(registrant, leaseDuration);
Lease<InstanceInfo> lease = new Lease<>(registrant, leaseDuration);
if (existingLease != null) {
lease.setServiceUpTimestamp(existingLease.getServiceUpTimestamp());
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public List<InstanceInfo> getInstancesById(String id) {
*/
@Deprecated
public List<InstanceInfo> getInstancesById(String id, boolean includeRemoteRegions) {
List<InstanceInfo> list = new ArrayList<InstanceInfo>();
List<InstanceInfo> list = new ArrayList<>();

for (Iterator<Entry<String, Map<String, Lease<InstanceInfo>>>> iter =
registry.entrySet().iterator(); iter.hasNext(); ) {
Expand All @@ -1086,7 +1086,7 @@ public List<InstanceInfo> getInstancesById(String id, boolean includeRemoteRegio
}

if (list == Collections.EMPTY_LIST) {
list = new ArrayList<InstanceInfo>();
list = new ArrayList<>();
}
list.add(decorateInstanceInfo(lease));
}
Expand Down Expand Up @@ -1163,7 +1163,7 @@ public int getNumOfRenewsPerMinThreshold() {
*/
@Override
public List<Pair<Long, String>> getLastNRegisteredInstances() {
List<Pair<Long, String>> list = new ArrayList<Pair<Long, String>>(recentRegisteredQueue);
List<Pair<Long, String>> list = new ArrayList<>(recentRegisteredQueue);
Collections.reverse(list);
return list;
}
Expand All @@ -1175,7 +1175,7 @@ public List<Pair<Long, String>> getLastNRegisteredInstances() {
*/
@Override
public List<Pair<Long, String>> getLastNCanceledInstances() {
List<Pair<Long, String>> list = new ArrayList<Pair<Long, String>>(recentCanceledQueue);
List<Pair<Long, String>> list = new ArrayList<>(recentCanceledQueue);
Collections.reverse(list);
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private void updateRenewalThreshold() {
*/
@Override
public List<Application> getSortedApplications() {
List<Application> apps = new ArrayList<Application>(getApplications().getRegisteredApplications());
List<Application> apps = new ArrayList<>(getApplications().getRegisteredApplications());
Collections.sort(apps, APP_COMPARATOR);
return apps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public class RemoteRegionRegistry implements LookupService<String> {
private final AtomicLong fetchRegistryGeneration = new AtomicLong(0);
private final Lock fetchRegistryUpdateLock = new ReentrantLock();

private final AtomicReference<Applications> applications = new AtomicReference<Applications>(new Applications());
private final AtomicReference<Applications> applicationsDelta = new AtomicReference<Applications>(new Applications());
private final AtomicReference<Applications> applications = new AtomicReference<>(new Applications());
private final AtomicReference<Applications> applicationsDelta = new AtomicReference<>(new Applications());
private final EurekaServerConfig serverConfig;
private volatile boolean readyForServingData;
private final EurekaHttpClient eurekaHttpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class AbstractTester {
public static final String LOCAL_REGION_INSTANCE_2_HOSTNAME = "blahloc2";
public static final String REMOTE_ZONE = "us-east-1c";

protected final List<Pair<String, String>> registeredApps = new ArrayList<Pair<String, String>>();
protected final Map<String, Application> remoteRegionApps = new HashMap<String, Application>();
protected final Map<String, Application> remoteRegionAppsDelta = new HashMap<String, Application>();
protected final List<Pair<String, String>> registeredApps = new ArrayList<>();
protected final Map<String, Application> remoteRegionApps = new HashMap<>();
protected final Map<String, Application> remoteRegionAppsDelta = new HashMap<>();

protected MockRemoteEurekaServer mockRemoteEurekaServer;
protected EurekaServerConfig serverConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ResultStatus call() throws Exception {
* @param task task to run.
*/
protected <T> AsyncResult<T> run(Callable<T> task) {
final AsyncResult<T> result = new ConcreteAsyncResult<T>();
final AsyncResult<T> result = new ConcreteAsyncResult<>();
new Thread(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Applications toApplications(Map<String, Application> applicationMa
}

public static Set<String> applicationNames(Applications applications) {
Set<String> names = new HashSet<String>();
Set<String> names = new HashSet<>();
for (Application application : applications.getRegisteredApplications()) {
names.add(application.getName());
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public static Application merge(Application first, Application second) {
public static Applications merge(Applications first, Applications second) {
Set<String> firstNames = applicationNames(first);
Set<String> secondNames = applicationNames(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 @@ -55,7 +55,7 @@ public Applications takeDelta(int count) {
currentIt = serviceIterator();
allApplications = new Applications();
}
List<InstanceInfo> instanceBatch = new ArrayList<InstanceInfo>();
List<InstanceInfo> instanceBatch = new ArrayList<>();
for (int i = 0; i < count; i++) {
InstanceInfo next = currentIt.next();
next.setActionType(ActionType.ADDED);
Expand Down

0 comments on commit a4b2f98

Please sign in to comment.