Tabnine Logo
Map$Entry.comparingByKey
Code IndexAdd Tabnine to your IDE (free)

How to use
comparingByKey
method
in
java.util.Map$Entry

Best Java code snippets using java.util.Map$Entry.comparingByKey (Showing top 20 results out of 459)

origin: apache/incubator-druid

@VisibleForTesting
static String[] getFrequentLocations(final Stream<String> locations)
{
 final Map<String, Long> locationCountMap = locations.collect(
   Collectors.groupingBy(location -> location, Collectors.counting())
 );
 final Comparator<Map.Entry<String, Long>> valueComparator =
   Map.Entry.comparingByValue(Comparator.reverseOrder());
 final Comparator<Map.Entry<String, Long>> keyComparator =
   Map.Entry.comparingByKey();
 return locationCountMap
   .entrySet().stream()
   .sorted(valueComparator.thenComparing(keyComparator))
   .limit(3)
   .map(Map.Entry::getKey)
   .toArray(String[]::new);
}
origin: fesh0r/fernflower

 private List<String> packImports() {
  return mapSimpleNames.entrySet().stream()
   .filter(ent ->
        // exclude the current class or one of the nested ones
        // empty, java.lang and the current packages
        !setNotImportedNames.contains(ent.getKey()) &&
        !ent.getValue().isEmpty() &&
        !JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
        !ent.getValue().equals(currentPackagePoint)
   )
   .sorted(Map.Entry.<String, String>comparingByValue().thenComparing(Map.Entry.comparingByKey()))
   .map(ent -> ent.getValue() + "." + ent.getKey())
   .collect(Collectors.toList());
 }
}
origin: knowm/XChange

 @Override
 public String digestParams(RestInvocation restInvocation) {
  // Get Parameters
  Map<String, String> params = restInvocation.getParamsMap().get(FormParam.class).asHttpHeaders();

  // TODO: Find More Elegant Solution To Remove Sign
  // Order By Key Alphabetically, Concancecate Values
  byte[] unsigned =
    params
      .entrySet()
      .stream()
      .sorted(Map.Entry.<String, String>comparingByKey())
      .filter(e -> !e.getKey().equalsIgnoreCase("sign"))
      .map(e -> e.getValue())
      .collect(Collectors.joining())
      .getBytes();

  // TODO: Determine Charceter Encoding
  return String.valueOf(md5.digest(unsigned));
 }
}
origin: stackoverflow.com

Optional<Map.Entry<LocalDate, List<String>>> first = map
     .entrySet()
     .stream()
     .filter(entry -> entry.getValue().contains("Barry"))
     .sorted(Map.Entry.comparingByKey())
     .findFirst();
origin: uber/hudi

@Override
public List<HoodieCompactionOperation> orderAndFilter(HoodieWriteConfig writeConfig,
  List<HoodieCompactionOperation> operations, List<HoodieCompactionPlan> pendingCompactionPlans) {
 // Iterate through the operations and accept operations as long as we are within the configured target partitions
 // limit
 List<HoodieCompactionOperation> filteredList = operations.stream()
   .collect(Collectors.groupingBy(HoodieCompactionOperation::getPartitionPath)).entrySet().stream()
   .sorted(Map.Entry.comparingByKey(comparator)).limit(writeConfig.getTargetPartitionsPerDayBasedCompaction())
   .flatMap(e -> e.getValue().stream())
   .collect(Collectors.toList());
 return filteredList;
}
origin: OpenNMS/opennms

  @Override
  public Object execute() throws Exception {
    serviceDetectorRegistry.getTypes().entrySet().stream()
      .sorted(Map.Entry.<String, String>comparingByKey()) 
      .forEachOrdered(e -> {
        System.out.printf("%s: %s\n", e.getKey(), e.getValue());
      });
    return null;
  }
}
origin: jpos/jPOS

  public void dumpHistograms (File dir, String prefix) {
    metrics.entrySet()
     .stream()
     .sorted(Map.Entry.comparingByKey())
     .forEach(e -> dumpHistogram (dir, prefix + e.getKey(), e.getValue().copy()));
  }
}
origin: stackoverflow.com

