List of usage examples for java.util.stream StreamSupport stream
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel)
From source file:com.epam.ta.reportportal.core.filter.impl.UpdateUserFilterHandler.java
@Override public List<OperationCompletionRS> updateUserFilter(CollectionsRQ<BulkUpdateFilterRQ> updateFilterRQs, String userName, String projectName) { Set<String> idsToLoad = updateFilterRQs.getElements().stream().map(BulkUpdateFilterRQ::getId) .collect(toSet());/*from w w w .j a v a 2 s . c o m*/ expect(idsToLoad.size(), equalTo(updateFilterRQs.getElements().size())).verify(BAD_REQUEST_ERROR); UserFilter[] userFilters = StreamSupport .stream(userFilterRepository.findAll(idsToLoad).spliterator(), false).toArray(UserFilter[]::new); expect(idsToLoad.size(), equalTo(userFilters.length)).verify(USER_FILTER_NOT_FOUND); final List<UserFilter> filterFromOtherProjects = Stream.of(userFilters) .filter(userFilter -> !userFilter.getProjectName().equalsIgnoreCase(projectName)).collect(toList()); expect(filterFromOtherProjects.size(), equalTo(0)).verify(ACCESS_DENIED); final Map<String, ProjectRole> projectRoles = projectRepository.findProjectRoles(userName); List<OperationCompletionRS> result = new ArrayList<>(idsToLoad.size()); synchronized (this) { List<UserFilter> updatedFilters = new ArrayList<>(idsToLoad.size()); for (int i = 0; i < updateFilterRQs.getElements().size(); i++) { AclUtils.isAllowedToEdit(userFilters[i].getAcl(), userName, projectRoles, userFilters[i].getName()); String name = updateFilterRQs.getElements().get(i).getName(); if (null != name && !name.equals(userFilters[i].getName())) { userFilterService.isFilterNameUnique(userName, updateFilterRQs.getElements().get(i).getName(), projectName); } updateUserFilter(userFilters[i], updateFilterRQs.getElements().get(i), userName, projectName); updatedFilters.add(userFilters[i]); result.add(buildResponse(userFilters[i])); } userFilterRepository.save(updatedFilters); } return result; }
From source file:com.adobe.acs.commons.data.Spreadsheet.java
/** * Parse out the input file synchronously for easier unit test validation * * @return List of files that will be imported, including any renditions * @throws IOException if the file couldn't be read */// w ww . ja v a2 s . co m private void parseInputFile(InputStream file) throws IOException { XSSFWorkbook workbook = new XSSFWorkbook(file); final XSSFSheet sheet = workbook.getSheetAt(0); rowCount = sheet.getLastRowNum(); final Iterator<Row> rows = sheet.rowIterator(); Row firstRow = rows.next(); headerRow = readRow(firstRow).stream().map(Variant::toString).map(this::convertHeaderName) .collect(Collectors.toList()); headerTypes = readRow(firstRow).stream().map(Variant::toString) .collect(Collectors.toMap(this::convertHeaderName, this::detectTypeFromName, this::upgradeToArray)); Iterable<Row> remainingRows = () -> rows; dataRows = StreamSupport.stream(remainingRows.spliterator(), false).map(this::buildRow) .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); }
From source file:ch.heigvd.gamification.api.ApplicationsEndpoint.java
@Override @RequestMapping(method = RequestMethod.GET) public ResponseEntity<List<ApplicationDTO>> applicationsGet() { UriComponents uriComponents = MvcUriComponentsBuilder.fromMethodName(BadgesEndpoint.class, "badgesGet", 1) .build();//from w ww . java 2s . co m return new ResponseEntity<>(StreamSupport.stream(apprepository.findAll().spliterator(), true) .map(p -> toDTO(p, uriComponents)).collect(toList()), HttpStatus.OK); }
From source file:com.simiacryptus.mindseye.test.data.MNIST.java
private static <T> Stream<T> toIterator(@Nonnull final Iterator<T> iterator) { return StreamSupport.stream(Spliterators.spliterator(iterator, 1, Spliterator.ORDERED), false); }
From source file:com._4dconcept.springframework.data.marklogic.repository.support.SimpleMarklogicRepository.java
@Override public List<T> findAllById(Iterable<ID> ids) { return StreamSupport.stream(ids.spliterator(), false).map(this::findById).filter(Optional::isPresent) .map(Optional::get).collect(Collectors.toList()); }
From source file:ddf.catalog.util.impl.ResultIterable.java
private static Stream<Result> stream(Iterator<Result> iterator) { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); }
From source file:fi.hsl.parkandride.dev.DevController.java
@RequestMapping(method = PUT, value = DEV_UTILIZATION) @TransactionalWrite/* w ww . j a v a2 s . c om*/ public ResponseEntity<Void> generateUtilizationData(@NotNull @PathVariable(FACILITY_ID) Long facilityId) { final Facility facility = facilityRepository.getFacility(facilityId); // Generate dummy usage for the last month final Random random = new Random(); final List<Utilization> utilizations = StreamSupport .stream(spliteratorUnknownSize( new DateTimeIterator(DateTime.now().minusMonths(1), DateTime.now(), Minutes.minutes(5)), Spliterator.ORDERED), false) .flatMap(ts -> facility.builtCapacity.keySet().stream().flatMap(capacityType -> { if (facility.pricingMethod == PricingMethod.PARK_AND_RIDE_247_FREE) { return Stream.of(new UtilizationKey(facilityId, capacityType, Usage.PARK_AND_RIDE)); } else { return facility.pricing.stream().filter(pr -> pr.capacityType == capacityType) .map(pr -> new UtilizationKey(facilityId, capacityType, pr.usage)); } }).map(utilizationKey -> newUtilization(utilizationKey, facility.builtCapacity.get(utilizationKey.capacityType), ts.minusSeconds(random.nextInt(180)) // Randomness to prevent timestamps for different capacity types being equal ))).collect(toList()); utilizationRepository.insertUtilizations(utilizations); predictionService.signalUpdateNeeded(utilizations); return new ResponseEntity<>(CREATED); }
From source file:com.crossover.trial.weather.domain.DomainRepositoryTest.java
@Test @DatabaseSetup("classpath:dbtest/airport_small.xml") public void testFindAllIataCodes() { List<IATA> iataCodes = StreamSupport.stream(airportRepository.findAllIATACodes().spliterator(), false) .collect(Collectors.toList()); assertThat(iataCodes, equalTo(asList("BOS", "EWR", "JFK", "LGA", "MMU").stream().map(IATA::valueOf) .collect(Collectors.toList()))); }
From source file:com.yoshio3.services.StorageService.java
public List<BlobStorageEntity> getAllFiles() { List<BlobStorageEntity> entity = new ArrayList<>(); try {//from w w w. ja v a 2s . com CloudBlobContainer container = blobClient.getContainerReference(CONTAINER_NAME_FOR_UPLOAD); Iterable<ListBlobItem> items = container.listBlobs(); Spliterator<ListBlobItem> spliterator = items.spliterator(); Stream<ListBlobItem> stream = StreamSupport.stream(spliterator, false); List<CloudBlob> blockBlob = stream.filter(item -> item instanceof CloudBlob) .map(item -> (CloudBlob) item).collect(Collectors.toList()); entity = blockBlob.stream().map(blob -> convertEntity(blob)).collect(Collectors.toList()); } catch (URISyntaxException | StorageException ex) { LOGGER.log(Level.SEVERE, "", ex); } return entity; }
From source file:com.netflix.spinnaker.orca.clouddriver.tasks.manifest.PatchManifestTask.java
private Object parsedManifestArtifact(@Nonnull Stage stage, Map task) { Artifact manifestArtifact = artifactResolver.getBoundArtifactForId(stage, task.get("manifestArtifactId").toString()); if (manifestArtifact == null) { throw new IllegalArgumentException( "No artifact could be bound to '" + task.get("manifestArtifactId") + "'"); }//from w w w .j ava 2 s . c o m log.info("Using {} as the manifest to be patched", manifestArtifact); manifestArtifact.setArtifactAccount((String) task.get("manifestArtifactAccount")); return retrySupport.retry(() -> { try { Response manifestText = oort.fetchArtifact(manifestArtifact); Iterable<Object> rawManifests = yamlParser.get().loadAll(manifestText.getBody().in()); List<Map> manifests = StreamSupport.stream(rawManifests.spliterator(), false).map(m -> { try { return Collections.singletonList(objectMapper.convertValue(m, Map.class)); } catch (Exception e) { return (List<Map>) objectMapper.convertValue(m, List.class); } }).flatMap(Collection::stream).collect(Collectors.toList()); Map<String, Object> manifestWrapper = new HashMap<>(); manifestWrapper.put("manifests", manifests); manifestWrapper = contextParameterProcessor.process(manifestWrapper, contextParameterProcessor.buildExecutionContext(stage, true), true); if (manifestWrapper.containsKey("expressionEvaluationSummary")) { throw new IllegalStateException("Failure evaluating manifest expressions: " + manifestWrapper.get("expressionEvaluationSummary")); } List<Map> manifestsAsList = (List<Map>) manifestWrapper.get("manifests"); return manifestsAsList.get(0); } catch (Exception e) { log.warn("Failure fetching/parsing manifests from {}", manifestArtifact, e); // forces a retry throw new IllegalStateException(e); } }, 10, 200, true); }