List of usage examples for java.util.function BiFunction apply
R apply(T t, U u);
From source file:com.yahoo.elide.parsers.state.RelationshipTerminalState.java
private Supplier<Pair<Integer, JsonNode>> handleRequest(StateContext state, BiFunction<Data<Resource>, RequestScope, Boolean> handler) { Data<Resource> data = state.getJsonApiDocument().getData(); handler.apply(data, state.getRequestScope()); return () -> Pair.of(HttpStatus.SC_NO_CONTENT, null); }
From source file:io.github.theangrydev.yatspeczohhakplugin.json.JsonCollectionsParameterCoercer.java
private Object coerceCollection(String stringToParse, Type actualTypeArgument, BiFunction<Type, Integer, CollectionBuilder> collectionBuilderConstructor) { JSONArray jsonArray = new JSONArray(stringToParse); int size = jsonArray.length(); CollectionBuilder collectionBuilder = collectionBuilderConstructor.apply(actualTypeArgument, size); for (int index = 0; index < size; index++) { Object element = coerceParameter(actualTypeArgument, jsonArray.get(index).toString()); collectionBuilder.add(element);//from w ww .ja v a2 s . co m } return collectionBuilder.build(); }
From source file:org.travis4j.model.json.AbstractJsonObject.java
public <T> List<T> toList(JSONArray array, boolean includeNulls, BiFunction<JSONArray, Integer, T> getter) { List<T> list = new ArrayList<>(array.length()); for (int i = 0; i < array.length(); i++) { if (!array.isNull(i) && !includeNulls) { list.add(getter.apply(array, i)); }/*from www . j ava2s . co m*/ } return list; }
From source file:org.sonar.api.config.ConfigurationTest.java
private <T> void verifySupportHeadAndOrTrailingWhitespaces(T value, BiFunction<Configuration, String, Optional<T>> t) { String randomKey = RandomStringUtils.randomAlphabetic(3); String randomNumberOfWhitespaces = StringUtils.repeat(" ", 1 + new Random().nextInt(10)); assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value)), randomKey)) .isEqualTo(Optional.of(value)); assertThat(t.apply(underTest.put(randomKey, String.valueOf(value) + randomNumberOfWhitespaces), randomKey)) .isEqualTo(Optional.of(value)); assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + String.valueOf(value) + randomNumberOfWhitespaces), randomKey)) .isEqualTo(Optional.of(value)); }
From source file:com.teradata.benchto.driver.listeners.benchmark.BenchmarkStatusReporter.java
private <T> void fireListeners(BiFunction<BenchmarkExecutionListener, T, Future<?>> invoker, T argument) { List<Future<?>> futures = new ArrayList<>(); for (BenchmarkExecutionListener listener : executionListeners) { futures.add(invoker.apply(listener, argument)); }//w w w. ja v a 2 s . co m pendingFutures.addAll(futures); }
From source file:nova.core.util.RayTracer.java
/** * Ray traces a cuboid/*from ww w .j a v a 2 s .co m*/ * @param cuboid The cuboid in absolute world coordinates * @return The ray trace result if the ray intersects the cuboid */ public <R extends RayTraceResult> Optional<R> rayTrace(Cuboid cuboid, BiFunction<Vector3D, Cuboid, R> resultMapper) { return rayTrace(cuboid, 0, distance).map(vec -> resultMapper.apply(vec, cuboid)); }
From source file:org.talend.dataprep.conversions.BeanConversionService.java
@Override public <T> T convert(Object source, Class<T> targetClass) { if (source == null) { return null; }/* w w w . java 2 s . c o m*/ try { T converted = targetClass.newInstance(); copyBean(source, converted); // Find registration Registration<T> registration = null; Class<?> currentSourceClass = source.getClass(); while (registration == null && !Object.class.equals(currentSourceClass)) { registration = registrations.get(currentSourceClass); currentSourceClass = currentSourceClass.getSuperclass(); } // Use registration if (registration != null) { List<BiFunction<Object, Object, Object>> customs = new ArrayList<>(); Class currentClass = targetClass; while (currentClass != null) { final BiFunction<Object, Object, Object> custom = registration.customs.get(currentClass); if (custom != null) { customs.add(custom); } currentClass = currentClass.getSuperclass(); } T result = converted; for (BiFunction<Object, Object, Object> current : customs) { result = (T) current.apply(source, converted); } return result; } else { return converted; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.icgc.dcc.portal.repository.FileRepository.java
private static TermFacet convertNormalAggregation(Aggregations aggregations, String name, BiFunction<Bucket, String, Long> docCountGetter) { val termsAgg = isNestedField(name) ? getSubAggResultFromNested(aggregations, name) : aggregations; val aggResult = (Terms) termsAgg.get(name); val termsBuilder = ImmutableList.<Term>builder(); long total = 0; for (val bucket : aggResult.getBuckets()) { val bucketKey = bucket.getKey(); val count = docCountGetter.apply(bucket, name); log.debug("convertNormalAggregation bucketKey: {}, count: {}", bucketKey, count); total += count;//from w w w . j av a2 s . c o m termsBuilder.add(new Term(bucketKey, count)); } val missingAgg = (Missing) termsAgg.get(MISSING); val missingCount = missingAgg.getDocCount(); log.debug("convertNormalAggregation Missing count is: {}", missingCount); // No need to return a term with a value of 0. if (missingCount > 0) { termsBuilder.add(new Term(MISSING, missingCount)); } return repoTermFacet(total, missingCount, termsBuilder.build()); }
From source file:org.thelq.pircbotx.commands.ModeCommands.java
protected final void addCommandChannelMode(char modeLetter, @NonNull String helpSuffix, boolean channelMode, @NonNull BiFunction<GenericEvent, ImmutableList<String>, String> argHandler) { addCommand("" + modeLetter, "Set channel " + helpSuffix, (event, channel, user, args) -> setChannelMode(event, channel, user, modeLetter, true, channelMode, argHandler.apply(event, args))); addCommand("-" + modeLetter, "Set channel " + helpSuffix, (event, channel, user, args) -> setChannelMode(event, channel, user, modeLetter, false, channelMode, argHandler.apply(event, args))); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesStatefulSetCachingAgent.java
@Override protected Map<KubernetesManifest, List<KubernetesManifest>> loadSecondaryResourceRelationships( List<KubernetesManifest> primaryResourceList) { BiFunction<String, String, String> manifestName = (namespace, name) -> namespace + ":" + name; Map<String, KubernetesManifest> services = namespaces.stream() .map(n -> credentials.list(KubernetesKind.SERVICE, n)).flatMap(Collection::stream) .collect(Collectors.toMap((m) -> manifestName.apply(m.getNamespace(), m.getName()), (m) -> m)); Map<KubernetesManifest, List<KubernetesManifest>> result = new HashMap<>(); for (KubernetesManifest manifest : primaryResourceList) { String serviceName = KubernetesStatefulSetHandler.serviceName(manifest); if (StringUtils.isEmpty(serviceName)) { continue; }//from w w w. j ava 2 s .c o m String key = manifestName.apply(manifest.getNamespace(), serviceName); if (!services.containsKey(key)) { continue; } KubernetesManifest service = services.get(key); result.put(manifest, Collections.singletonList(service)); } return result; }