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:com.evolveum.midpoint.provisioning.impl.manual.TestSemiManual.java

private String formatCsvLine(String[] data) {
    return Arrays.stream(data).map(s -> "\"" + s + "\"").collect(Collectors.joining(","));
}

From source file:at.tfr.securefs.client.SecurefsClient.java

public void parse(String[] args) throws ParseException {
    CommandLineParser clp = new DefaultParser();
    CommandLine cmd = clp.parse(options, args);
    baseDir = cmd.getOptionValue("b");
    Arrays.stream(cmd.getOptionValue("f").split(",")).forEach(f -> files.add(Paths.get(f)));
    asyncTest = Boolean.parseBoolean(cmd.getOptionValue("a", "false"));
    threads = Integer.parseInt(cmd.getOptionValue("t", "1"));
    if (cmd.hasOption("r") || cmd.hasOption("w") || cmd.hasOption("d")) {
        read = write = delete = false;//w  w w  .j  av  a2  s  .  c  o m
        read = cmd.hasOption("r");
        write = cmd.hasOption("w");
        delete = cmd.hasOption("d");
    }
}

From source file:org.openlmis.fulfillment.Resource2Db.java

/**
 * Inserts data into a single table.  Given the columns and a list of data to insert, will
 * run a batch update to insert it./*  www .  j  a va 2s  .  c  om*/
 * @param tableName the name of the table (including schema) to insert into.
 * @param dataWithHeader a pair where pair.left is an ordered list of column names and pair.right
 *                       is an array of rows to insert, where each row is similarly ordered as
 *                       the columns in pair.left.
 */
private void insertToDbFromBatchedPair(String tableName, Pair<List<String>, List<Object[]>> dataWithHeader) {
    XLOGGER.entry(tableName);

    String columnDesc = dataWithHeader.getLeft().stream().collect(joining(","));
    String valueDesc = dataWithHeader.getLeft().stream().map(s -> "?").collect((joining(",")));
    String insertSql = String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, columnDesc, valueDesc);
    XLOGGER.info("Insert SQL: " + insertSql);

    List<Object[]> data = dataWithHeader.getRight();
    data.forEach(e -> XLOGGER.info(tableName + ": " + Arrays.toString(e)));
    int[] updateCount = template.batchUpdate(insertSql, data);

    XLOGGER.exit("Total " + tableName + " inserts: " + Arrays.stream(updateCount).sum());
}

From source file:org.fenixedu.bennu.spring.BennuSpringConfiguration.java

private Set<String> getBaseNames(ApplicationContext context) {
    final Set<String> baseNames = new HashSet<>();
    baseNames.add(getBundleBasename("BennuSpringResources"));
    final String[] beanNames = context.getBeanNamesForAnnotation(BennuSpringModule.class);
    for (String beanName : beanNames) {
        BennuSpringModule bennuSpringModuleAnnotation = context.findAnnotationOnBean(beanName,
                BennuSpringModule.class);
        if (bennuSpringModuleAnnotation != null) {
            baseNames.addAll(Arrays.stream(bennuSpringModuleAnnotation.bundles()).map(this::getBundleBasename)
                    .collect(Collectors.toSet()));
        }// ww w  . j a va 2s . co  m
    }
    return baseNames;
}

From source file:com.intellij.plugins.haxe.model.HaxeFileModel.java

public List<HaxeUsingModel> getUsingModels() {
    return Arrays.stream(file.getChildren()).filter(element -> element instanceof HaxeUsingStatement)
            .map(element -> ((HaxeUsingStatement) element).getModel()).collect(Collectors.toList());
}

From source file:org.apache.james.ESReporterTest.java

private boolean checkMetricRecordedInElasticSearch() {
    try (Client client = embeddedElasticSearchRule.getNode().client()) {
        return !Arrays
                .stream(client.prepareSearch().setQuery(QueryBuilders.matchAllQuery()).get().getHits()
                        .getHits())/*from   w  w w  .  j  av a  2  s  .c  o m*/
                .filter(searchHit -> searchHit.getIndex().startsWith(TestESMetricReporterModule.METRICS_INDEX))
                .collect(Collectors.toList()).isEmpty();
    } catch (Exception e) {
        return false;
    }
}

From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java

