Example usage for java.util.function Consumer Consumer

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

Introduction

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

Prototype

Consumer

Source Link

Usage

From source file:com.quancheng.plugin.common.PrintMessageFile.java

private Map<String, Pair<DescriptorProto, List<FieldDescriptorProto>>> transform(
        DescriptorProto sourceMessageDesc) {
    Map<String, Pair<DescriptorProto, List<FieldDescriptorProto>>> nestedFieldMap = Maps.newHashMap();
    sourceMessageDesc.getNestedTypeList().forEach(new Consumer<DescriptorProto>() {

        @Override/*from   w  w  w  .  ja v a 2s  . c  o  m*/
        public void accept(DescriptorProto t) {
            nestedFieldMap.put(t.getName(),
                    new ImmutablePair<DescriptorProto, List<FieldDescriptorProto>>(t, t.getFieldList()));
        }

    });
    return nestedFieldMap;
}

From source file:com.vsthost.rnd.jdeoptim.diagnostics.Diagnostics.java

/**
 * Defines a signal to be emitted when an iteration has started.
 *
 * @param iteration The iteration number.
 *///from ww w.  j ava 2 s  .c  o m
public void iterationStarted(final int iteration) {
    this.observers.forEach(new Consumer<Listener>() {
        @Override
        public void accept(Listener observer) {
            observer.iterationStarted(iteration);
        }
    });
}

From source file:org.eclipse.vorto.maven.GeneratorMojo.java

private byte[] loadInformationModels() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ZipOutputStream zaos = new ZipOutputStream(baos);

    Files.walk(Paths.get((project.getBasedir().toURI()))).filter(new Predicate<Path>() {

        public boolean test(Path path) {
            return !path.toFile().isDirectory()
                    && (path.getFileName().toString().endsWith(ModelType.InformationModel.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Functionblock.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Datatype.getExtension()));
        }//  w w  w. j a v  a2s .  c  o  m
    }).forEach(new Consumer<Path>() {

        public void accept(Path t) {
            addToZip(zaos, t);
        }
    });

    return baos.toByteArray();
}

From source file:com.diversityarrays.kdxplore.KDXplore.java

