Skip to content

Commit da89e60

Browse files
committed
apply suggestions
1 parent ab684c1 commit da89e60

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

internal-api/src/main/java/datadog/trace/api/remoteconfig/ServiceNameCollector.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
import datadog.trace.api.Config;
66
import java.util.ArrayList;
7-
import java.util.HashSet;
87
import java.util.List;
9-
import java.util.Locale;
108
import java.util.Set;
9+
import java.util.TreeSet;
1110
import java.util.concurrent.ConcurrentHashMap;
1211
import javax.annotation.Nullable;
1312
import org.slf4j.Logger;
@@ -19,9 +18,6 @@ public class ServiceNameCollector {
1918

2019
private static final int MAX_EXTRA_SERVICE = Config.get().getRemoteConfigMaxExtraServices();
2120

22-
private static final String SERVICE_NAME_LOWERCASE =
23-
Config.get().getServiceName().toLowerCase(Locale.ROOT);
24-
2521
// This is not final to allow mocking it on tests
2622
private static ServiceNameCollector INSTANCE = new ServiceNameCollector();
2723

@@ -67,16 +63,10 @@ public List<String> getServices() {
6763
if (services.isEmpty()) {
6864
return null;
6965
}
70-
final Set<String> uniques = new HashSet<>(services.size());
71-
// avoids reiterating again to convert a set to a list
72-
final ArrayList<String> ret = new ArrayList<>(services.size());
73-
for (String current : services.keySet()) {
74-
String lowerCase = current.toLowerCase(Locale.ROOT);
75-
if (!SERVICE_NAME_LOWERCASE.equals(lowerCase) && uniques.add(lowerCase)) {
76-
ret.add(current);
77-
}
78-
}
79-
return ret.isEmpty() ? null : ret;
66+
final Set<String> uniqueNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
67+
uniqueNames.addAll(services.keySet());
68+
uniqueNames.remove(Config.get().getServiceName());
69+
return uniqueNames.isEmpty() ? null : new ArrayList<>(uniqueNames);
8070
}
8171

8272
public void clear() {

0 commit comments

Comments
 (0)