Example usage for java.util.function Consumer accept

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

Introduction

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

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:com.eclecticlogic.pedal.impl.TransactionImpl.java

@Override
public void run(Consumer<Context> block) {
    _exec(context -> {// ww  w . java2 s .  c  o m
        block.accept(context);
        return null;
    });
}

From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java

@Before
public void setUp() throws Exception {
    this.eventAggregator = new EventAggregator(AGGREGATED_BUCKET, eventDataReader, s3Repo);
    this.eventAggregator.setSeed(0);
    doAnswer((i) -> {//from  w w w. j a v  a 2s . c o  m
        Object[] arguments = i.getArguments();
        Consumer<List<String>> callback = (Consumer<List<String>>) arguments[3];
        callback.accept(
                new ArrayList<>(asList("0", "DevOps", "49.2", "16.6167", "Brno", "Male", "6", "1449770125")));
        return null;
    }).when(eventDataReader).read(anyInt(), anyInt(), anyInt(), any(Consumer.class));
}

From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManager.java

private void notifyCallbacks(String containerImageFilePath, byte[] imageData) {
    List<Consumer<byte[]>> pendingCallbacks = null;
    synchronized (RETRIEVE_LOCK) {
        pendingCallbacks = pendingCallbacksByImagePath.remove(containerImageFilePath);
    }/* w  ww .  j ava2 s. c o m*/

    if (pendingCallbacks != null) {
        for (Consumer<byte[]> consumer : pendingCallbacks) {
            consumer.accept(imageData);
        }
    }
}

From source file:io.mapzone.controller.LoginAppDesign.java

@Override
public Shell createMainWindow(@SuppressWarnings("hiding") Display display) {
    this.display = display;
    mainWindow = new Shell(display, SWT.NO_TRIM);
    mainWindow.setMaximized(true);//from   w w  w  .j  av  a 2s.  co m
    UIUtils.setVariant(mainWindow, CSS_SHELL);

    mainWindow.setLayout(new FillLayout());

    String handlerId = RWT.getRequest().getParameter("id");

    SimpleDialog dialog = new SimpleDialog(mainWindow);
    dialog.title.set("Login required");
    dialog.setContents(parent -> {
        LoginForm loginForm = new LoginForm() {
            @Override
            protected boolean login(String name, String passwd) {
                Optional<User> loggedIn = tryLogin(name, passwd);
                if (loggedIn.isPresent()) {
                    Consumer<User> handler = handlers.remove(handlerId);
                    handler.accept(loggedIn.get());
                    return true;
                } else {
                    formSite.setFieldValue("password", "");
                    return false;
                }
            }

            @Override
            protected PanelSite panelSite() {
                throw new RuntimeException("not yet implemented.");
            }
        };
        loginForm.showRegisterLink.set(false);
        loginForm.showStoreCheck.set(true);
        loginForm.showLostLink.set(false); // XXX implement!

        new BatikFormContainer(loginForm).createContents(parent);
    });
    dialog.open();

    mainWindow.open();
    return mainWindow;
}

From source file:ninja.eivind.hotsreplayuploader.files.tempwatcher.RecursiveTempWatcherTest.java

@Test
public void testSetCallbackIsAppliedProperly() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    tempWatcher.setCallback(file -> latch.countDown());
    TempWatcher lastChild = getChildRecursively(tempWatcher);
    Consumer<File> callback = lastChild.getCallback();

    callback.accept(null);

    if (!latch.await(500, TimeUnit.MILLISECONDS)) {
        throw new TimeoutException("Latch was not tripped.");
    }//  w w w. jav  a  2 s  .com
}

From source file:org.apache.tinkerpop.gremlin.structure.io.gryo.GryoPool.java

public void doWithWriter(final Consumer<GryoWriter> writerFunction) {
    final GryoWriter gryoWriter = this.takeWriter();
    writerFunction.accept(gryoWriter);
    this.offerWriter(gryoWriter);
}

From source file:io.mandrel.transport.Pooled.java

public void with(Consumer<? super T> action) {
    T pooled = null;//from w  ww  . jav  a2  s . c o  m
    try {
        pooled = internalPool.borrowObject(hostAndPort);
        action.accept(pooled);
    } catch (RuntimeTTransportException e) {
        try {
            internalPool.invalidateObject(hostAndPort, pooled);
            pooled = null;
        } catch (Exception e1) {
            log.warn("", e1);
        }
        throw e;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        if (pooled != null) {
            try {
                internalPool.returnObject(hostAndPort, pooled);
            } catch (Exception e) {
                throw new TClientException("Could not return the resource to the pool", e);
            }
        }
    }
}

From source file:com.github.tddts.jet.service.impl.LoginServiceImpl.java

@Override
public void processLogin(Supplier<Optional<Pair<String, String>>> credentialsSupplier,
        Consumer<URI> loginUriConsumer) {
    AuthorizationType authType = userBean.getAuthorizationType();

    server.start();/*from ww  w  .j av  a2 s.c o  m*/

    if (authType.isImplicit()) {
        loginUriConsumer.accept(authService.getLoginPageURI());
    }

    if (authType.isDev()) {
        Optional<Pair<String, String>> credentialsPair = credentialsSupplier.get();

        credentialsPair.ifPresent(creds -> {
            userBean.setClientId(creds.getKey());
            userBean.setSercretKey(creds.getValue());
            loginUriConsumer.accept(authService.getLoginPageURI(userBean.getClientId()));
        });

    }
}

From source file:co.degraph.server.acceptance.api.controllers.GraphResourceChecks.java

public GraphResourceChecks hasEdge(String startId, String endId, Consumer<EdgeResourceChecks> edgeCheck) {
    EdgeResource edge = find(getValue().getEdges(),
            e -> e.getStart().getId().equals(startId) && e.getEnd().getId().equals(endId));

    edgeCheck.accept(new EdgeResourceChecks(edge));
    return this;
}

From source file:org.netbeans.jcode.ng.main.AngularUtil.java

public static void copyDynamicResource(Consumer<FileTypeStream> parserManager, String inputResource,
        FileObject webRoot, Function<String, String> pathResolver, ProgressHandler handler) throws IOException {
    InputStream inputStream = Angular1Generator.class.getClassLoader().getResourceAsStream(inputResource);
    try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
        ZipEntry entry;//from  w  w w . jav  a2 s. c  o m
        while ((entry = zipInputStream.getNextEntry()) != null) {
            if (entry.getName().lastIndexOf('.') == -1) {
                continue;
            }
            String fileType = entry.getName().substring(entry.getName().lastIndexOf('.') + 1);
            String targetPath = pathResolver.apply(entry.getName());
            if (targetPath == null) {
                continue;
            }
            handler.progress(targetPath);
            FileObject target = org.openide.filesystems.FileUtil.createData(webRoot, targetPath);
            FileLock lock = target.lock();
            try (OutputStream outputStream = target.getOutputStream(lock)) {
                parserManager.accept(new FileTypeStream(fileType, zipInputStream, outputStream));
                zipInputStream.closeEntry();
            } finally {
                lock.releaseLock();
            }
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
        System.out.println("InputResource : " + inputResource);
    }
}