public static void mainImpl(String[] args, Closure<KDXploreFrame> onCreateCallback,
        final Closure<UpdateCheckContext> updateChecker) {
    Locale defaultLocale = Locale.getDefault();
    System.out.println("Locale=" + defaultLocale); //$NON-NLS-1$

    // System.setProperty("apple.laf.useScreenMenuBar", "true");
    // //$NON-NLS-1$ //$NON-NLS-2$

    // Initialise the appFolder

    KdxplorePreferences prefs = KdxplorePreferences.getInstance();
    applyUIdefaultPreferences(prefs);//from  w w w.j a  v  a2s  . c om

    String kdxploreName = KDXPLORE_APP_NAME;
    ApplicationFolder defaultAppFolder = ApplicationFolders.getApplicationFolder(kdxploreName);
    String[] newArgs = CommandArgs.parseRunModeOption(defaultAppFolder, args);

    String baseNameForDistrib = kdxploreName.toLowerCase();
    if (RunMode.DEMO == RunMode.getRunMode()) {
        kdxploreName = kdxploreName + "Demo"; //$NON-NLS-1$
    }
    final ApplicationFolder appFolder = ApplicationFolders.getApplicationFolder(kdxploreName);
    CommandArgs commandArgs = new CommandArgs(appFolder, KdxConstants.VERSION, KdxConstants.VERSION_CODE,
            newArgs);

    org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ClassPathExtender.class);

    if (commandArgs.baseDir == null) {
        File userDir = new File(System.getProperty("user.dir")); //$NON-NLS-1$

        File distribDir;
        if ("kdxos_main".equals(userDir.getName())) {
            // In Eclipse project this is where we store it
            distribDir = new File(userDir.getParentFile(), baseNameForDistrib);
        } else {
            distribDir = new File(userDir, baseNameForDistrib);
        }

        System.out.println("userDir=" + userDir); //$NON-NLS-1$
        System.out.println("distribDir=" + distribDir); //$NON-NLS-1$

        commandArgs.baseDir = distribDir.isDirectory() ? distribDir : userDir;
    }

    if (!commandArgs.baseDir.isDirectory()) {
        GuiUtil.errorMessage(null, "baseDir is not a directory: " + commandArgs.baseDir); //$NON-NLS-1$
        System.exit(1);
    }

    File libDir = new File(commandArgs.baseDir, "lib"); //$NON-NLS-1$
    File[] libFiles = libDir.listFiles();
    if (libFiles == null) {
        MsgBox.error(null, Msg.MSG_APP_START_DIRECTORY(kdxploreName, commandArgs.baseDir),
                Msg.ERRTITLE_MISSING_LIBRARY_FILES() + ": " + libDir.getPath());
        System.exit(1);
    } else if (libFiles.length < REQD_LIB_COUNT) {
        MsgBox.error(null, Msg.MSG_APP_START_DIRECTORY(kdxploreName, commandArgs.baseDir),
                Msg.ERRTITLE_MISSING_LIBRARY_FILES() + ": " + libFiles.length);
        System.exit(1);
    }

    // = = = = = = = = = = = = = = = = = = =
    // = = = = = = = = = = = = = = = = = = =
    // = = = = = = = CLASSPATH = = = = = = =
    ClassPathExtender.VERBOSE = !commandArgs.quiet; // RunMode.getRunMode().isDeveloper();
    String libs_sb = "lib,plugins,kdxlibs,../runlibs"; //$NON-NLS-1$

    boolean[] seenPdfbox = new boolean[1];
    Consumer<File> jarChecker = new Consumer<File>() {
        @Override
        public void accept(File f) {
            if (f.getName().startsWith("pdfbox")) {
                seenPdfbox[0] = true;
            }
        }
    };
    ClassPathExtender.appendToClassPath(commandArgs.baseDir, libs_sb, jarChecker, log);
    if (seenPdfbox[0]) {
        System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
    }

    // = = = = = = = = = = = = = = = = = = =
    // = = = = = = = = = = = = = = = = = = =
    // = = = = = = = = = = = = = = = = = = =

    doStaticInitChecks(commandArgs.quiet);
    if (commandArgs.runInitChecks) {
        System.out.println("Init checks OK"); //$NON-NLS-1$
        System.exit(0);
    }

    establishLogger(appFolder);

    @SuppressWarnings("unused")
    String configName = commandArgs.establishKdxConfig();

    Long versionSubinfo = null;
    if (commandArgs.errmsg == null) {
        if (!KdxploreConfig.getInstance().isEternal()) {
            commandArgs.expiryChecks(KdxConstants.VERSION);
            versionSubinfo = KdxConstants.getVersionSubinfo();
            if (versionSubinfo == Long.MAX_VALUE) {
                versionSubinfo = null;
            }
        }
    }

    String baseTitle = appFolder.getApplicationName() + " v" + KdxConstants.VERSION; //$NON-NLS-1$

    String expiresIn = ""; //$NON-NLS-1$
    if (versionSubinfo != null) {
        if ((0 < versionSubinfo && versionSubinfo < 14) || RunMode.getRunMode().isDeveloper()) {
            expiresIn = " " + Msg.KDX_EXPIRES_IN_N_DAYS(versionSubinfo.intValue()); //$NON-NLS-1$
        }
    }
    if (commandArgs.errmsg != null) {
        JOptionPane.showMessageDialog(null, commandArgs.errmsg, baseTitle + expiresIn,
                JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    final String kdxploreTitle = buildKdxploreTitle(baseTitle, expiresIn,
            commandArgs.kdxConfigService.getConfigName());

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            // TODO allow user to change "base font size"
            String uiMultiplier = null;
            try {
                String propertyName = CommandArgs.UI_MULTIPLIER_PROPERTY_NAME;
                uiMultiplier = System.getProperty(propertyName);
                if (uiMultiplier != null) {
                    try {
                        float multiplier = Float.parseFloat(uiMultiplier);
                        setUIfontSize(multiplier);
                    } catch (NumberFormatException e) {
                        System.err.println(String.format("?invalid value for %s: %s", //$NON-NLS-1$
                                propertyName, uiMultiplier));
                    }
                }
            } catch (SecurityException e) {
                System.err.println(String.format("Ignoring: %s %s", //$NON-NLS-1$
                        e.getClass().getSimpleName(), e.getMessage()));
            }

            GuiUtil.initLookAndFeel();

            try {
                KDXploreFrame frame = new KDXploreFrame(appFolder, kdxploreTitle, KdxConstants.VERSION_CODE,
                        KdxConstants.VERSION, updateChecker);
                frame.setVisible(true);
                if (onCreateCallback != null) {
                    onCreateCallback.execute(frame);
                }
            } catch (IOException e) {
                MsgBox.error(null, e, Msg.ERRTITLE_UNABLE_TO_START_KDXPLORE(KDXPLORE_APP_NAME));
            }

        }
    });
}

From source file:com.vsthost.rnd.jdeoptim.diagnostics.Diagnostics.java

