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:lda.inference.internal.CollapsedGibbsSampler.java

/**
 * Get the full conditional distribution over topics.
 * docID and vocabID are passed to this distribution for parameters.
 * @param numTopics// www  .  j  av a 2 s  .c  o  m
 * @param docID
 * @param vocabID
 * @return the integer distribution over topics
 */
IntegerDistribution getFullConditionalDistribution(final int numTopics, final int docID, final int vocabID) {
    int[] topics = IntStream.range(0, numTopics).toArray();
    double[] probabilities = Arrays.stream(topics).mapToDouble(t -> getTheta(docID, t) * getPhi(t, vocabID))
            .toArray();
    return new EnumeratedIntegerDistribution(topics, probabilities);
}

From source file:eu.tripledframework.eventstore.infrastructure.ReflectionObjectConstructor.java

private Method getEventHandlerMethods(DomainEvent event) {
    Set<Method> methods = Arrays.stream(targetClass.getMethods())
            .filter(constructor -> constructor.isAnnotationPresent(ConstructionHandler.class))
            .collect(Collectors.toSet());
    for (Method method : methods) {
        ConstructionHandler annotation = method.getAnnotation(ConstructionHandler.class);
        if (annotation.value().equals(event.getClass())) {
            return method;
        }/*from   w w w  . ja  v a 2 s. c  o m*/
    }
    return null;
}

From source file:org.mascherl.session.MascherlSessionStorage.java

public MascherlSession restoreSession(HttpServletRequest request) {
    MascherlSession mascherlSession = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        Optional<Cookie> cookieOptional = Arrays.stream(cookies)
                .filter((cookie) -> Objects.equals(cookieName, cookie.getName())).findAny();
        if (cookieOptional.isPresent()) {
            String encryptedValue = cookieOptional.get().getValue();
            try {
                String data = cryptoHelper.decryptAES(encryptedValue);
                mascherlSession = new MascherlSession(objectMapper, data);
            } catch (RuntimeException e) {
                logger.log(Level.WARNING, "Session could not be restored. Will continue with empty session.",
                        e);/* w w w.ja  v a  2  s .  c om*/
            }
        }
    }
    if (mascherlSession == null) {
        mascherlSession = new MascherlSession(objectMapper); // no session available, return a new one
    }

    request.setAttribute(MASCHERL_SESSION_REQUEST_ATTRIBUTE, mascherlSession);
    return mascherlSession;
}

From source file:com.demonwav.mcdev.creator.LiteLoaderProjectSettingsWizard.java

public LiteLoaderProjectSettingsWizard(@NotNull MinecraftProjectCreator creator) {
    this.creator = creator;

    mcpWarning.setVisible(false);//from  w w w . j a v  a  2  s . c o m

    minecraftVersionBox.addActionListener(e -> {
        if (mcpVersion != null) {
            mcpVersion.setMcpVersion(mcpVersionBox, (String) minecraftVersionBox.getSelectedItem(),
                    mcpBoxActionListener);
        }
    });

    pluginNameField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            if (mainClassModified) {
                return;
            }

            String[] words = pluginNameField.getText().split("\\s+");
            String word = Arrays.stream(words).map(WordUtils::capitalize).collect(Collectors.joining());

            String[] mainClassWords = mainClassField.getText().split("\\.");
            mainClassWords[mainClassWords.length - 1] = LITEMOD + word;

            mainClassField.getDocument().removeDocumentListener(listener);
            mainClassField.setText(Arrays.stream(mainClassWords).collect(Collectors.joining(".")));
            mainClassField.getDocument().addDocumentListener(listener);
        }
    });

    mainClassField.getDocument().addDocumentListener(listener);

    try {
        new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                mcpVersion = McpVersion.downloadData();
                return null;
            }

            @Override
            protected void done() {
                if (mcpVersion == null) {
                    return;
                }

                minecraftVersionBox.removeAllItems();

                mcpVersion.getVersions().forEach(minecraftVersionBox::addItem);
                // Always select most recent
                minecraftVersionBox.setSelectedIndex(0);

                if (mcpVersion != null) {
                    mcpVersion.setMcpVersion(mcpVersionBox, (String) minecraftVersionBox.getSelectedItem(),
                            mcpBoxActionListener);
                }

                loadingBar.setIndeterminate(false);
                loadingBar.setVisible(false);
            }
        }.execute();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ddf.lib.OwaspDiffRunner.java

