List of usage examples for java.util.function BiFunction apply
R apply(T t, U u);
From source file:org.apache.samza.sql.runner.SamzaSqlApplicationConfig.java
public static <T> T initializePlugin(String pluginName, String plugin, Config staticConfig, String pluginDomainFormat, BiFunction<Object, Config, T> factoryInvoker) { String pluginDomain = String.format(pluginDomainFormat, plugin); Config pluginConfig = staticConfig.subset(pluginDomain); String factoryName = pluginConfig.getOrDefault(CFG_FACTORY, ""); Validate.notEmpty(factoryName, String.format("Factory is not set for %s", plugin)); Object factory = ReflectionUtils.createInstance(factoryName); Validate.notNull(factory, String.format("Factory creation failed for %s", plugin)); LOG.info("Instantiating {} using factory {} with props {}", pluginName, factoryName, pluginConfig); return factoryInvoker.apply(factory, pluginConfig); }
From source file:org.lambdamatic.mongodb.apt.template.TemplateType.java
/** * Returns the {@link TemplateType} for the given {@link VariableType}, or throws a * {@link MetadataGenerationException} if it was not a known or supported type. * //w ww. ja v a 2 s . c o m * @param variableType the variable to analyze * @return the corresponding {@link TemplateType} * @throws MetadataGenerationException if the given variable type is not supported */ private static TemplateType getMetadataFieldType(final TypeMirror variableType, final BiFunction<PrimitiveType, ProcessingEnvironment, TemplateType> primitiveTypeToTemplateType, final Function<DeclaredType, TemplateType> embeddedDocumentToTemplateType, final BiFunction<TypeMirror, ProcessingEnvironment, TemplateType> collectionToTemplateType, final BiFunction<DeclaredType, ProcessingEnvironment, TemplateType> mapToTemplateType, final Function<DeclaredType, TemplateType> declaredTypeToTemplateType, final ProcessingEnvironment processingEnv) throws MetadataGenerationException { if (variableType instanceof PrimitiveType) { return primitiveTypeToTemplateType.apply((PrimitiveType) variableType, processingEnv); } else if (variableType instanceof DeclaredType) { final DeclaredType declaredType = (DeclaredType) variableType; final TypeElement declaredElement = (TypeElement) declaredType.asElement(); if (declaredElement.getAnnotation(EmbeddedDocument.class) != null) { // embedded documents return embeddedDocumentToTemplateType.apply(declaredType); } else if (ElementUtils.isAssignable(declaredType, Collection.class)) { // collections (list/set) return collectionToTemplateType.apply(declaredType.getTypeArguments().get(0), processingEnv); } else if (ElementUtils.isAssignable(declaredType, Map.class)) { // map return mapToTemplateType.apply(declaredType, processingEnv); } else { return declaredTypeToTemplateType.apply(declaredType); } } else if (variableType.getKind() == TypeKind.ARRAY) { final TypeMirror componentType = ((ArrayType) variableType).getComponentType(); if (componentType instanceof PrimitiveType) { final PrimitiveType primitiveType = (PrimitiveType) componentType; final TypeElement boxedClass = processingEnv.getTypeUtils().boxedClass(primitiveType); return collectionToTemplateType.apply(boxedClass.asType(), processingEnv); } return collectionToTemplateType.apply(componentType, processingEnv); } throw new MetadataGenerationException("Unexpected variable type: " + variableType); }
From source file:com.github.steveash.guavate.Guavate.java
/** * Helper method to merge two mutable maps by inserting all values from {@code map2} into {@code map1}. * <p>//from ww w .j a v a2 s. c o m * If {@code map1} already contains a mapping for a key the merge function is applied to the existing value and * the new value, and the return value is inserted. * @param map1 the map into which values are copied * @param map2 the map from which values are copied * @param mergeFn function applied to the existing and new values if the map contains the key * @param <K> the key type * @param <V> the value type * @return {@code map1} with the values from {@code map2} inserted */ private static <K, V> Map<K, V> mergeMaps(Map<K, V> map1, Map<K, V> map2, BiFunction<? super V, ? super V, ? extends V> mergeFn) { for (Map.Entry<K, V> entry : map2.entrySet()) { V existingValue = map1.get(entry.getKey()); if (existingValue == null) { map1.put(entry.getKey(), entry.getValue()); } else { map1.put(entry.getKey(), mergeFn.apply(existingValue, entry.getValue())); } } return map1; }
From source file:Main.java
public String calc(BiFunction<Integer, Integer, String> bi, Integer i1, Integer i2) { return bi.apply(i1, i2); }
From source file:Main.java
public Util() { BiFunction<String, String, String> strFunc = this::append; String name = "java2s.com"; String s = strFunc.apply(name, " hi"); System.out.println(s);//from w w w .j a va2 s . co m strFunc = Util.super::append; name = "java2s.com"; s = strFunc.apply(name, " Java Lambda Tutorial"); System.out.println(s); }
From source file:org.apache.commons.weaver.privilizer.example.MethodReferencesUsingBlueprints.java
public String utilsGetProperty(int i, String key) { final BiFunction<Integer, String, String> f = Utils::getProperty; return f.apply(i, key); }
From source file:com.synopsys.integration.blackduck.service.ComponentService.java
public <T> T getFilteredSearchResults(ExternalId externalId, List<ComponentSearchResultView> searchResults, BiFunction<ExternalId, List<ComponentSearchResultView>, T> filterFunction) { return filterFunction.apply(externalId, searchResults); }
From source file:org.n52.iceland.config.json.AbstractJsonActivationDao.java
protected <K extends AbstractComparableServiceVersionDomainKey<K>> Function<JsonNode, K> createDomainDecoder( BiFunction<ServiceOperatorKey, String, K> fun) { Objects.requireNonNull(fun); return n -> fun.apply(decodeServiceOperatorKey(n), n.path(JsonConstants.DOMAIN).textValue()); }
From source file:org.codice.alliance.security.banner.marking.MarkingExtractor.java
@Override public void process(String input, Metacard metacard) { BannerMarkings bannerMarkings = null; try {/* w w w .j a va 2 s. c om*/ Optional<String> bannerLine = new BufferedReader(new StringReader(input)).lines().map(String::trim) .filter(s -> !s.isEmpty()).findFirst(); if (bannerLine.isPresent()) { bannerMarkings = BannerMarkings.parseMarkings(bannerLine.get()); } } catch (MarkingsValidationException e) { LOGGER.warn("Errors validating document markings", e); } if (bannerMarkings == null) { return; } for (BiFunction<Metacard, BannerMarkings, Attribute> attFunc : attProcessors.values()) { metacard.setAttribute(attFunc.apply(metacard, bannerMarkings)); } }
From source file:com.samsung.sjs.constraintsolver.TypeConstraintFixedPointSolver.java
private static void traverseAndUpdateType(Type type, final Set<Type> inProgress, final BiFunction<Type, Context, Type> typeUpdater) { BiFunction<Type, Context, Type> updateAndRecurse = (t, context) -> { Type newType = typeUpdater.apply(t, context); traverseAndUpdateType(newType, inProgress, typeUpdater); return newType; };//from w w w . ja v a 2 s.c o m if (inProgress.contains(type)) { logger.trace("already handling type {}", type); return; } logger.trace("handling type {}", type); inProgress.add(type); if (type instanceof ObjectType) { ObjectType ot = (ObjectType) type; for (Property p : ot.properties()) { Type ptype = p.getType(); Type newType = updateAndRecurse.apply(ptype, Context.OTHER); ot.setProperty(p.getName(), newType, p.isRO(), p.getSourceLoc()); } } else if (type instanceof ArrayType) { ArrayType at = (ArrayType) type; Type elemType = at.elemType(); at.setElemType(updateAndRecurse.apply(elemType, Context.OTHER)); } else if (type instanceof MapType) { MapType mt = (MapType) type; Type elemType = mt.elemType(); mt.setElemType(updateAndRecurse.apply(elemType, Context.OTHER)); } else if (type instanceof CodeType) { CodeType ft = (CodeType) type; List<Type> paramTypes = ft.paramTypes(); for (int i = 0; i < paramTypes.size(); i++) { Type curParamType = paramTypes.get(i); ft.setParamType(updateAndRecurse.apply(curParamType, Context.OTHER), i); } Type returnType = ft.returnType(); ft.setReturnType(updateAndRecurse.apply(returnType, Context.OTHER)); if (type instanceof ConstructorType) { ConstructorType cType = (ConstructorType) type; Type proto = cType.getPrototype(); Type updated = updateAndRecurse.apply(proto, Context.CONSTRUCTOR_PROTO); cType.setPrototype(updated); } if (type instanceof UnattachedMethodType) { UnattachedMethodType umType = (UnattachedMethodType) type; Type recv = umType.receiverType(); Type updatedRecv = updateAndRecurse.apply(recv, Context.RECEIVER); umType.setReceiverType(updatedRecv); } } else if (type instanceof IntersectionType) { // immutable, so just traverse for (Type t : ((IntersectionType) type).getTypes()) { traverseAndUpdateType(t, inProgress, typeUpdater); } } else if (type instanceof ObjectUnionType) { // immutable, so just traverse for (Type t : ((ObjectUnionType) type)) { traverseAndUpdateType(t, inProgress, typeUpdater); } } inProgress.remove(type); }