Skip to content

Commit

Permalink
Use the Java 7 diamond operator everywhere. (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjni authored Jun 24, 2021
1 parent 96f4057 commit b8fadff
Show file tree
Hide file tree
Showing 687 changed files with 4,568 additions and 4,634 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ When updating the changelog, remember to be very clear about what behavior has c
and what APIs have changed, if applicable.

## [Unreleased]
- Use the Java 7 diamond operator everywhere.

## [29.19.4] - 2021-06-23
- Do not apply Idea and Eclipse plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public URI measureBoundedLoad_firstFull_MPCHash_100Hosts_21Probes(BoundedLoad_MP

@State(Scope.Benchmark)
public static class ConsistentHashRing_10Hosts_100PointsPerHost_State {
Ring<URI> _ring = new ConsistentHashRing<URI>(buildPointsMap(10, 100));
Ring<URI> _ring = new ConsistentHashRing<>(buildPointsMap(10, 100));
Random _random = new Random();
}

Expand Down Expand Up @@ -247,7 +247,7 @@ public URI measureBoundedLoad_firstFull_ConsistentHashRing_10Hosts_100PointsPerH

@State(Scope.Benchmark)
public static class ConsistentHashRing_100Hosts_100PointsPerHost_State {
Ring<URI> _ring = new ConsistentHashRing<URI>(buildPointsMap(100, 100));
Ring<URI> _ring = new ConsistentHashRing<>(buildPointsMap(100, 100));
Random _random = new Random();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Future<RestResponse> restRequest(RestRequest request, String routeKey)
public Future<RestResponse> restRequest(final RestRequest request, final RequestContext requestContext,
String routekey)
{
final FutureCallback<String> futureCallback = new FutureCallback<String>();
final FutureCallback<String> futureCallback = new FutureCallback<>();
String originalServiceName = LoadBalancerUtil.getServiceNameFromUri(request.getURI());
String resultServiceName;
_routeLookup.run(originalServiceName, _routingGroup, routekey, futureCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.linkedin.d2.contrib;

import com.linkedin.common.callback.FutureCallback;
import com.linkedin.common.util.None;
import com.linkedin.d2.balancer.D2Client;
import com.linkedin.d2.balancer.D2ClientBuilder;
import com.linkedin.r2.message.rest.RestRequest;
Expand Down Expand Up @@ -49,14 +48,14 @@ public void testSimpleRouteLookup() throws ExecutionException, InterruptedExcept
{
RouteLookup routeLookup = new SimpleTestRouteLookup();

FutureCallback<String> futureCallback = new FutureCallback<String>();
FutureCallback<String> futureCallback = new FutureCallback<>();
String serviceName = "BarBar";
routeLookup.run(serviceName, null, "1",futureCallback);

String resultString = futureCallback.get();
Assert.assertEquals(resultString, serviceName + "1" + "Foo");

futureCallback = new FutureCallback<String>();
futureCallback = new FutureCallback<>();
routeLookup.run(serviceName, "blah", "2",futureCallback);
resultString = futureCallback.get();
Assert.assertEquals(resultString, serviceName + "blah" + "2" + "Foo");
Expand All @@ -68,7 +67,7 @@ public void testRouteLookupClientFuture() throws ExecutionException, Interrupted
RouteLookup routeLookup = new SimpleTestRouteLookup();

final D2Client d2Client = new D2ClientBuilder().setZkHosts("localhost:2121").build();
d2Client.start(new FutureCallback<None>());
d2Client.start(new FutureCallback<>());
RouteLookupClient routeLookupClient = new RouteLookupClient(d2Client, routeLookup, "WestCoast");
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("d2://simple_uri")).build();
Future<RestResponse> future = routeLookupClient.restRequest(dummyRestRequest, "5436");
Expand Down Expand Up @@ -97,10 +96,10 @@ public void testRouteLookupClientCallback()
RouteLookup routeLookup = new SimpleTestRouteLookup();

final D2Client d2Client = new D2ClientBuilder().setZkHosts("localhost:2121").build();
d2Client.start(new FutureCallback<None>());
d2Client.start(new FutureCallback<>());
RouteLookupClient routeLookupClient = new RouteLookupClient(d2Client, routeLookup, "WestCoast");
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("d2://simple_uri")).build();
FutureCallback<RestResponse> futureCallback = new FutureCallback<RestResponse>();
FutureCallback<RestResponse> futureCallback = new FutureCallback<>();
routeLookupClient.restRequest(dummyRestRequest,futureCallback, "5555");

try
Expand All @@ -124,7 +123,7 @@ public void testBadRequest()
RouteLookup routeLookup = new SimpleTestRouteLookup();

final D2Client d2Client = new D2ClientBuilder().setZkHosts("localhost:2121").build();
d2Client.start(new FutureCallback<None>());
d2Client.start(new FutureCallback<>());
RouteLookupClient routeLookupClient = new RouteLookupClient(d2Client, routeLookup, "WestCoast");
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("http://simple_uri")).build();
try
Expand Down
14 changes: 7 additions & 7 deletions d2-int-test/src/test/java/com/linkedin/d2/D2BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public Map<String,AtomicInteger> sendRequests(int num,

public Map<String, List<String>> generateClusterData(String[] clusters, int addOn)
{
Map<String, List<String>> clustersData = new HashMap<String, List<String>> ();
Map<String, List<String>> clustersData = new HashMap<>();

for (int i=0; i < clusters.length; i++)
{
Expand All @@ -276,8 +276,8 @@ public Map<String, List<String>> generateClusterData(String[] clusters, int add

public Map<String, Object> generatePartitionProperties(String regex, int keyRangeStart, int partitionCount, int partitionSize, String type)
{
final Map<String, Object> partitionProperties = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<String, Object>();
final Map<String, Object> partitionProperties = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("partitionKeyRegex", regex);
map.put("keyRangeStart", String.valueOf(keyRangeStart));
map.put("partitionCount", String.valueOf(partitionCount));
Expand All @@ -290,7 +290,7 @@ public Map<String, Object> generatePartitionProperties(String regex, int keyRang

protected <T> Map<LoadBalancerEchoServer,T> createLatencyDataHash(List<LoadBalancerEchoServer> servers, T[] latency)
{
Map<LoadBalancerEchoServer,T> hash = new HashMap<LoadBalancerEchoServer,T>();
Map<LoadBalancerEchoServer,T> hash = new HashMap<>();
int count = 0;
for (LoadBalancerEchoServer server: servers)
{
Expand All @@ -308,13 +308,13 @@ protected <T> Map<LoadBalancerEchoServer,T> createLatencyDataHash(List<LoadBalan

protected static Map<LoadBalancerEchoServer,Map<Integer, Double>> createServerWeightDataMap(List<LoadBalancerEchoServer> servers, int partitionId, Double[] weight)
{
Map<LoadBalancerEchoServer,Map<Integer, Double>> hash = new HashMap<LoadBalancerEchoServer,Map<Integer, Double>>();
Map<LoadBalancerEchoServer,Map<Integer, Double>> hash = new HashMap<>();
int count = 0;
for (LoadBalancerEchoServer server: servers)
{
if (count < weight.length)
{
Map<Integer, Double> partitionWeight = new HashMap<Integer, Double> ();
Map<Integer, Double> partitionWeight = new HashMap<>();
partitionWeight.put(Integer.valueOf(partitionId), weight[count]);
hash.put(server, partitionWeight);
count++;
Expand Down Expand Up @@ -344,7 +344,7 @@ protected void assertServersWeighSetup(Map<LoadBalancerEchoServer,Map<Integer, D

protected Map<Integer,AtomicInteger> generateHostResponseCountMap(Map<String,String> responses)
{
Map<Integer,AtomicInteger> res = new HashMap<Integer,AtomicInteger>();
Map<Integer,AtomicInteger> res = new HashMap<>();

res.put(Integer.valueOf(ECHO_SERVER_PORT1_1), new AtomicInteger(0));
res.put(Integer.valueOf(ECHO_SERVER_PORT1_2), new AtomicInteger(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void setup() throws IOException, Exception
_zkPort = _zkServer.getPort();
_zkHosts = ZK_HOST+":" + _zkPort;
_zkUriString = "zk://"+_zkHosts;

// Register clusters/services (two services per cluster)
LoadBalancerClientCli.runDiscovery(_zkHosts, "/d2", D2_CONFIG_DATA);

// Get LoadBalancer Client
_cli = new LoadBalancerClientCli(_zkHosts, "/d2");

Expand Down Expand Up @@ -235,7 +235,7 @@ public void testEchoServerMarkDownUp() throws IOException, InterruptedException,
// Echo Server mark up
_echoServers.get(1).markUp();
_echoServers.get(2).markUp();

msg = generateMessage(_zkUriString);
expectedResponses = getExpectedResponses(0, msg);

Expand Down Expand Up @@ -297,7 +297,7 @@ private String getExpectedResponse(int partitionId, String msg, String postfix)

private void startAllEchoServers() throws Exception
{
_echoServers = new ArrayList<LoadBalancerEchoServer>();
_echoServers = new ArrayList<>();
_echoServers.add(startEchoServer(ZK_HOST, _zkPort, ECHO_SERVER_HOST, ECHO_SERVER_PORT1, "cluster-1", "service-1_1", "service-1_2", "service-1_3" ));
_echoServers.add(startEchoServer(ZK_HOST, _zkPort, ECHO_SERVER_HOST, ECHO_SERVER_PORT2, "cluster-1", "service-1_1", "service-1_2", "service-1_3" ));
_echoServers.add(startEchoServer(ZK_HOST, _zkPort, ECHO_SERVER_HOST, ECHO_SERVER_PORT3, "cluster-2", "service-2_1", "service-2_2", "service-2_3" ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testRegisterUnregisterDefaultPartitionEchoServers() throws IOExcepti
InterruptedException,
Exception
{
_echoServers = new ArrayList<LoadBalancerEchoServer>();
_echoServers = new ArrayList<>();
setup();
assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DEFAULT_PARTITION_DATA), 0);
_cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
Expand All @@ -109,13 +109,13 @@ public void testRegisterUnregisterCustomPartitionEchoServers() throws IOExceptio
InterruptedException,
Exception
{
_echoServers = new ArrayList<LoadBalancerEchoServer>();
_echoServers = new ArrayList<>();
setup();
assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_CUSTOM_PARTITION_DATA), 0);
_cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
_client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
// Echo servers startup
Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
Map<Integer, Double> partitionWeight = new HashMap<>();
partitionWeight.put(Integer.valueOf(1), Double.valueOf(1.0d));
startCustomPartitionEchoServers(partitionWeight);
assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
Expand All @@ -135,13 +135,13 @@ public void testRegisterUnregisterAllEchoServers() throws IOException,
InterruptedException,
Exception
{
_echoServers = new ArrayList<LoadBalancerEchoServer>();
_echoServers = new ArrayList<>();
setup();
assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DATA), 0);
_cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
_client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
// Echo servers startup
Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
Map<Integer, Double> partitionWeight = new HashMap<>();
partitionWeight.put(Integer.valueOf(1), Double.valueOf(1.0d));
startAllEchoServers(partitionWeight);
assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ private void assertQuorumProcessAllRequests(String clustersData) throws Exceptio

private void startAllEchoServers() throws Exception
{
_echoServers = new ArrayList<LoadBalancerEchoServer>();
Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
_echoServers = new ArrayList<>();
Map<Integer, Double> partitionWeight = new HashMap<>();
partitionWeight.put(Integer.valueOf(1), Double.valueOf(1.0d));
_echoServers.add(startEchoServer(getHost(_zkHosts[0]), getPort(_zkHosts[0]), ECHO_SERVER_HOST, ECHO_SERVER_PORT1_1, "cluster-1", "service-1_1", "service-1_2", "service-1_3" ));
_echoServers.add(startEchoServer(getHost(_zkHosts[0]), getPort(_zkHosts[0]), ECHO_SERVER_HOST, ECHO_SERVER_PORT1_2, "cluster-1", "service-1_1", "service-1_2", "service-1_3" ));
Expand Down
12 changes: 5 additions & 7 deletions d2-int-test/src/test/java/com/linkedin/d2/quorum/ZKQuorum.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.linkedin.d2.quorum;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -51,10 +49,10 @@ public class ZKQuorum
* @param n - number of peers in the ensemble ( for test stability, set peer number in a quorum to 7+ (7, 9 or 11) )
*/

public ZKQuorum(int ttlPeersCount) throws IOException, Exception
public ZKQuorum(int ttlPeersCount) throws Exception
{
_peers = new HashMap<Integer, ZKPeer>();
_peersView = new HashMap<Long, QuorumServer>();
_peers = new HashMap<>();
_peersView = new HashMap<>();
_peerCount = ttlPeersCount;
_hosts = "";

Expand Down Expand Up @@ -225,7 +223,7 @@ private boolean isExists(int id)
return false;
}

public void restart(int id) throws IOException, Exception
public void restart(int id) throws Exception
{
_log.info("Restarting peer #" + getQuorumPeerPortsInfo(id));
_peers.get(id).shutdown(false);
Expand All @@ -248,7 +246,7 @@ public void restartPeersInTerminatedState() throws Exception
waitForAllPeersUp();
}

public void startAll() throws IOException, Exception
public void startAll() throws Exception
{
for (int id=1; id <= _peerCount; id++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public class LatencyMetric {
* - read happens on previously put aside current, once read is completed, the histogram is reset
* and put back as inactive
*/
private AtomicReference<AbstractHistogram> _current = new AtomicReference<AbstractHistogram>(
private AtomicReference<AbstractHistogram> _current = new AtomicReference<>(
new ShortCountsHistogram(LOWEST_DISCERNIBLE_VALUE, HIGHEST_TRACKABLE_VALUE, NUMBER_OF_SIGNIFICANT_VALUE_DIGITS));

private AtomicReference<AbstractHistogram> _inactive = new AtomicReference<AbstractHistogram>(
private AtomicReference<AbstractHistogram> _inactive = new AtomicReference<>(
new ShortCountsHistogram(LOWEST_DISCERNIBLE_VALUE, HIGHEST_TRACKABLE_VALUE, NUMBER_OF_SIGNIFICANT_VALUE_DIGITS));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public D2ClientBuilder setDeterministicSubsettingMetadataProvider(DeterministicS

private Map<String, TransportClientFactory> createDefaultTransportClientFactories()
{
final Map<String, TransportClientFactory> clientFactories = new HashMap<String, TransportClientFactory>();
final Map<String, TransportClientFactory> clientFactories = new HashMap<>();
TransportClientFactory transportClientFactory = new HttpClientFactory.Builder().build();
clientFactories.put("http", transportClientFactory);
clientFactories.put("https", transportClientFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Future<RestResponse> restRequest(RestRequest request)
@Override
public Future<RestResponse> restRequest(RestRequest request, RequestContext requestContext)
{
final FutureCallback<RestResponse> future = new FutureCallback<RestResponse>();
final FutureCallback<RestResponse> future = new FutureCallback<>();
restRequest(request, requestContext, future);
return future;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public DegraderTrackerClientImpl(URI uri, Map<Integer, PartitionData> partitionD
* However, now it becomes harder to have different configurations for different partitions.
*/
int mapSize = partitionDataMap.size();
Map<Integer, PartitionState>partitionStates = new HashMap<Integer, PartitionState>(mapSize * 2);
Map<Integer, PartitionState>partitionStates = new HashMap<>(mapSize * 2);
config.setName("TrackerClient Degrader: " + uri);
DegraderImpl degrader = new DegraderImpl(config);
DegraderControl degraderControl = new DegraderControl(degrader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void writeConfig() throws ExecutionException, TimeoutException, Interrupt
{
long startTime = System.currentTimeMillis();

FutureCallback<None> callback = new FutureCallback<None>();
FutureCallback<None> callback = new FutureCallback<>();
_store.start(callback);
callback.get(_timeout, _timeoutUnit);

Expand Down Expand Up @@ -116,7 +116,7 @@ public void onError(Throwable e)
throw new TimeoutException();
}

FutureCallback<None> shutdownCallback = new FutureCallback<None>();
FutureCallback<None> shutdownCallback = new FutureCallback<>();
_store.shutdown(shutdownCallback);
shutdownCallback.get(_timeout, _timeoutUnit);

Expand All @@ -134,7 +134,7 @@ public static Map<String,Object> merge(Map<String,Object> source, Map<String,Obj
{
defaultMap = Collections.emptyMap();
}
Map<String,Object> result = new HashMap<String,Object>(defaultMap);
Map<String, Object> result = new HashMap<>(defaultMap);
for (String key : source.keySet())
{
Object sourceValue = source.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PartitionDataFactory
{
public static Map<Integer, PartitionData> createPartitionDataMap(Map<String, Object> sourceMap)
{
Map<Integer, PartitionData> map = new HashMap<Integer, PartitionData>();
Map<Integer, PartitionData> map = new HashMap<>();
if (sourceMap != null)
{
for (Map.Entry<String, Object> entry : sourceMap.entrySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum AllowedClientPropertyKeys
private static final Set<String> _allowedKeys;
static
{
_allowedKeys = new HashSet<String>();
_allowedKeys = new HashSet<>();
for (AllowedClientPropertyKeys propertyKey: AllowedClientPropertyKeys.values())
{
_allowedKeys.add(propertyKey._keyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public ServiceProperties fromMap(Map<String,Object> map)
Set<URI> banned = new HashSet<>(bannedList);
List<String> prioritizedSchemes = mapGetOrDefault(map, PropertyKeys.PRIORITIZED_SCHEMES, Collections.emptyList());

Map<String, Object> metadataProperties = new HashMap<String,Object>();
Map<String, Object> metadataProperties = new HashMap<>();
String isDefaultService = mapGetOrDefault(map, PropertyKeys.IS_DEFAULT_SERVICE, null);
if ("true".equalsIgnoreCase(isDefaultService))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,22 @@ public UriProperties(String clusterName,
Map<URI, Map<String, Object>> uriSpecificProperties)
{
_clusterName = clusterName;
Map<URI, Map<Integer, PartitionData>> partitionDescriptionsMap = new HashMap<URI, Map<Integer, PartitionData>>(partitionDescriptions.size() * 2);
Map<URI, Map<Integer, PartitionData>> partitionDescriptionsMap = new HashMap<>(partitionDescriptions.size() * 2);
for (Map.Entry<URI, Map<Integer, PartitionData>> entry : partitionDescriptions.entrySet())
{
partitionDescriptionsMap.put(entry.getKey(), Collections.unmodifiableMap(
new HashMap<Integer, PartitionData>(entry.getValue())));
partitionDescriptionsMap.put(entry.getKey(), Collections.unmodifiableMap(new HashMap<>(entry.getValue())));
}
_partitionDesc = Collections.unmodifiableMap(partitionDescriptionsMap);

// group uris by scheme and partition
HashMap<String, Map<Integer, Set<URI>>> urisBySchemeAndPartition = new HashMap<String, Map<Integer, Set<URI>>>();
HashMap<String, Map<Integer, Set<URI>>> urisBySchemeAndPartition = new HashMap<>();
for (Map.Entry<URI, Map<Integer, PartitionData>> entry : _partitionDesc.entrySet())
{
final URI uri = entry.getKey();
Map<Integer, Set<URI>> map= urisBySchemeAndPartition.get(uri.getScheme());
if (map == null)
{
map = new HashMap<Integer, Set<URI>>();
map = new HashMap<>();
urisBySchemeAndPartition.put(uri.getScheme(), map);
}

Expand All @@ -72,7 +71,7 @@ public UriProperties(String clusterName,
Set<URI> uriSet = map.get(partitionId);
if (uriSet == null)
{
uriSet = new HashSet<URI>();
uriSet = new HashSet<>();
map.put(partitionId, uriSet);
}
uriSet.add(uri);
Expand Down
Loading

0 comments on commit b8fadff

Please sign in to comment.