@Override
public TreeItem<TimeSeriesBinding<Double>> getBindingTree() throws DataAdapterException {
    Gson gson = new Gson();
    try {//  www  . j av a  2 s  .c o  m
        JsonJrdsTree t = gson.fromJson(getJsonTree(treeViewTab.getCommand(), treeViewTab.getArgument(), filter),
                JsonJrdsTree.class);
        Map<String, JsonJrdsItem> m = Arrays.stream(t.items).collect(Collectors.toMap(o -> o.id, (o -> o)));
        TreeItem<TimeSeriesBinding<Double>> tree = new TreeItem<>(
                bindingFactory.of("", getSourceName(), "/", this));
        for (JsonJrdsItem branch : Arrays.stream(t.items).filter(
                jsonJrdsItem -> JRDS_TREE.equals(jsonJrdsItem.type) || JRDS_FILTER.equals(jsonJrdsItem.type))
                .collect(Collectors.toList())) {
            attachNode(tree, branch.id, m);
        }
        return tree;
    } catch (JsonParseException e) {
        throw new DataAdapterException(
                "An error occurred while parsing the json response to getBindingTree request", e);
    } catch (URISyntaxException e) {
        throw new SourceCommunicationException("Error building URI for request", e);
    }
}

From source file:com.github.nginate.commons.testing.Unique.java

@SafeVarargs
@SuppressWarnings("varargs")
private static Stream<Character> getCharsStream(Pair<Character, Character>... fromToInclusivePairs) {
    int[] validChars = Arrays.stream(fromToInclusivePairs)
            .flatMapToInt(fromTo -> IntStream.rangeClosed(fromTo.getLeft(), fromTo.getRight())).toArray();
    return IntStream.iterate(0, i -> i + 1)
            .map(i -> validChars[i - validChars.length * (i / validChars.length)])
            .mapToObj(charCode -> (char) charCode);
}

From source file:acmi.l2.clientmod.xdat.Controller.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    interfaceResources = resources;/*from   w ww .  j  a  va2 s.  co  m*/

    Node scriptingTab = loadScriptTabContent();

    initialDirectory.addListener((observable, oldVal, newVal) -> {
        if (newVal != null)
            XdatEditor.getPrefs().put("initialDirectory", newVal.getPath());
    });
    editor.xdatClassProperty().addListener((ob, ov, nv) -> {
        log.log(Level.INFO, String.format("XDAT class selected: %s", nv.getName()));

        tabs.getTabs().clear();

        for (Iterator<InvalidationListener> it = xdatListeners.iterator(); it.hasNext();) {
            editor.xdatObjectProperty().removeListener(it.next());
            it.remove();
        }

        editor.setXdatObject(null);

        if (scriptingTab != null) {
            Tab tab = new Tab("script console");
            tab.setContent(scriptingTab);
            tabs.getTabs().add(tab);
        }

        Arrays.stream(nv.getDeclaredFields()).filter(field -> List.class.isAssignableFrom(field.getType()))
                .forEach(field -> {
                    field.setAccessible(true);
                    tabs.getTabs().add(createTab(field));
                });
    });
    progressBar.visibleProperty().bind(editor.workingProperty());
    open.disableProperty().bind(Bindings.isNull(editor.xdatClassProperty()));
    BooleanBinding nullXdatObject = Bindings.isNull(editor.xdatObjectProperty());
    tabs.disableProperty().bind(nullXdatObject);
    save.disableProperty().bind(nullXdatObject);
    saveAs.disableProperty().bind(nullXdatObject);

    xdatFile.addListener((observable, oldValue, newValue) -> {
        if (newValue == null)
            return;

        Collection<File> files = FileUtils.listFiles(newValue.getParentFile(),
                new WildcardFileFilter("SysString-*.dat"), null);
        if (!files.isEmpty()) {
            File file = files.iterator().next();
            log.info("sysstring file: " + file);
            try (InputStream is = L2Crypt.decrypt(new FileInputStream(file), file.getName())) {
                SysstringPropertyEditor.strings.clear();
                int count = IOUtil.readInt(is);
                for (int i = 0; i < count; i++) {
                    SysstringPropertyEditor.strings.put(IOUtil.readInt(is), IOUtil.readString(is));
                }
            } catch (Exception ignore) {
            }
        }

        File file = new File(newValue.getParentFile(), "L2.ini");
        try {
            TexturePropertyEditor.environment = new Environment(file);
            TexturePropertyEditor.environment.getPaths().forEach(s -> log.info("environment path: " + s));
        } catch (Exception ignore) {
        }
    });
}