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:co.runrightfast.akka.AkkaUtils.java

/**
 * Concatenates the path via path separator : '/'
 *
 *
 * @param basePath base path//from   w  ww  .j a va  2s .  com
 * @param path appended to base path
 * @param paths optional additional paths
 * @return actor path
 */
static String actorPath(final String basePath, final String path, final String... paths) {
    notBlank(basePath, "basePath");
    notBlank(path, "path");
    if (paths != null) {
        Validate.noNullElements(paths);
    }

    final StringBuilder sb = new StringBuilder(128).append(basePath).append('/').append(path);

    if (paths != null) {
        Arrays.stream(paths).forEach(p -> sb.append('/').append(p));
    }

    return sb.toString();
}

From source file:com.thinkbiganalytics.nifi.provenance.util.ProvenanceEventUtil.java

public static boolean contains(ProvenanceEventType[] allowedEvents, ProvenanceEventType event) {
    return Arrays.stream(allowedEvents).anyMatch(event::equals);
}

From source file:Main.java

/**
 * @param entries//www. j a  v  a2s.co  m
 *                the <i>final</i> set of entries to add to the newly created
 * <i>unmodifiable</i> map
 * @param <K>     the key type
 * @param <V>     the value type
 *
 * @return an <i>unmodifiable</i> map with all given entries
 */
@SafeVarargs
@SuppressWarnings("varargs")
public static <K, V> Map<K, V> map(Entry<K, V>... entries) {
    return Collections
            .unmodifiableMap(Arrays.stream(entries).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
}

From source file:Main.java

@SafeVarargs
public static <T> Set<T> union(Set<T>... elements) {
    return Arrays.stream(elements).flatMap(Set::stream).collect(toSet());
}

From source file:edu.umd.umiacs.clip.tools.math.Formatter.java

public static List<Double> format(double[] array) {
    return Arrays.stream(array).map(Formatter::format).boxed().collect(toList());
}

From source file:org.leandreck.endpoints.processor.model.VariableAnnotations.java

public static boolean isOptional(final AnnotationMirror annotationMirror) {
    final boolean relevantAnnotation = Arrays.stream(VariableAnnotations.values())
            .map(it -> annotationMirror.getAnnotationType().toString().startsWith(it.annotation))
            .reduce((a, b) -> a || b).orElse(false);

    final boolean optional;
    if (relevantAnnotation) {
        final String required = annotationMirror.getElementValues().entrySet().stream()
                .filter(e -> e.getKey().toString().equals("required()")).map(e -> e.getValue().toString())
                .findFirst().orElse("true");
        optional = !Boolean.valueOf(required);
    } else {/*  w w w.  j  a v a 2  s . c  o  m*/
        optional = false;
    }

    return optional;
}

From source file:com.thoughtworks.go.agent.common.util.HeaderUtil.java

public static Map<String, String> parseExtraProperties(Header extraPropertiesHeader) {
    if (extraPropertiesHeader == null || StringUtils.isBlank(extraPropertiesHeader.getValue())) {
        return new HashMap<>();
    }/*from www  .  ja v  a 2 s.  com*/

    try {
        final String headerValue = new String(Base64.decodeBase64(extraPropertiesHeader.getValue()), UTF_8);

        if (StringUtils.isBlank(headerValue)) {
            return new HashMap<>();
        }

        return Arrays.stream(headerValue.trim().split(" +")).map(property -> property.split("="))
                .collect(Collectors.toMap(keyAndValue -> keyAndValue[0].replaceAll("%20", " "),
                        keyAndValue -> keyAndValue[1].replaceAll("%20", " "), (value1, value2) -> value1,
                        LinkedHashMap::new));
    } catch (Exception e) {
        LOGGER.warn("Failed to parse extra properties header value: {}", extraPropertiesHeader.getValue(), e);
        return new HashMap<>();
    }
}

From source file:com.thoughtworks.go.config.rules.SupportedEntity.java

public static SupportedEntity fromString(String type) {
    return Arrays.stream(values()).filter(t -> equalsIgnoreCase(t.type, type)).findFirst().orElse(UNKNOWN);
}

From source file:Main.java

/**
 * Lists and filters data in array and returns with applied filter.
 * /*from w w  w . java  2  s  . c o  m*/
 * @param <T>
 *            Class for array where you get random item.
 * @param array
 *            Lists data in array.
 * @param filter
 *            Applies filter to array.
 * @return Array is returned with applied filter.
 */
public static <T> int timesFound(T[] array, Predicate<T> filter) {
    return (int) Arrays.stream(array).filter(filter).count();
}

From source file:com.blackducksoftware.integration.hub.detect.detector.clang.CompileCommandsJsonFile.java

public static List<CompileCommand> parseJsonCompilationDatabaseFile(final Gson gson,
        final File compileCommandsJsonFile) throws IOException {
    final String compileCommandsJson = FileUtils.readFileToString(compileCommandsJsonFile,
            StandardCharsets.UTF_8);
    final CompileCommandJsonData[] compileCommands = gson.fromJson(compileCommandsJson,
            CompileCommandJsonData[].class);
    return Arrays.stream(compileCommands).map(rawCommand -> new CompileCommand(rawCommand))
            .collect(Collectors.toList());
}