String output = map.entrySet().stream()
   .sorted(Map.Entry.<String, Integer> comparingByValue()
    .reversed()
    .thenComparing(Map.Entry.comparingByKey())
    )
   .map(entry -> entry.getKey() + " - " + entry.getValue())
   .collect(joining());
origin: jpos/jPOS

public Map<String,Histogram> metrics() {
  return metrics.entrySet()
   .stream()
   .sorted(Map.Entry.comparingByKey())
   .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().copy()));
}
origin: OpenNMS/opennms

  @Override
  public Object execute() throws Exception {
    serviceDetectorRegistry.getTypes().entrySet().stream()
      .sorted(Map.Entry.<String, String>comparingByKey()) 
      .forEachOrdered(e -> {
        System.out.printf("%s: %s\n", e.getKey(), e.getValue());
      });
    return null;
  }
}
origin: apache/accumulo

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
  justification = "code runs in same security context as user who provided input")
@Override
public void execute(String[] args) throws Exception {
 Opts opts = new Opts();
 opts.parseArgs("accumulo convert-config", args);
 File xmlFile = new File(opts.xmlPath);
 if (!xmlFile.exists()) {
  throw new IllegalArgumentException("xml config file does not exist at " + opts.xmlPath);
 }
 Path propsPath = Paths.get(opts.propsPath);
 if (propsPath.toFile().exists()) {
  throw new IllegalArgumentException("properties file already exists at " + opts.propsPath);
 }
 Configuration xmlConfig = new Configuration(false);
 xmlConfig.addResource(xmlFile.toURI().toURL());
 try (BufferedWriter w = Files.newBufferedWriter(propsPath, Charset.forName("UTF-8"))) {
  StreamSupport.stream(xmlConfig.spliterator(), false).sorted(Map.Entry.comparingByKey())
    .forEach(e -> writeLine(w, e.toString()));
 }
}
origin: stackoverflow.com

Map.Entry<K,V> maxElt = map.entrySet().stream()
             .max(Map.Entry.comparingByKey())
             .orElse(...);
origin: diffplug/spotless

private static List<String> getImportOrder(File importsFile) {
  try (Stream<String> lines = Files.lines(importsFile.toPath())) {
    return lines.filter(line -> !line.startsWith("#"))
        // parse 0=input
        .map(ImportOrderStep::splitIntoIndexAndName)
        .sorted(Map.Entry.comparingByKey())
        .map(Map.Entry::getValue)
        .collect(Collectors.toCollection(ArrayList::new));
  } catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}
origin: apache/tinkerpop

@Override
public Collection<ImmutableMetrics> getMetrics() {
  return positionIndexedMetrics.entrySet().stream().sorted(Map.Entry.comparingByKey()).
      collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
      (oldValue, newValue) -> oldValue, LinkedHashMap::new)).values();
}
origin: knowm/XChange

@Override
public String digestParams(RestInvocation restInvocation) {
 String httpMethod = restInvocation.getHttpMethod();
 String host = getHost(restInvocation.getBaseUrl());
 String method = "/" + restInvocation.getMethodPath();
 String query =
   Stream.of(
       restInvocation.getParamsMap().get(FormParam.class),
       restInvocation.getParamsMap().get(QueryParam.class))
     .map(Params::asHttpHeaders)
     .map(Map::entrySet)
     .flatMap(Collection::stream)
     .filter(e -> !"Signature".equals(e.getKey()))
     .sorted(Map.Entry.comparingByKey())
     .map(e -> e.getKey() + "=" + encodeValue(e.getValue()))
     .collect(Collectors.joining("&"));
 String toSign = String.format("%s\n%s\n%s\n%s", httpMethod, host, method, query);
 Mac mac = getMac();
 String signature =
   encodeValue(Base64.getEncoder().encodeToString(mac.doFinal(toSign.getBytes())).trim());
 replaceSignatureUrl(restInvocation, signature);
 return signature;
}
origin: cloudfoundry/uaa

public static <K extends Comparable<? super K>, V extends Object> Map<K, V> sortByKeys(Map<K,V> map) {
  List<Entry<K, V>> sortedEntries = map
    .entrySet()
    .stream()
    .sorted(comparingByKey())
    .collect(Collectors.toList());
  LinkedHashMap<K, V> result = new LinkedHashMap<>();
  for (Map.Entry<K, V> entry : sortedEntries) {
    Object value = entry.getValue();
    if (value instanceof Map) {
      value = sortByKeys((Map) value);
    }
    result.put(entry.getKey(), (V)value);
  }
  return result;
}
origin: knowm/XChange

