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:io.ingenieux.lambada.maven.LambadaGenerateMojo.java

private JsonNode compilePatches(Patch[] patches) throws IOException {
    if (null != patches && 0 == patches.length)
        return null;

    ArrayNode result = OBJECT_MAPPER.createArrayNode();

    result.addAll(Arrays.stream(patches).map(p -> Unthrow.wrap(patch -> {
        ObjectNode resultNode = OBJECT_MAPPER.createObjectNode();

        resultNode.put("op", patch.patchType().name().toLowerCase());

        resultNode.put("path", patch.path());

        if (isNotBlank(patch.patchValue())) {
            final String sourceValue = patch.patchValue();

            if (-1 != "{[\"".indexOf(sourceValue.charAt(0))) {
                resultNode.set("value", resultNode.textNode(sourceValue));
            } else {
                resultNode.put("value", sourceValue);
            }//from  www.  j a  v a2  s  .c  o m
        } else if (isNotBlank(patch.from())) {
            final String sourceValue = patch.from();

            if (-1 != "{[\"".indexOf(sourceValue.charAt(0))) {
                resultNode.set("from", resultNode.textNode(sourceValue));
            } else {
                resultNode.put("from", sourceValue);
            }
        } else {
            throw new IllegalStateException("Missing (from|value) on annotation @Patch");
        }

        return resultNode;
    }, p)).collect(Collectors.toList()));

    return result;
}

From source file:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java

/**
 * Imports the annotations of all brat-annotated documents located in the provided folder.  
 * // ww  w.  j av a 2 s .  com
 * @param inputFolder the path to the brat corpus folder to import 
 * @throws IOException if an Exception occurs accessing the folder
 */
public void importDataset(String inputFolder) throws IOException {
    Assert.hasText(inputFolder, "inputFolder parameter cannot be empty [importDataset(" + inputFolder + ")]");
    File dir = new File(inputFolder);
    Assert.isTrue(dir.isDirectory(),
            "Provided parameter has to be a path to a folder. [importDataset(" + inputFolder + ")]");

    // retrieve all files that end with ann, strip off the extension and save the file name without extension in a list
    List<String> baseFileNames = Arrays.stream(dir.listFiles((d, name) -> name.endsWith(".ann")))
            .map(f -> f.getName().substring(0, f.getName().length() - 4)).collect(Collectors.toList());
    for (String baseFileName : baseFileNames) {
        importThread(inputFolder, baseFileName);
    }
}

From source file:au.gov.dto.springframework.security.web.context.CookieSecurityContextRepository.java

private Cookie getAuthenticationCookie(HttpServletRequest request) {
    if (request.getCookies() == null) {
        return null;
    }//w  w w.j a v  a  2s. co  m
    Optional<Cookie> maybeCookie = Arrays.stream(request.getCookies())
            .filter(cookie -> cookie.getName().equals(authenticationCookieName)).findFirst();
    return maybeCookie.isPresent() ? maybeCookie.get() : null;
}

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

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

From source file:com.epam.dlab.backendapi.dao.BillingDAO.java

private boolean isShapeAcceptable(List<String> shapeNames, String... shapes) {
    return shapeNames == null || shapeNames.isEmpty() || Arrays.stream(shapes).anyMatch(shapeNames::contains);
}

From source file:com.netflix.spinnaker.halyard.backup.services.v1.BackupService.java

