Example usage for java.util Arrays stream

List of usage examples for java.util Arrays stream

Introduction

In this page you can find the example usage for java.util Arrays stream.

Prototype

public static DoubleStream stream(double[] array) 

Source Link

Document

Returns a sequential DoubleStream with the specified array as its source.

Usage

From source file:act.installer.reachablesexplorer.FreemarkerRenderer.java

public static void main(String[] args) throws Exception {
    CLIUtil cliUtil = new CLIUtil(Loader.class, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);

    File baseOutputDir = new File(cl.getOptionValue(OPTION_OUTPUT_DEST));
    if (!baseOutputDir.exists()) {
        cliUtil.failWithMessage("Unable to find output directory at %s", baseOutputDir.getAbsolutePath());
        return;/*from  w  w w. j  a  v a2s .  co m*/
    }

    File reachablesOut = new File(baseOutputDir, "Reachables");
    File pathsOut = new File(baseOutputDir, "Paths");
    File seqsOut = new File(baseOutputDir, "Sequences");

    for (File subdir : Arrays.asList(reachablesOut, pathsOut, seqsOut)) {
        if (!subdir.exists()) {
            LOGGER.info("Creating output directory at %s", subdir.getAbsolutePath());
            subdir.mkdir();
        } else if (!subdir.isDirectory()) {
            cliUtil.failWithMessage("Output directory at %s is not a directory", subdir.getAbsolutePath());
            return;
        }
    }

    FreemarkerRenderer renderer = FreemarkerRendererFactory.build(
            cl.getOptionValue(OPTION_DB_HOST, DEFAULT_HOST),
            Integer.valueOf(cl.getOptionValue(OPTION_DB_PORT, DEFAULT_PORT.toString())),
            cl.getOptionValue(OPTION_DB_NAME, DEFAULT_DB_NAME),
            cl.getOptionValue(OPTION_REACHABLES_COLLECTION, DEFAULT_REACHABLES_COLLECTION),
            cl.getOptionValue(OPTION_SEQUENCES_COLLECTION, DEFAULT_SEQUENCES_COLLECTION),
            cl.getOptionValue(OPTION_DNA_COLLECTION, DEFAULT_DNA_COLLECTION),
            cl.getOptionValue(OPTION_RENDERING_CACHE, DEFAULT_RENDERING_CACHE),
            cl.getOptionValue(OPTION_INSTALLER_SOURCE_DB, DEFAULT_CHEMICALS_DATABASE),
            cl.getOptionValue(OPTION_PATHWAY_COLLECTION, DEFAULT_PATHWAY_COLLECTION),
            cl.hasOption(OPTION_OMIT_PATHWAYS_AND_DESIGNS), reachablesOut, pathsOut, seqsOut);
    LOGGER.info("Page generation starting");

    List<Long> idsToRender = Collections.emptyList();
    if (cl.hasOption(OPTION_RENDER_SOME)) {
        idsToRender = Arrays.stream(cl.getOptionValues(OPTION_RENDER_SOME)).map(renderer::lookupMolecule)
                .collect(Collectors.toList());
    }
    renderer.generatePages(idsToRender);
}

From source file:com.blackducksoftware.integration.hub.detect.detector.gradle.GradleInspectorExtractor.java

