List of usage examples for java.util.function Function andThen
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after)
From source file:Main.java
public static void main(String... args) { Function<String, Integer> toInteger = Integer::valueOf; Function<String, String> backToString = toInteger.andThen(String::valueOf); System.out.println(backToString.apply("123")); }
From source file:Main.java
public static void main(String[] args) { Function<Integer, Integer> incrementer = (n) -> n + 1; Function<Integer, Integer> after = (n) -> n - 1; System.out.println(incrementer.andThen(after).apply(2)); }
From source file:Main.java
public static void main(String[] args) { Function<Integer, String> converter = (i) -> Integer.toString(i); Function<String, Integer> reverse = (s) -> Integer.parseInt(s); System.out.println(converter.apply(3).length()); System.out.println(converter.andThen(reverse).apply(30).byteValue()); }
From source file:Main.java
public static void main(String[] args) { Function<Double, Double> square = number -> number * number; Function<Double, Double> half = number -> number * 2; List<Double> numbers = Arrays.asList(10D, 4D, 12D); // pay attention to the order System.out.println(mapIt(numbers, square.compose(half))); System.out.println(mapIt(numbers, half.compose(square))); // you can chain them System.out.println(mapIt(numbers, half.andThen(square))); }
From source file:co.runrightfast.zest.assemblers.ModuleAssembler.java
static Function<ModuleAssembly, ModuleAssembly> composeAssembler( @NonNull final Function<ModuleAssembly, ModuleAssembly> assembler1, @NonNull final Function<ModuleAssembly, ModuleAssembly> assembler2, final Function<ModuleAssembly, ModuleAssembly>... moreAssemblers) { if (ArrayUtils.isNotEmpty(moreAssemblers)) { noNullElements(moreAssemblers);//from ww w .j av a 2s .c o m Function<ModuleAssembly, ModuleAssembly> chain = assembler1.andThen(assembler2); for (final Function<ModuleAssembly, ModuleAssembly> assembler : moreAssemblers) { chain = chain.andThen(assembler); } return chain; } else { return assembler1.andThen(assembler2); } }
From source file:org.trustedanalytics.datasetpublisher.boundary.MetadataMapper.java
/** * Converts table name to valid string according to database engine and driver constraints. * @param string table name//from w ww .j a va2s . c om * @return valid name */ private String toValidTableName(String string) { final Function<String, String> lowercase = String::toLowerCase; return lowercase // prefix must be a letter .andThen(s -> s.matches("^[a-zA-Z].*") ? s : "x" + s) // replace non alphanumeric characters .andThen(s -> s.replaceAll("\\W", "_")) // add underscore after name that is Impala reserved word .andThen(s -> isValidKeyword(s) ? s : s + "_") // limit identifier length .andThen(s -> StringUtils.left(s, IDENTIFIER_MAX_LEN)) // apply initial name .apply(string); }
From source file:com.ibasco.agql.core.client.AbstractRestClient.java
/** * <p>Factory method for creating the default {@link WebMessenger}</p> * * @return A {@link WebMessenger} instance *//*www . j a v a 2s . c om*/ @Override public final WebMessenger<Req, Res> createWebMessenger() { Function<Response, Res> responseFactory = this::createWebApiResponse; return new WebMessenger<>(responseFactory.andThen(this::applyContentTypeProcessor)); }
From source file:org.apache.lens.cube.parse.CubeTestSetup.java
private void createFromXML(CubeMetastoreClient client) { SchemaTraverser.SchemaEntityProcessor processor = (file, aClass) -> { Function<String, String> f = GREGORIAN_SUBSTITUTOR::replace; Function<String, String> g = ABSOLUTE_SUBSTITUTOR::replace; try {/* w ww . j ava2s . co m*/ BufferedReader br = new BufferedReader(new FileReader(file)); String replaced = br.lines().map(f.andThen(g)).collect(Collectors.joining("\n")); StringReader sr = new StringReader(replaced); client.createEntity(LensJAXBContext.unmarshall(sr)); } catch (LensException | JAXBException | IOException e) { throw new RuntimeException(e); } }; new SchemaTraverser(new File(getClass().getResource("/schema").getFile()), processor, null, null).run(); }
From source file:org.briljantframework.data.Collectors.java
public static <T, A, R, F> Collector<T, ?, F> withFinisher(Collector<T, A, R> collector, Function<R, F> finisher) { Function<A, R> f = collector.finisher(); Set<Collector.Characteristics> characteristics = collector.characteristics(); Collector.Characteristics[] empty = new Collector.Characteristics[characteristics.size()]; return Collector.of(collector.supplier(), collector.accumulator(), collector.combiner(), f.andThen(finisher), characteristics.toArray(empty)); }
From source file:org.codice.ddf.catalog.ui.metacard.MetacardApplication.java
protected UpdateResponse patchMetacards(List<MetacardChanges> metacardChanges, String subjectIdentifer) throws SourceUnavailableException, IngestException { Set<String> changedIds = metacardChanges.stream().flatMap(mc -> mc.getIds().stream()) .collect(Collectors.toSet()); Map<String, Result> results = util.getMetacardsWithTagById(changedIds, "*"); for (MetacardChanges changeset : metacardChanges) { for (AttributeChange attributeChange : changeset.getAttributes()) { for (String id : changeset.getIds()) { List<String> values = attributeChange.getValues(); Result result = results.get(id); if (result == null) { LOGGER.debug(//from w w w .j a v a 2s.c om "Metacard {} either does not exist or user {} does not have permission to see it", id, subjectIdentifer); throw new NotFoundException("Result was not found"); } Metacard resultMetacard = result.getMetacard(); Function<Serializable, Serializable> mapFunc = Function.identity(); if (isChangeTypeDate(attributeChange, resultMetacard)) { mapFunc = mapFunc.andThen(serializable -> Date.from(util.parseDate(serializable))); } resultMetacard.setAttribute(new AttributeImpl(attributeChange.getAttribute(), values.stream().filter(Objects::nonNull).map(mapFunc).collect(Collectors.toList()))); } } } List<Metacard> changedMetacards = results.values().stream().map(Result::getMetacard) .collect(Collectors.toList()); return catalogFramework.update(new UpdateRequestImpl( changedMetacards.stream().map(Metacard::getId).toArray(String[]::new), changedMetacards)); }