List of usage examples for java.util.function UnaryOperator apply
R apply(T t);
From source file:Main.java
public static void main(String[] args) { UnaryOperator<String> i = (x) -> x.toUpperCase(); System.out.println(i.apply("java2s.com")); }
From source file:com.carlomicieli.jtrains.value.objects.Address.java
/** * Constructs new {@code Address} object. * * <p>/*from ww w . j a v a 2 s .c om*/ * <pre> * Address maerklin = Address.build( * b -> b.streetAddress("Stuttgarter Strae 55-57") * .city("Goppingen") * .postalCode("D-73033") * .country("Germany") * .locality("A") * .state("Baden-Wurttemberg") * ); * </pre> * </p> * * @param op the building {@code operator} * @return a new {@code Address}. */ public static Address build(UnaryOperator<Builder> op) { return op.apply(new Builder()).build(); }
From source file:com.carlomicieli.jtrains.core.models.Railway.java
public static Railway build(UnaryOperator<Builder> op) { return op.apply(new Builder()).build(); }
From source file:com.carlomicieli.jtrains.core.models.Brand.java
/** * Constructs a new {@code Brand} objects using the builder fluent interface. * * <p>//from w w w . j a v a2s. c o m * <pre> * Brand acme = build(b -> b * .id(new ObjectId("607c7f79bcf86cd7994f6c0a")) * .name("ACME") * .companyName("Anonima Costruttori Modelli Esatti") * .website("http://www.acmetreni.com") * .emailAddress("mail@acme.com") * .description(Locale.ENGLISH, "ACME description") * .industrial(true)); * </pre> * </p> */ public static Brand build(UnaryOperator<Builder> op) { return op.apply(new Builder()).build(); }
From source file:gedi.util.FileUtils.java
public static long download(File file, String url, UnaryOperator<InputStream> streamAdapter, Progress progress, LongFunction<String> bytesToMessage) throws MalformedURLException, IOException { final byte[] buffer = new byte[8024]; int n = 0;//from www. j a va2 s. c o m long count = 0; InputStream input = new URL(url).openStream(); if (streamAdapter != null) input = streamAdapter.apply(input); OutputStream output = new FileOutputStream(file); while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; long ucount = count; progress.incrementProgress().setDescription(() -> bytesToMessage.apply(ucount)); } input.close(); output.close(); return count; }
From source file:onl.area51.httpd.action.Action.java
default Action wrapif(boolean wrap, UnaryOperator<Action> mapper) { return wrap ? mapper.apply(this) : this; }
From source file:com.github.horrorho.inflatabledonkey.args.ArgsManager.java
String parse(String optionName, String value, UnaryOperator<String> parser) { try {//from w w w.j a v a 2 s .c om return parser.apply(value); } catch (RuntimeException ex) { logger.debug("-- test() - RuntimeException: {}", ex.getMessage()); throw new IllegalArgumentException(optionName + " has bad value '" + value + "'"); } }
From source file:de.metas.ui.web.letter.LetterRestController.java
private WebuiLetterChangeResult changeLetter(final String letterId, final UnaryOperator<WebuiLetter> letterModifier) { final WebuiLetterChangeResult result = lettersRepo.changeLetter(letterId, letterOld -> { assertWritable(letterOld);/*from w ww. j a va 2 s.c o m*/ return letterModifier.apply(letterOld); }); return result; }
From source file:libepg.util.bytearray.ByteArraySplitter.java
/** * ????????????????????0??<br>/* ww w .jav a 2s . c o m*/ * 1.??????????????????<br> * 2.??????????????????????????<br> * * * @author normal * @param src ? * @param lengthFieldPosition * ??(??????????????)<br> * @param lengthFieldLength ????? * @param preProcessor ???8????????????? * @return ??? * * ????<br> * X=?????<br> * Y=?<br> * Z=????<br> * ???=XXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZXXXXYYZZZZZZZ<br> * ???1=XXXXYYZZZZZZ<br> * ???2=XXXXYYZZZZZZ<br> * ???3=XXXXYYZZZZZZ<br> * ???4=XXXXYYZZZZZZ<br> * ???5=XXXXYYZZZZZZ<br> * ???6=XXXXYYZZZZZZ<br> * ???7=XXXXYYZZZZZZ<br> * ???8=XXXXYYZZZZZZ<br> * ???9=XXXXYYZZZZZZZ<br> */ public static synchronized List<byte[]> splitByLengthField(byte[] src, int lengthFieldPosition, int lengthFieldLength, UnaryOperator<Integer> preProcessor) { UnaryOperator<Integer> preProcessor_t; if (preProcessor == null) { throw new NullPointerException("??????????"); } else { preProcessor_t = preProcessor; } if (LOG.isTraceEnabled()) { LOG.trace(" = " + Hex.encodeHexString(src)); LOG.trace("?? = " + lengthFieldPosition); LOG.trace("??? = " + lengthFieldLength); } List<byte[]> dest = new ArrayList<>(); try (ByteArrayInputStream bis = new ByteArrayInputStream(src)) { while (bis.available() > 0) { //?????????????????? bis.mark(0); //??????????????????????? bis.skip(lengthFieldPosition - 1); //?? byte[] lengthFieldValue_Byte = new byte[lengthFieldLength]; if (bis.read(lengthFieldValue_Byte) == -1) { break; } int lengthFieldValue = ByteConverter.bytesToInt(lengthFieldValue_Byte);//? int lengthFieldValue_Processed = preProcessor_t.apply(lengthFieldValue); if (LOG.isTraceEnabled()) { LOG.trace("?(byte) = " + Hex.encodeHexString(lengthFieldValue_Byte)); LOG.trace("?(?) = " + lengthFieldValue); LOG.trace("?() = " + lengthFieldValue_Processed); } //?? bis.reset(); //???????(??????-1+???+??) int partLength = lengthFieldPosition - 1 + lengthFieldLength + lengthFieldValue_Processed; if (LOG.isTraceEnabled()) { LOG.trace("?????= " + partLength); } //??? byte[] temp = new byte[partLength]; //? if (bis.read(temp) == -1) { break; } if (LOG.isTraceEnabled()) { LOG.trace("?= " + Hex.encodeHexString(temp)); } dest.add(temp); } } catch (IOException ex) { LOG.info("???????????"); } finally { return dest; } }
From source file:enumj.Enumerator.java
/** * Returns an infinite enumerator obtained by applying repeatedly the * provided unary operator./*from www .j a v a 2s . c om*/ * <p> * The resulted enumerator returns <code>seed</code>, * <code>f(seed)</code>, <code>f(f(seed))</code> ... * </p> * * @param <E> the type of enumerated elements * @param seed the initial element * @param f state-less {@link Function} instance to apply on the previous * element to obtain the next element * @return the iterated enumerator * @exception IllegalArgumentException <code>f</code> is null. */ public static <E> Enumerator<E> iterate(E seed, UnaryOperator<E> f) { Checks.ensureNotNull(f, Messages.NULL_ENUMERATOR_GENERATOR); final Mutable<E> result = new MutableObject(seed); final MutableBoolean first = new MutableBoolean(true); return of(() -> { if (first.booleanValue()) { first.setValue(false); } else { result.setValue(f.apply(result.getValue())); } return Optional.of(result.getValue()); }); }