List of usage examples for java.lang Iterable spliterator
default Spliterator<T> spliterator()
From source file:com.epam.ta.reportportal.core.project.impl.UpdateProjectHandler.java
/** * Validate candidates for unassign from projects, and update default * project if it required//from w w w . j a va2 s.c o m * * @param users * @param projectName */ private void processCandidateForUnaassign(Iterable<User> users, String projectName) { List<User> updated = StreamSupport.stream(users.spliterator(), false) .filter(it -> it.getDefaultProject().equals(projectName)).map(it -> { it.setDefaultProject(personalProjectName(it.getId())); return it; }).collect(toList()); userRepository.save(updated); }
From source file:com.joyent.manta.client.multipart.EncryptedMultipartManager.java
@Override public void complete(final EncryptedMultipartUpload<WRAPPED_UPLOAD> upload, final Iterable<? extends MantaMultipartUploadTuple> parts) throws IOException { try (Stream<? extends MantaMultipartUploadTuple> stream = StreamSupport.stream(parts.spliterator(), false)) {/*w ww . j av a 2 s .c om*/ complete(upload, stream); } }
From source file:net.staticsnow.nexus.repository.apt.internal.hosted.AptHostedFacet.java
private List<Asset> selectOldPackagesToRemove(String packageName, String arch) throws IOException, PGPException { if (config.assetHistoryLimit == null) { return Collections.emptyList(); }/* www. j av a2 s . c o m*/ int count = config.assetHistoryLimit; StorageTx tx = UnitOfWork.currentTx(); Map<String, Object> sqlParams = new HashMap<>(); sqlParams.put(P_PACKAGE_NAME, packageName); sqlParams.put(P_ARCHITECTURE, arch); sqlParams.put(P_ASSET_KIND, "DEB"); Iterable<Asset> assets = tx.findAssets(ASSETS_BY_PACKAGE_AND_ARCH, sqlParams, Collections.singleton(getRepository()), ""); List<Asset> removals = new ArrayList<>(); Map<String, List<Asset>> assetsByArch = StreamSupport.stream(assets.spliterator(), false) .collect(Collectors.groupingBy(a -> a.formatAttributes().get(P_ARCHITECTURE, String.class))); for (Map.Entry<String, List<Asset>> entry : assetsByArch.entrySet()) { if (entry.getValue().size() <= count) { continue; } int trimCount = entry.getValue().size() - count; Set<String> keepVersions = entry.getValue().stream() .map(a -> new Version(a.formatAttributes().get(P_PACKAGE_VERSION, String.class))).sorted() .skip(trimCount).map(v -> v.toString()).collect(Collectors.toSet()); entry.getValue().stream() .filter(a -> !keepVersions.contains(a.formatAttributes().get(P_PACKAGE_VERSION, String.class))) .forEach((item) -> removals.add(item)); } return removals; }
From source file:com.yahoo.elide.graphql.GraphQLEndpoint.java
/** * Create handler./*from w w w.j a v a 2s. co m*/ * * @param securityContext security context * @param graphQLDocument post data as jsonapi document * @return response */ @POST @Consumes(MediaType.APPLICATION_JSON) public Response post(@Context SecurityContext securityContext, String graphQLDocument) { ObjectMapper mapper = elide.getMapper().getObjectMapper(); JsonNode topLevel; try { topLevel = mapper.readTree(graphQLDocument); } catch (IOException e) { log.debug("Invalid json body provided to GraphQL", e); // NOTE: Can't get at isVerbose setting here for hardcoding to false. If necessary, we can refactor // so this can be set appropriately. return buildErrorResponse(new InvalidEntityBodyException(graphQLDocument), false); } Function<JsonNode, Response> executeRequest = (node) -> executeGraphQLRequest(mapper, securityContext, graphQLDocument, node); if (topLevel.isArray()) { Iterator<JsonNode> nodeIterator = topLevel.iterator(); Iterable<JsonNode> nodeIterable = () -> nodeIterator; // NOTE: Create a non-parallel stream // It's unclear whether or not the expectations of the caller would be that requests are intended // to run serially even outside of a single transaction. We should revisit this. Stream<JsonNode> nodeStream = StreamSupport.stream(nodeIterable.spliterator(), false); ArrayNode result = nodeStream.map(executeRequest).map(response -> { try { return mapper.readTree((String) response.getEntity()); } catch (IOException e) { log.debug("Caught an IO exception while trying to read response body"); return JsonNodeFactory.instance.objectNode(); } }).reduce(JsonNodeFactory.instance.arrayNode(), (arrayNode, node) -> arrayNode.add(node), (left, right) -> left.addAll(right)); try { return Response.ok(mapper.writeValueAsString(result)).build(); } catch (IOException e) { log.error("An unexpected error occurred trying to serialize array response.", e); return Response.serverError().build(); } } return executeRequest.apply(topLevel); }
From source file:org.bozzo.ipplan.domain.model.ui.SubnetResource.java
/** * @param id/*from ww w. ja v a 2 s . c o m*/ * @param infraId * @param ip * @param size * @param description * @param group * @param lastModifed * @param userId * @param optionId * @param swipMod */ @JsonCreator public SubnetResource(@JsonProperty("id") Long id, @JsonProperty Integer infraId, @JsonProperty Long ip, @JsonProperty Integer netmask, @JsonProperty Long size, @JsonProperty String description, @JsonProperty String group, @JsonProperty Date lastModifed, @JsonProperty String userId, @JsonProperty Long optionId, @JsonProperty Date swipMod, @JsonProperty Iterable<Address> addresses) { this.id = id; this.infraId = infraId; this.ip = ip; this.size = size; this.netmask = netmask; this.description = description; this.group = group; this.lastModifed = lastModifed; this.userId = userId; this.optionId = optionId; this.swipMod = swipMod; if (addresses != null) { this.setAddresses( StreamSupport.stream(addresses.spliterator(), true).map(new ToAddressResourceFunction())); } }
From source file:com.github.larsq.spring.embeddedamqp.SimpleAmqpMessageContainer.java
/** * Find set of abstract exchange routers by traversing a comprising class. * This method is invoked to discover available router types. * * @return//from ww w . j a va 2 s . c om */ Set<AbstractExchangeRouter> findRouters() { ClassStructureWalker walker = new ClassStructureWalker(Routers.class, false, true); Iterable<Class<?>> innerClasses = walker .traverseClassStructure(clz -> Sets.newHashSet(clz.getDeclaredClasses())); return StreamSupport.stream(innerClasses.spliterator(), false) .filter(AbstractExchangeRouter.class::isAssignableFrom) .filter(clz -> !Modifier.isAbstract(clz.getModifiers())) .map(clz -> (AbstractExchangeRouter) invokeInnerClassConstructor(clz)).collect(Collectors.toSet()); }
From source file:com.thinkbiganalytics.metadata.modeshape.user.JcrUserGroup.java
private <C, J> Iterable<C> iterateReferances(String nodeType, Class<C> modelClass, Class<J> jcrClass) { return () -> { @SuppressWarnings("unchecked") Iterable<Property> propItr = () -> { try { return (Iterator<Property>) this.node.getWeakReferences(); } catch (Exception e) { throw new MetadataRepositoryException( "Failed to retrieve the users in the group node: " + this.node, e); }/*ww w . ja v a 2 s. c om*/ }; return StreamSupport.stream(propItr.spliterator(), false).map(p -> JcrPropertyUtil.getParent(p)) .filter(n -> JcrUtil.isNodeType(n, nodeType)).map(n -> { try { @SuppressWarnings("unchecked") C entity = (C) ConstructorUtils.invokeConstructor(jcrClass, n); return entity; } catch (Exception e) { throw new MetadataRepositoryException("Failed to retrieve create entity: " + jcrClass, e); } }).iterator(); }; }
From source file:fr.landel.utils.assertor.utils.AssertorIterable.java
private static <I extends Iterable<T>, T> boolean has(final I iterable1, final Iterable<T> iterable2, final boolean all, final boolean not, final EnumAnalysisMode analysisMode) { final int size2 = IterableUtils.size(iterable2); if (all && !not && size2 > IterableUtils.size(iterable1)) { return false; }//from w w w . j a v a 2s .c o m if (EnumAnalysisMode.STANDARD.equals(analysisMode)) { if (all && !not) { for (final T objectRef : iterable2) { if (!AssertorIterable.has(iterable1, objectRef, analysisMode)) { return false; } } return true; } else if (!all) { // any and not any for (final T objectRef : iterable2) { if (AssertorIterable.has(iterable1, objectRef, analysisMode)) { return !not; } } return not; } else { // not all long found = 0; for (final T objectRef : iterable2) { if (AssertorIterable.has(iterable1, objectRef, analysisMode)) { ++found; } } return HelperAssertor.isValid(all, not, found, size2); } } else { return HelperAssertor.isValid( StreamSupport.stream(iterable2.spliterator(), EnumAnalysisMode.PARALLEL.equals(analysisMode)), o -> AssertorIterable.has(iterable1, o, analysisMode), all, not, () -> size2); } }
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManager.java
/** * Completes a multipart transfer by assembling the parts on Manta. * This is a synchronous operation.//from w ww . j a va 2 s. com * * @param upload multipart upload object * @param parts iterable of multipart part objects * @throws IOException thrown if there is a problem connecting to Manta */ @Override public void complete(final ServerSideMultipartUpload upload, final Iterable<? extends MantaMultipartUploadTuple> parts) throws IOException { Validate.notNull(upload, "Upload state object must not be null"); final Stream<? extends MantaMultipartUploadTuple> partsStream = StreamSupport.stream(parts.spliterator(), false); complete(upload, partsStream); }
From source file:com.joyent.manta.client.multipart.JobsMultipartManager.java
@Override public void complete(final JobsMultipartUpload upload, final Iterable<? extends MantaMultipartUploadTuple> parts) throws IOException { Validate.notNull(upload, "Multipart upload object must not be null"); try (Stream<? extends MantaMultipartUploadTuple> stream = StreamSupport.stream(parts.spliterator(), false)) {//from w ww . j av a2s .co m complete(upload, stream); } }