private void tarHalconfig(String halconfigDir, String halconfigTar) throws IOException {
    FileOutputStream tarOutput = null;
    BufferedOutputStream bufferedTarOutput = null;
    TarArchiveOutputStream tarArchiveOutputStream = null;
    IOException fatalCleanup = null;
    try {//ww w.  j a v  a 2s  . c  om
        tarOutput = new FileOutputStream(new File(halconfigTar));
        bufferedTarOutput = new BufferedOutputStream(tarOutput);
        tarArchiveOutputStream = new TarArchiveOutputStream(bufferedTarOutput);
        TarArchiveOutputStream finalTarArchiveOutputStream = tarArchiveOutputStream;
        Arrays.stream(new File(halconfigDir).listFiles()).filter(Objects::nonNull)
                .forEach(f -> addFileToTar(finalTarArchiveOutputStream, f.getAbsolutePath(), ""));
    } catch (HalException e) {
        log.info("HalException caught during tar operation", e);
        throw e;
    } catch (IOException e) {
        log.info("IOException caught during tar operation", e);
        throw new HalException(Problem.Severity.FATAL, "Failed to backup halconfig: " + e.getMessage(), e);
    } finally {
        if (tarArchiveOutputStream != null) {
            try {
                tarArchiveOutputStream.finish();
                tarArchiveOutputStream.close();
            } catch (IOException e) {
                fatalCleanup = e;
            }
        }

        if (bufferedTarOutput != null) {
            bufferedTarOutput.close();
        }

        if (tarOutput != null) {
            tarOutput.close();
        }
    }

    if (fatalCleanup != null) {
        throw fatalCleanup;
    }
}

From source file:com.globocom.grou.report.ReportService.java

private void notifyByHttp(Test test, String url) throws IOException {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new StringEntity(mapper.writeValueAsString(test.getResult())));
        Arrays.stream(HEADERS).forEach(httpPost::setHeader);
        CloseableHttpResponse response = httpClient.execute(httpPost);
        LOGGER.info("Test " + test.getProject() + "." + test.getName() + ": sent notification to " + url
                + " [response status=" + response.getStatusLine().getStatusCode() + "]");
    }// w  w w. ja v  a2 s. co m
}

From source file:de.se_rwth.langeditor.util.Misc.java

public static boolean removeFromClasspath(IJavaProject javaProject, Predicate<IClasspathEntry> predicate) {
    try {//from   ww w  . j  a v a  2  s .c  o m
        IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> filteredClasspath = Arrays.stream(oldClasspath).filter(predicate.negate())
                .collect(Collectors.toList());
        IClasspathEntry[] newClasspath = filteredClasspath
                .toArray(new IClasspathEntry[filteredClasspath.size()]);
        javaProject.setRawClasspath(newClasspath, null);
        return oldClasspath.length > newClasspath.length;
    } catch (JavaModelException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java

static void removeCredentialCookies(final HttpServletRequest request,
        final HttpServletResponse response) {
    Arrays.stream(request.getCookies())
            .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)).forEach(c -> {
                final Cookie removal = new Cookie(c.getName(), "");
                removal.setPath("/");
                removal.setMaxAge(0);//from w w w. jav  a  2  s.  c om
                removal.setHttpOnly(true);
                removal.setSecure(true);

                response.addCookie(removal);
            });
}

From source file:com.grayfox.server.dao.foursquare.PoiFoursquareDao.java

protected List<Poi> fetchNearestByCategory(FoursquareApi foursquareApi, Location location, Integer radius,
        String categoryFoursquareId) {
    Result<Venue[]> venuesResult = foursquareApi.searchVenues(location.stringValues(), null, null, null, null,
            null, null, null, radius, null, null, categoryFoursquareId, null, null, null);
    if (venuesResult.getMeta().getCode() == 200) {
        List<Poi> pois = new ArrayList<>(venuesResult.getResponse().length);
        Arrays.stream(venuesResult.getResponse()).forEach(venue -> pois.add(toPoi(venue)));
        return pois;
    } else {//from  w w  w  . j a v  a2 s  .c o  m
        LOGGER.error(
                "Foursquare error while requesting [venues/search] [code={}, errorType={}, errorDetail={}]",
                venuesResult.getMeta().getCode(), venuesResult.getMeta().getErrorType(),
                venuesResult.getMeta().getErrorDetail());
        throw new DaoException.Builder().messageKey("foursquare.request.error")
                .addMessageArgument(venuesResult.getMeta().getErrorDetail()).build();
    }
}