private static String getMavenHome() throws OwaspDiffRunnerException {
    String mavenHome;//from   www.j  a v  a 2s .  c o  m
    String mavenVersionInfo;

    try {
        mavenVersionInfo = IOUtils.toString(runTime.exec(MAVEN_VERSION_COMMAND).getInputStream());

        //parsing console response, confirmed to work with at least maven version 3.3.9
        mavenHome = Arrays.stream(mavenVersionInfo.split(System.getProperty("line.separator")))
                .filter(str -> str.contains("Maven home:")).findFirst().get().split("Maven home:")[1].trim();

    } catch (Exception e) {
        throw new OwaspDiffRunnerException(OwaspDiffRunnerException.UNABLE_TO_RETRIEVE_MAVEN_HOME, e);
    }

    return mavenHome;
}

From source file:org.jboss.forge.addon.springboot.commands.setup.SetupProjectCommand.java

private static List<String> splitVersions(String s) {
    return Arrays.stream(s.split(",")).distinct().filter(element -> !element.isEmpty())
            .collect(Collectors.toList());
}

From source file:com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationManager.java

private void resolvePolicyProperties() {
    final String policyCheckFailOnSeverities = detectConfiguration
            .getProperty(DetectProperty.DETECT_POLICY_CHECK_FAIL_ON_SEVERITIES, PropertyAuthority.None);
    final boolean atLeastOnePolicySeverity = StringUtils.isNotBlank(policyCheckFailOnSeverities);
    if (atLeastOnePolicySeverity) {
        boolean allSeverities = false;
        final String[] splitSeverities = policyCheckFailOnSeverities.split(",");
        for (final String severity : splitSeverities) {
            if (severity.equalsIgnoreCase("ALL")) {
                allSeverities = true;//w ww.ja va2 s. c  o  m
                break;
            }
        }
        if (allSeverities) {
            final List<String> allPolicyTypes = Arrays.stream(PolicySeverityType.values())
                    .filter(type -> type != PolicySeverityType.UNSPECIFIED).map(type -> type.toString())
                    .collect(Collectors.toList());
            this.policyCheckFailOnSeverities = StringUtils.join(allPolicyTypes, ",");
        } else {
            this.policyCheckFailOnSeverities = StringUtils.join(splitSeverities, ",");
        }
    }
}

From source file:com.offbynull.coroutines.antplugin.InstrumentTask.java

@Override
public void execute() throws BuildException {
    // Check classpath
    if (classpath == null) {
        throw new BuildException("Classpath not set");
    }/*w ww . j a  v  a 2s  .c o  m*/

    // Check source directory
    if (sourceDirectory == null) {
        throw new BuildException("Source directory not set");
    }
    if (!sourceDirectory.isDirectory()) {
        throw new BuildException("Source directory is not a directory: " + sourceDirectory.getAbsolutePath());
    }

    // Check target directory
    if (targetDirectory == null) {
        throw new BuildException("Target directory not set");
    }
    try {
        FileUtils.forceMkdir(targetDirectory);
    } catch (IOException ioe) {
        throw new BuildException("Unable to create target directory", ioe);
    }

    // Check JDK libs directory
    if (jdkLibsDirectory == null) {
        throw new BuildException("JDK libs directory not set");
    }
    if (!jdkLibsDirectory.isDirectory()) {
        throw new BuildException(
                "JDK libs directory is not a directory: " + jdkLibsDirectory.getAbsolutePath());
    }

    List<File> combinedClasspath;
    try {
        log("Getting compile classpath", Project.MSG_DEBUG);
        combinedClasspath = Arrays.stream(classpath.split(";")).map(x -> x.trim()).filter(x -> !x.isEmpty())
                .map(x -> new File(x)).collect(Collectors.toList());
        log("Getting bootstrap classpath", Project.MSG_DEBUG);
        combinedClasspath.addAll(FileUtils.listFiles(jdkLibsDirectory, new String[] { "jar" }, true));

        log("Classpath for instrumentation is as follows: " + combinedClasspath, Project.MSG_INFO);
    } catch (Exception ex) {
        throw new BuildException("Unable to get compile classpath elements", ex);
    }

    Instrumenter instrumenter;
    try {
        log("Creating instrumenter...", Project.MSG_INFO);
        instrumenter = new Instrumenter(combinedClasspath);

        log("Processing " + sourceDirectory.getAbsolutePath() + " ... ", Project.MSG_INFO);
        instrumentPath(instrumenter);
    } catch (Exception ex) {
        throw new BuildException("Failed to instrument", ex);
    }
}

From source file:me.rkfg.xmpp.bot.plugins.CoolStoryPlugin.java

@Override
public List<String> getCommand() {
    return Arrays.stream(WEBSITES).flatMap(w -> Arrays.stream(w.getCommands())).collect(Collectors.toList());
}

From source file:com.appdynamics.cloudfoundry.appdservicebroker.catalog.Service.java

Service requires(String... requires) {
    synchronized (this.monitor) {
        if (this.requires == null) {
            this.requires = new ArrayList<>();
        }//from   w ww . j a  va 2  s .  com
        Arrays.stream(requires).forEach(this.requires::add);
        return this;
    }
}