Example usage for java.util.function Consumer andThen

List of usage examples for java.util.function Consumer andThen

Introduction

In this page you can find the example usage for java.util.function Consumer andThen.

Prototype

default Consumer<T> andThen(Consumer<? super T> after) 

Source Link

Document

Returns a composed Consumer that performs, in sequence, this operation followed by the after operation.

Usage

From source file:Main.java

public static void main(String[] args) {
    Consumer<String> c = (x) -> System.out.println(x.toLowerCase());
    c.andThen(c).accept("Java2s.com");
}

From source file:Main.java

public static void main(String[] args) {
    Message message = new Message("java2s.com");

    Consumer<Message> messageConsumer = (t) -> System.out.println(t);
    Consumer<Message> endConsumer = (t) -> System.out.println("End: " + t);
    messageConsumer.andThen(endConsumer).accept((message));

}

From source file:Main.java

public static void main(String[] args) {
    List<Student> students = Arrays.asList(new Student(1, 3, "John"), new Student(2, 4, "Jane"),
            new Student(3, 3, "Jack"));

    Consumer<Student> raiser = e -> {
        e.gpa = e.gpa * 1.1;/* www.j  av a 2  s . co  m*/
    };

    raiseStudents(students, System.out::println);
    raiseStudents(students, raiser.andThen(System.out::println));
}

From source file:org.eclipse.packagedrone.utils.rpm.build.RpmBuilder.java

private <T> void addFile(final String targetName, final T sourcePath, final Consumer<FileEntry> customizer,
        final int mode, final Instant fileModificationInstant, final RecorderFunction<T> func)
        throws IOException {
    final PathName pathName = PathName.parse(targetName);

    final long mtime = fileModificationInstant.getEpochSecond();
    final int inode = this.currentInode++;

    final short smode = (short) (mode | CpioConstants.C_ISREG);

    final Result result = func.record(this.recorder, "./" + pathName.toString(), sourcePath,
            cpioCustomizer(mtime, inode, smode));

    Consumer<FileEntry> c = this::initEntry;
    c = c.andThen(entry -> {
        entry.setModificationTime((int) mtime);
        entry.setInode(inode);/*w w w . ja v  a  2s .  c o m*/
        entry.setMode(smode);
    });

    if (customizer != null) {
        c = c.andThen(customizer);
    }

    addResult(pathName, result, c);
}

From source file:org.eclipse.packagedrone.utils.rpm.build.RpmBuilder.java

private void addDirectory(final String targetName, final int mode, final Instant modInstant,
        final Consumer<FileEntry> customizer) throws IOException {
    final PathName pathName = PathName.parse(targetName);

    final long mtime = modInstant.getEpochSecond();
    final int inode = this.currentInode++;

    final short smode = (short) (mode | CpioConstants.C_ISDIR);

    final Result result = this.recorder.addDirectory("./" + pathName.toString(),
            cpioCustomizer(mtime, inode, smode));

    Consumer<FileEntry> c = this::initEntry;
    c = c.andThen(entry -> {
        entry.setModificationTime((int) mtime);
        entry.setInode(inode);/*  w w  w .ja v a 2s .c o  m*/
        entry.setMode(smode);
        entry.setSize(0);
        entry.setTargetSize(4096);
    });

    if (customizer != null) {
        c = c.andThen(customizer);
    }

    addResult(pathName, result, c);
}

From source file:org.eclipse.packagedrone.utils.rpm.build.RpmBuilder.java

private void addSymbolicLink(final String targetName, final String linkTo, final int mode,
        final Instant modInstant, final Consumer<FileEntry> customizer) throws IOException {
    final PathName pathName = PathName.parse(targetName);

    final long mtime = modInstant.getEpochSecond();
    final int inode = this.currentInode++;

    final short smode = (short) (mode | CpioConstants.C_ISLNK);

    final Result result = this.recorder.addSymbolicLink("./" + pathName.toString(), linkTo,
            cpioCustomizer(mtime, inode, smode));

    Consumer<FileEntry> c = this::initEntry;
    c = c.andThen(entry -> {
        entry.setModificationTime((int) mtime);
        entry.setInode(inode);/*from w  w w. ja  va  2 s . com*/
        entry.setMode(smode);
        entry.setSize(result.getSize());
        entry.setTargetSize(result.getSize());
        entry.setLinkTo(linkTo);
    });

    if (customizer != null) {
        c = c.andThen(customizer);
    }

    addResult(pathName, result, c);
}