@Override
public String digestParams(RestInvocation restInvocation) {
 String method = restInvocation.getHttpMethod();
 String path = stripParams(restInvocation.getPath());
 String query =
   Stream.of(
       restInvocation.getParamsMap().get(PathParam.class),
       restInvocation.getParamsMap().get(FormParam.class))
     .map(Params::asHttpHeaders)
     .map(Map::entrySet)
     .flatMap(Collection::stream)
     .filter(e -> !"signature".equals(e.getKey()))
     .sorted(Entry.comparingByKey())
     .map(e -> e.getKey() + "=" + e.getValue())
     .collect(Collectors.joining("&"));
 String toSign = String.format("%s|/api/v2/%s|%s", method, path, query);
 Mac sha256hmac = getMac();
 byte[] signed = sha256hmac.doFinal(toSign.getBytes());
 String signature = new String(encodeHex(signed));
 replaceInvocationUrl(restInvocation, signature);
 return signature;
}
origin: confluentinc/ksql

private void printOverriddenProperties(final QueryDescription queryDescription) {
 final Map<String, Object> overriddenProperties = queryDescription.getOverriddenProperties();
 if (overriddenProperties.isEmpty()) {
  return;
 }
 final List<List<String>> rows = overriddenProperties.entrySet().stream()
   .sorted(Entry.comparingByKey())
   .map(prop -> Arrays.asList(prop.getKey(), "", Objects.toString(prop.getValue())))
   .collect(Collectors.toList());
 new Builder()
   .withColumnHeaders("Property", "Value")
   .withRows(rows)
   .withHeaderLine(String.format(
     "%n%-20s%n%-20s",
     "Overridden Properties",
     "---------------------"))
   .build()
   .print(this);
}
origin: codecentric/spring-boot-admin

protected Tuple2<String, Instant> getStatus(List<Instance> instances) {
  //TODO: Correct is just a second readmodel for groups
  Map<String, Instant> statusWithTime = instances.stream()
                          .collect(toMap(instance -> instance.getStatusInfo().getStatus(),
                            Instance::getStatusTimestamp,
                            this::getMax
                          ));
  if (statusWithTime.size() == 1) {
    Map.Entry<String, Instant> e = statusWithTime.entrySet().iterator().next();
    return Tuples.of(e.getKey(), e.getValue());
  }
  if (statusWithTime.containsKey(StatusInfo.STATUS_UP)) {
    Instant oldestNonUp = statusWithTime.entrySet()
                      .stream()
                      .filter(e -> !StatusInfo.STATUS_UP.equals(e.getKey()))
                      .map(Map.Entry::getValue)
                      .min(naturalOrder())
                      .orElse(Instant.EPOCH);
    Instant latest = getMax(oldestNonUp, statusWithTime.getOrDefault(StatusInfo.STATUS_UP, Instant.EPOCH));
    return Tuples.of(StatusInfo.STATUS_RESTRICTED, latest);
  }
  return statusWithTime.entrySet()
             .stream()
             .min(Map.Entry.comparingByKey(StatusInfo.severity()))
             .map(e -> Tuples.of(e.getKey(), e.getValue()))
             .orElse(Tuples.of(STATUS_UNKNOWN, Instant.EPOCH));
}
origin: stackoverflow.com

Map<K,V> topTen =
 map.entrySet().stream()
   .sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
   .limit(10)
   .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
java.utilMap$EntrycomparingByKey

Popular methods of Map$Entry

  • getValue
    Returns the value corresponding to this entry. If the mapping has been removed from the backing map
  • getKey
  • setValue
    Sets the value of this entry to the specified value, replacing any existing value.
  • equals
    Compares the specified object to this Map.Entry and returns if they are equal. To be equal, the obje
  • hashCode
    Returns an integer hash code for the receiver. Object which are equal return the same value for this
  • comparingByValue
  • <init>

Popular in Java

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • putExtra (Intent)
  • setScale (BigDecimal)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now