@Override public void notifyOfRemovedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); synchronized (this) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); final Integer count = collectorWithCount.getValue(); final Collector collector = collectorWithCount.getKey(); removeMetric(metric, dimensionValues, collector); if (count == 1) { try { CollectorRegistry.defaultRegistry.unregister(collector); } catch (Exception e) { log.warn("There was a problem unregistering metric {}.", scopedMetricName, e); } collectorsWithCountByMetricName.remove(scopedMetricName); } else { collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count - 1)); } } }
@Override public void notifyOfAddedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionKeys = new LinkedList<>(); List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { final String key = dimension.getKey(); dimensionKeys.add(CHARACTER_FILTER.filterCharacters(key.substring(1, key.length() - 1))); dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); final String helpString = metricName + " (scope: " + getLogicalScope(group) + ")"; final Collector collector; Integer count = 0; synchronized (this) { if (collectorsWithCountByMetricName.containsKey(scopedMetricName)) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); collector = collectorWithCount.getKey(); count = collectorWithCount.getValue(); } else { collector = createCollector(metric, dimensionKeys, dimensionValues, scopedMetricName, helpString); try { collector.register(); } catch (Exception e) { log.warn("There was a problem registering metric {}.", metricName, e); } } addMetric(metric, dimensionValues, collector); collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count + 1)); } }
.skip(position) .findFirst() .map(entry -> getPoint(new Geoshape(entry.getKey()), entry.getValue())) .orElse(null); default:
/** * add multiple metadata entries * * @param data the metadata to add */ public void addAll(final List<SimpleImmutableEntry<String, String>> data){ for(final SimpleImmutableEntry<String, String> entry : data){ this.add(entry.getKey(), entry.getValue()); } }
private static String rewrite (String text, SimpleImmutableEntry<Pattern,String>[] patterns) { String x = text; Matcher m; for (SimpleImmutableEntry<Pattern,String> pair : patterns) x = pair.getKey().matcher(x).replaceAll(pair.getValue()); return x.trim(); }
private static Map.Entry<Long, Integer> parseConcat(String concat) { int pos = concat.indexOf(CONCAT_SEPARATOR); Preconditions.checkArgument(pos > 0 && pos < concat.length() - 1, "%s value '%s' is invalid.", KEY_CONCAT, concat); String count = concat.substring(0, pos); String offset = concat.substring(pos + CONCAT_SEPARATOR.length()); try { val result = new AbstractMap.SimpleImmutableEntry<Long, Integer>(Long.parseLong(offset), Integer.parseInt(count)); Preconditions.checkArgument(result.getKey() >= 0 && result.getValue() >= 0, "%s value '%s' is invalid.", KEY_CONCAT, concat); return result; } catch (NumberFormatException nfe) { throw new IllegalArgumentException(String.format("%s value '%s' is invalid.", KEY_CONCAT, concat), nfe); } }
public Map<Language, String> getForI18nKey(String i18nKey) { return translations.entrySet().stream() .map(entry -> new SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTranslation(i18nKey))) .filter(pair -> pair.getValue().isPresent()) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().get())); }
@Override public Map<String, String> getNamespaces() { final Map<String, String> namespaces = new HashMap<>(); jdbi.useHandle(handle -> handle.select("SELECT prefix, namespace FROM namespaces") .map((rs, ctx) -> new SimpleImmutableEntry<>(rs.getString("prefix"), rs.getString("namespace"))) .forEach(pair -> namespaces.put(pair.getKey(), pair.getValue()))); return namespaces; }
@Override public List<AppRegistration> importAll(boolean overwrite, Resource... resources) { return Stream.of(resources) .map(this::loadProperties) .flatMap(prop -> prop.entrySet().stream() .map(toStringAndUriFunc) .flatMap(kv -> toValidAppRegistration(kv, metadataUriFromProperties(kv.getKey(), prop))) .filter(a -> isOverwrite(a, overwrite)) .map(ar -> save(ar))) .collect(Collectors.toList()); }
private static String getPayloadOxum(final Bag bag){ for(final SimpleImmutableEntry<String,String> keyValue : bag.getMetadata().getAll()){ if("Payload-Oxum".equals(keyValue.getKey())){ return keyValue.getValue(); } } return null; }
void completeComponentProperties(Map<String, String> properties) { componentProperties.forEach(entry -> properties.put(entry.getKey(), extractAssetMetadata(entry.getValue(), properties))); String dbValue = properties.getOrDefault(calciteProperties.get(0), ""); String tableValue = properties.getOrDefault(calciteProperties.get(1), ""); properties.put(calciteProperties.get(0), dbValue); properties.put(calciteProperties.get(1), tableValue); }
private static void writeResults (BufferedWriter writer, String query, KBest kbest) throws Exception { DecimalFormat formatter = new DecimalFormat("#.####"); for (SimpleImmutableEntry<String,Double> pair : kbest.toArray()) { writer.write(query + "\t" + pair.getKey() + "\t" + formatter.format(pair.getValue())); writer.newLine(); } }
protected ReactiveHttpRequest buildRequest(Object[] argv) { Map<String, ?> substitutionsMap = methodMetadata.indexToName().entrySet().stream() .flatMap(e -> e.getValue().stream() .map(v -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), v))) .collect(Collectors.toMap(Map.Entry::getValue, entry -> argv[entry.getKey()])); HttpMethod method = HttpMethod.resolve(methodMetadata.template().method()); URI uri = defaultUriBuilderFactory.uriString(methodMetadata.template().url()) .queryParams(parameters(argv)).build(substitutionsMap); return new ReactiveHttpRequest(method, uri, headers(argv, substitutionsMap), body(argv)); }
@Override public List<AppRegistration> importAll(boolean overwrite, Resource... resources) { return Stream.of(resources) .map(this::loadProperties) .flatMap(prop -> prop.entrySet().stream() .map(toStringAndUriFunc) .flatMap(kv -> toValidAppRegistration(kv, metadataUriFromProperties(kv.getKey(), prop))) .filter(a -> isOverwrite(a, overwrite)) .map(ar -> save(ar))) .collect(Collectors.toList()); }
public List<String> dump() { cleanUpOldExceptions(); final ImmutableList.Builder<String> builder = ImmutableList.builder(); for( final SimpleImmutableEntry<ZonedDateTime, Throwable> entry : timestampedThrowables ) { builder.add(entry.getKey() + " " + entry.getValue()); } return builder.build(); }
if (clientTLSProps != null) { clientCert = clientTLSProps.getValue(); clientKey = clientTLSProps.getKey();
/** * Splits the query string in * * @param url * @return */ Map<String, String> getParametersFromUrl(String url) { // url.getQuery won't work on file addresses int idx = url.indexOf("?"); if (idx == -1 || idx == url.length() - 1) { return Collections.emptyMap(); } String query = url.substring(idx + 1); return Arrays.stream(query.split("&")) .map(this::splitQueryParameter) .filter(e -> e.getValue() != null) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v2)); }
/** * Splits the query string in * * @param url * @return */ Map<String, String> getParametersFromUrl(String url) { // url.getQuery won't work on file addresses int idx = url.indexOf("?"); if (idx == -1 || idx == url.length() - 1) { return Collections.emptyMap(); } String query = url.substring(idx + 1); return Arrays.stream(query.split("&")) .map(this::splitQueryParameter) .filter(e -> e.getValue() != null) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v2)); }
@Override public SimpleImmutableEntry<String, Integer> visit(Node node) { @SuppressWarnings("unchecked") SimpleImmutableEntry<String, Integer> leftResult = (SimpleImmutableEntry<String, Integer>) node.left().accept(this); @SuppressWarnings("unchecked") SimpleImmutableEntry<String, Integer> rightResult = (SimpleImmutableEntry<String, Integer>) node.right().accept(this); int leftDepth = leftResult.getValue(); int rightDepth = rightResult.getValue(); return leftDepth >= rightDepth ? new SimpleImmutableEntry<>(leftResult.getKey(), 1 + leftDepth) : new SimpleImmutableEntry<>(rightResult.getKey(), 1 + rightDepth); } }
@GET @Path("{token}/update/{pin}") @Consumes(value = MediaType.APPLICATION_JSON) @Metric(HTTP_UPDATE_PIN_DATA) public Response updateWidgetPinDataViaGet(@PathParam("token") String token, @PathParam("pin") String pinString, @QueryParam("value") String[] pinValues, @EnumQueryParam(WidgetProperty.class) AbstractMap.SimpleImmutableEntry<WidgetProperty, String> widgetProperty) { if (pinValues != null) { return updateWidgetPinData(token, pinString, pinValues); } if (widgetProperty != null) { return updateWidgetProperty(token, pinString, widgetProperty.getKey(), widgetProperty.getValue()); } return badRequest("Wrong request format."); }