public Extraction extract(final File directory, final String gradleExe, final String gradleInspector,
        final File outputDirectory) {
    try {/* w  w  w .j ava2  s.  c  om*/
        String gradleCommand = detectConfiguration.getProperty(DetectProperty.DETECT_GRADLE_BUILD_COMMAND,
                PropertyAuthority.None);

        final List<String> arguments = new ArrayList<>();
        if (StringUtils.isNotBlank(gradleCommand)) {
            gradleCommand = gradleCommand.replaceAll("dependencies", "").trim();
            Arrays.stream(gradleCommand.split(" ")).filter(StringUtils::isNotBlank).forEach(arguments::add);
        }
        arguments.add("dependencies");
        arguments.add(String.format("--init-script=%s", gradleInspector));
        arguments.add(String.format("-DGRADLEEXTRACTIONDIR=%s", outputDirectory.getCanonicalPath()));
        arguments.add("--info");

        final Executable executable = new Executable(directory, gradleExe, arguments);
        final ExecutableOutput output = executableRunner.execute(executable);

        if (output.getReturnCode() == 0) {
            final File rootProjectMetadataFile = detectFileFinder.findFile(outputDirectory,
                    "rootProjectMetadata.txt");
            final List<File> codeLocationFiles = detectFileFinder.findFiles(outputDirectory,
                    "*_dependencyGraph.txt");

            final List<DetectCodeLocation> codeLocations = new ArrayList<>();
            String projectName = null;
            String projectVersion = null;
            if (codeLocationFiles != null) {
                codeLocationFiles.stream()
                        .map(codeLocationFile -> gradleReportParser.parseDependencies(codeLocationFile))
                        .filter(Optional::isPresent).map(Optional::get).forEach(codeLocations::add);

                if (rootProjectMetadataFile != null) {
                    final Optional<NameVersion> projectNameVersion = gradleReportParser
                            .parseRootProjectNameVersion(rootProjectMetadataFile);
                    if (projectNameVersion.isPresent()) {
                        projectName = projectNameVersion.get().getName();
                        projectVersion = projectNameVersion.get().getVersion();
                    }
                } else {
                    logger.warn(
                            "Gradle inspector did not create a meta data report so no project version information was found.");
                }
            }
            return new Extraction.Builder().success(codeLocations).projectName(projectName)
                    .projectVersion(projectVersion).build();
        } else {
            return new Extraction.Builder()
                    .failure("The gradle inspector returned a non-zero exit code: " + output.getReturnCode())
                    .build();
        }
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}

From source file:net.buildstatic.mappacker.command.PackCommand.java

public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
    try {/*from  ww w .  j a  va  2s  . c  o m*/
        if (args.length > 1) {
            World world = Bukkit.getWorld(args[0]);
            if (world != null) {
                File tempDir = new File(System.getProperty("java.io.tmpdir"));
                File tempWorld = new File(tempDir,
                        world.getWorldFolder().getName() + File.separator + world.getWorldFolder().getName());
                FileUtils.copyDirectory(world.getWorldFolder(), tempWorld);

                File mapDat = new File(tempWorld, "map.dat");
                if (!mapDat.exists() && !mapDat.createNewFile()) {
                    FileUtils.deleteDirectory(tempWorld);
                    sender.sendMessage(
                            ChatColor.RED + "Error: Aborting... unable to create map.dat. Try again?");
                    return false;
                }
                YamlConfiguration configuration = YamlConfiguration.loadConfiguration(mapDat);
                StringBuilder creator = new StringBuilder();
                for (int i = 1; i < args.length; i++) {
                    creator.append(i == 1 || i + 1 == args.length ? "" : " ");
                    creator.append(args[i]);
                }
                configuration.set("Creator", creator.toString());
                configuration.save(mapDat);

                Arrays.stream(FILES_TO_REMOVE).forEach(fileName -> {
                    File file = new File(tempWorld, fileName);
                    if (file.isDirectory())
                        Arrays.stream(file.listFiles()).forEach(file1 -> file1.delete());
                    file.delete();
                });

                File zipped = new File(MapPacker.getInstance().getDataFolder(), tempWorld.getName() + ".zip");
                if (zipped.exists() && !zipped.delete()) {
                    sender.sendMessage(ChatColor.RED + "Error: Unable to delete old zip. Try again?");
                    FileUtils.deleteDirectory(tempWorld);
                    return false;
                }
                ZipUtil.pack(new File(tempDir, world.getWorldFolder().getName()), zipped);
                if (zipped.exists())
                    sender.sendMessage(ChatColor.GREEN + "Success! The map is all ready to go @ "
                            + zipped.getAbsolutePath() + ".");
                else
                    sender.sendMessage(ChatColor.RED + "Error: File was not able to be zipped up. Try again?");

                FileUtils.deleteDirectory(tempWorld);
                return true;
            }
            sender.sendMessage(ChatColor.RED + "Error: \"" + args[0] + "\" is not a valid world.");
        } else
            sender.sendMessage(ChatColor.RED + "Usage: /pack <world name> <creator>");
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return false;
}

From source file:edu.washington.gs.skyline.model.quantification.FoldChangeDataSet.java

/**
 * Construct a new FoldChangeDataSet.  The first four collections must all have the same number of elements.
 * The "subjectControls" must have the same number of elements as the number of unique values of "subjects".
 * @param abundances log2 intensity// w w w.  j  a va  2  s. com
 * @param features identifiers of the transition that the abundance was measured for.  Note that Skyline always sums
 *                 the transition intensities before coming in here, the feature values should all be zero.
 * @param runs integers representing which replicate the value came from
 * @param subjects identifiers used for combining biological replicates.
 * @param subjectControls specifies which subject values belong to the control group.
 */
public FoldChangeDataSet(Collection<Double> abundances, Collection<Integer> features, Collection<Integer> runs,
        Collection<Integer> subjects, Collection<Boolean> subjectControls) {
    if (abundances.size() != features.size() || abundances.size() != subjects.size()
            || abundances.size() != runs.size()) {
        throw new IllegalArgumentException("Wrong number of rows");
    }
    this.abundances = abundances.stream().mapToDouble(Double::doubleValue).toArray();
    this.features = features.stream().mapToInt(Integer::intValue).toArray();
    this.runs = runs.stream().mapToInt(Integer::intValue).toArray();
    this.subjects = subjects.stream().mapToInt(Integer::intValue).toArray();
    this.subjectControls = ArrayUtils.toPrimitive(subjectControls.toArray(new Boolean[subjectControls.size()]));
    if (this.abundances.length == 0) {
        featureCount = 0;
        subjectCount = 0;
        runCount = 0;
    } else {
        if (Arrays.stream(this.features).min().getAsInt() < 0 || Arrays.stream(this.runs).min().getAsInt() < 0
                || Arrays.stream(this.subjects).min().getAsInt() < 0) {
            throw new IllegalArgumentException("Cannot be negative");
        }
        featureCount = Arrays.stream(this.features).max().getAsInt() + 1;
        subjectCount = Arrays.stream(this.subjects).max().getAsInt() + 1;
        runCount = Arrays.stream(this.runs).max().getAsInt() + 1;
    }
    if (this.subjectControls.length != subjectCount) {
        throw new IllegalArgumentException("Wrong number of subjects");
    }
}

From source file:com.adobe.acs.commons.data.Spreadsheet.java

public Spreadsheet(boolean convertHeaderNames, InputStream file, String... required) throws IOException {
    delimiters = new HashMap<>();
    this.enableHeaderNameConversion = convertHeaderNames;
    if (required == null || required.length == 0) {
        requiredColumns = Collections.EMPTY_LIST;
    } else {/*from ww  w.  ja  v a  2  s  .c  o m*/
        requiredColumns = Arrays.stream(required).map(this::convertHeaderName).collect(Collectors.toList());
    }
    parseInputFile(file);
}

From source file:de.rkl.tools.tzconv.configuration.PreferencesProvider.java

public List<ZoneId> getPreferredSelectedZoneIds() {
    final String preferredZoneIdsString = applicationPreferences.get(PREFERENCES_KEY_SELECTED_ZONE_IDS, null);
    return (isBlank(preferredZoneIdsString) ? null
            : Arrays.stream(preferredZoneIdsString.split(PREFERENCES_SELECTED_ZONE_IDS_DELIMITER))
                    .map(ZoneId::of).collect(toList()));
}

From source file:jp.co.opentone.bsol.framework.core.elasticsearch.response.ElasticsearchSearchResultRecord.java

/**
 * ?????????Stream?./*ww  w  .j  ava  2s  . com*/
 * @see Stream
 * @param fieldName ??
 * @return {@link Stream}
 */
public Stream<String> getHighlightedFragments(String fieldName) {
    HighlightField field = hit.getHighlightFields().get(fieldName);
    if (field != null) {
        Stream<Text> s = Arrays.stream(field.getFragments());
        return s.map(t -> t.string());
    }

    return new ArrayList<String>().stream();
}

From source file:Combiner.MaxDepthCombiner.java

private double[] combineSingle(double[] called, double[] imputed, int[] reads) {
    if (Arrays.stream(reads).sum() <= maxDepth) {
        double[] totalProb = new double[3];

        totalProb[0] = w * imputed[0] + (1.0 - w) * called[0];
        totalProb[1] = w * imputed[1] + (1.0 - w) * called[1];
        totalProb[2] = w * imputed[2] + (1.0 - w) * called[2];

        return totalProb;
    } else {//ww w .j a  v  a  2  s  . co  m
        return called;
    }
}

From source file:com.github.triceo.robozonky.app.CommandLineInterface.java

/**
 * Convert the command line arguments into a string and log it.
 * @param cli Parsed command line./*from  w w  w  .  j av a 2 s .  co m*/
 */
private static void logOptionValues(final CommandLine cli) {
    final List<String> optionsString = Arrays.stream(cli.getOptions()).filter(o -> cli.hasOption(o.getOpt()))
            .filter(o -> !o.equals(CommandLineInterface.OPTION_PASSWORD)).map(o -> {
                String result = "-" + o.getOpt();
                final String value = cli.getOptionValue(o.getOpt());
                if (value != null) {
                    result += " " + value;
                }
                return result;
            }).collect(Collectors.toList());
    CommandLineInterface.LOGGER.debug("Processing command line: {}.", optionsString);
}

From source file:alfio.manager.EventNameManager.java

private Optional<String> getCroppedName(String cleanDisplayName) {
    String candidate = Arrays.stream(cleanDisplayName.split(SPACES_AND_PUNCTUATION))
            .map(w -> Pair.of(NUMBER_MATCHER.matcher(w).matches(), w))
            .map(p -> p.getKey() ? p.getValue() : StringUtils.left(p.getValue(), 1))
            .collect(Collectors.joining());
    if (isUnique(candidate)) {
        return Optional.of(candidate);
    }//from  ww  w . j  a  v a 2s.com
    return Optional.empty();
}