Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Dec 18, 2024
1 parent ab684c1 commit da89e60
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import datadog.trace.api.Config;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import org.slf4j.Logger;
Expand All @@ -19,9 +18,6 @@ public class ServiceNameCollector {

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

private static final String SERVICE_NAME_LOWERCASE =
Config.get().getServiceName().toLowerCase(Locale.ROOT);

// This is not final to allow mocking it on tests
private static ServiceNameCollector INSTANCE = new ServiceNameCollector();

Expand Down Expand Up @@ -67,16 +63,10 @@ public List<String> getServices() {
if (services.isEmpty()) {
return null;
}
final Set<String> uniques = new HashSet<>(services.size());
// avoids reiterating again to convert a set to a list
final ArrayList<String> ret = new ArrayList<>(services.size());
for (String current : services.keySet()) {
String lowerCase = current.toLowerCase(Locale.ROOT);
if (!SERVICE_NAME_LOWERCASE.equals(lowerCase) && uniques.add(lowerCase)) {
ret.add(current);
}
}
return ret.isEmpty() ? null : ret;
final Set<String> uniqueNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
uniqueNames.addAll(services.keySet());
uniqueNames.remove(Config.get().getServiceName());
return uniqueNames.isEmpty() ? null : new ArrayList<>(uniqueNames);
}

public void clear() {
Expand Down

0 comments on commit da89e60

Please sign in to comment.