/**
 * Defines a signal to be emitted when an iteration has finished.
 *
 * @param iteration The iteration number.
 * @param population The population as of the iteration has finished.
 *//*from   w  w w  .  j  a v  a2 s  .c o m*/
public void iterationFinished(final int iteration, final Population population) {
    this.observers.forEach(new Consumer<Listener>() {
        @Override
        public void accept(Listener observer) {
            observer.iterationFinished(iteration, population);
        }
    });
}

From source file:dk.dma.ais.reader.AisReader.java

/**
 * Add a queue for receiving messages/*from   w  w w .  j  a v  a  2 s. c o  m*/
 * 
 * @param queue
 */
public void registerQueue(final IMessageQueue<AisMessage> queue) {
    requireNonNull(queue);
    registerHandler(new Consumer<AisMessage>() {
        @Override
        public void accept(AisMessage message) {
            try {
                queue.push(message);
            } catch (MessageQueueOverflowException e) {
                LOG.error("Message queue overflow, dropping message: " + e.getMessage());
            }
        }
    });
}

From source file:de.jackwhite20.japs.client.cache.impl.PubSubCacheImpl.java

@Override
public Future<Boolean> has(String key) {

    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("key cannot be null or empty");
    }/*from   w  w  w . ja  va 2s .  c  om*/

    return executorService.submit(() -> {

        int id = CALLBACK_COUNTER.getAndIncrement();

        AtomicBoolean has = new AtomicBoolean(false);

        CountDownLatch countDownLatch = new CountDownLatch(1);

        callbacks.put(id, new Consumer<JSONObject>() {

            @Override
            public void accept(JSONObject jsonObject) {

                has.set(jsonObject.getBoolean("has"));

                countDownLatch.countDown();
            }
        });

        JSONObject jsonObject = new JSONObject().put("op", OpCode.OP_CACHE_HAS.getCode()).put("key", key)
                .put("id", id);

        write(jsonObject);

        countDownLatch.await();

        return has.get();
    });
}

From source file:com.vsthost.rnd.jdeoptim.diagnostics.Diagnostics.java

/**
 * Defines a signal to be emitted when an evolution has finished.
 *
 * @param population The population as of the evolution has finished.
 *//*  ww  w  .  jav a 2 s  . c  o  m*/
public void evolutionFinished(final Population population) {
    this.observers.forEach(new Consumer<Listener>() {
        @Override
        public void accept(Listener observer) {
            observer.evolutionFinished(population);
        }
    });
}

From source file:org.eclipse.vorto.maven.GeneratorMojo.java

private byte[] loadMappingModels() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ZipOutputStream zaos = new ZipOutputStream(baos);

    Files.walk(Paths.get((project.getBasedir().toURI()))).filter(new Predicate<Path>() {

        public boolean test(Path path) {
            return !path.toFile().isDirectory()
                    && (path.getFileName().toString().endsWith(ModelType.Mapping.getExtension())
                            || path.getFileName().toString().endsWith(ModelType.Functionblock.getExtension()));
        }/*from w  w  w . j a v  a  2 s  .c  o  m*/
    }).forEach(new Consumer<Path>() {

        public void accept(Path t) {
            addToZip(zaos, t);
        }
    });

    return baos.toByteArray();
}

From source file:gedi.atac.Atac.java

public static void buildFseqBed(String path, GenomicRegionStorage<? extends AlignedReadsData> storage)
        throws IOException {

    int offset = 4;
    LineOrientedFile out = new LineOrientedFile(path);
    out.startWriting();//from w  w  w  . j a va2  s  .  c o  m
    ConsoleProgress progress = new ConsoleProgress();
    progress.init();

    storage.iterateMutableReferenceGenomicRegions(Chromosome.obtain("chr9"))
            .forEachRemaining(new Consumer<MutableReferenceGenomicRegion<? extends AlignedReadsData>>() {

                @Override
                public void accept(MutableReferenceGenomicRegion<? extends AlignedReadsData> mrgr) {
                    try {
                        int v = mrgr.getData().getTotalCountOverallInt(ReadCountMode.All);
                        if (v != 0) {
                            writeBed(out, mrgr.getReference(), GenomicRegionPosition.Start
                                    .position(mrgr.getReference(), mrgr.getRegion(), offset), "+", v);
                            writeBed(out, mrgr.getReference(), GenomicRegionPosition.Stop
                                    .position(mrgr.getReference(), mrgr.getRegion(), -offset), "-", v);
                        }
                        progress.setDescription(mrgr.getReference() + ":" + mrgr.getRegion());
                        progress.incrementProgress();
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }

            });

    progress.finish();
    out.finishWriting();
}