List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:com.netflix.genie.core.jpa.specifications.JpaCommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param user The name of the user who created the command * @param statuses The status of the command * @param tags The set of tags to search the command for * @return A specification object used for querying */// w w w .ja v a 2s. co m public static Specification<CommandEntity> find(final String name, final String user, final Set<CommandStatus> statuses, final Set<String> tags) { return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(CommandEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates .add(cb.like(root.get(CommandEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.netflix.genie.core.jpa.specifications.JpaApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param user The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search the command for * @param type The type of applications to fine * @return A specification object used for querying *//* w w w . jav a2 s . com*/ public static Specification<ApplicationEntity> find(final String name, final String user, final Set<ApplicationStatus> statuses, final Set<String> tags, final String type) { return (final Root<ApplicationEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(ApplicationEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates.add( cb.like(root.get(ApplicationEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } if (StringUtils.isNotBlank(type)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.type), type)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaCommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param user The name of the user who created the command * @param statuses The status of the command * @param tags The set of tags to search the command for * @return A specification object used for querying *//*from w w w .j av a 2 s . c o m*/ public static Specification<CommandEntity> find(@Nullable final String name, @Nullable final String user, @Nullable final Set<CommandStatus> statuses, @Nullable final Set<TagEntity> tags) { return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { predicates.add( cb.or(statuses.stream().map(status -> cb.equal(root.get(CommandEntity_.status), status)) .toArray(Predicate[]::new))); } if (tags != null && !tags.isEmpty()) { final Join<CommandEntity, TagEntity> tagEntityJoin = root.join(CommandEntity_.tags); predicates.add(tagEntityJoin.in(tags)); cq.groupBy(root.get(CommandEntity_.id)); cq.having(cb.equal(cb.count(root.get(CommandEntity_.id)), tags.size())); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.ikanow.aleph2.management_db.mongodb.services.IkanowV1SyncService_LibraryJars.java
/** Want to end up with 3 lists: * - v1 objects that don't exist in v2 (Create them) * - v2 objects that don't exist in v1 (Delete them) * - matching v1/v2 objects with different modified times (Update them) * @param to_compare/*www.j a v a 2 s.c o m*/ * @returns a 3-tuple with "to create", "to delete", "to update" - NOTE: none of the _ids here include the "v1_" */ protected static Tuple3<Collection<String>, Collection<String>, Collection<String>> compareJarsToLibraryBeans_categorize( final Tuple2<Map<String, String>, Map<String, Date>> to_compare) { // Want to end up with 3 lists: // - v1 sources that don't exist in v2 (Create them) // - v2 sources that don't exist in v1 (Delete them) // - matching v1/v2 sources with different modified times (Update them) // (do delete first, then going to filter to_compare._1() on value==null) final Set<String> v2_not_v1 = new HashSet<String>(to_compare._2().keySet()); v2_not_v1.removeAll(to_compare._1().keySet()); // OK not worried about deletes any more, not interested in isApproved:false final Set<String> to_compare_approved = to_compare._1().entrySet().stream() .filter(kv -> null != kv.getValue() && !kv.getValue().isEmpty()).map(kv -> kv.getKey()) .collect(Collectors.toSet()); final Set<String> v1_and_v2 = new HashSet<String>(to_compare_approved); v1_and_v2.retainAll(to_compare._2().keySet()); final List<String> v1_and_v2_mod = v1_and_v2.stream().filter(id -> { try { final Date v1_date = parseJavaDate(to_compare._1().get(id)); final Date v2_date = to_compare._2().get(id); return v1_date.getTime() > v2_date.getTime(); } catch (Exception e) { return false; // (just ignore) } }).collect(Collectors.toList()); final Set<String> v1_not_v2 = new HashSet<String>(to_compare_approved); v1_not_v2.removeAll(to_compare._2().keySet()); return Tuples._3T(v1_not_v2, v2_not_v1, v1_and_v2_mod); }
From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param user The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search with * @param type The type of applications to fine * @return A specification object used for querying *///from w w w .j av a 2 s .c om public static Specification<ApplicationEntity> find(@Nullable final String name, @Nullable final String user, @Nullable final Set<ApplicationStatus> statuses, @Nullable final Set<TagEntity> tags, @Nullable final String type) { return (final Root<ApplicationEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { predicates.add( cb.or(statuses.stream().map(status -> cb.equal(root.get(ApplicationEntity_.status), status)) .toArray(Predicate[]::new))); } if (tags != null && !tags.isEmpty()) { final Join<ApplicationEntity, TagEntity> tagEntityJoin = root.join(ApplicationEntity_.tags); predicates.add(tagEntityJoin.in(tags)); cq.groupBy(root.get(ApplicationEntity_.id)); cq.having(cb.equal(cb.count(root.get(ApplicationEntity_.id)), tags.size())); } if (StringUtils.isNotBlank(type)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.type), type)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.act.reachables.LoadAct.java
private static void addToNw(Reaction rxn) { /**/*ww w .ja v a 2 s.co m*/ * This class takes in a reaction and adds it to ActData. * * Special handling is afforded to abstract reactions and reactions w/ only cofactors as substrates. */ Long rxnid = (long) rxn.getUUID(); // Filter out abstract substrates. These reactions are invalid Long[] inputChemicalsArray = ArrayUtils.addAll(rxn.getSubstrates(), rxn.getSubstrateCofactors()); // Some reactions have coenzymes, so don't forget about those. inputChemicalsArray = ArrayUtils.addAll(inputChemicalsArray, rxn.getCoenzymes()); if (Arrays.stream(inputChemicalsArray).anyMatch(x -> ActData.instance().metaCycBigMolsOrRgrp.contains(x))) { logProgress(String.format("Skipping reaction %d as it contains an abstract substrate.", rxnid)); return; } // Remove cofactors from the needed substrates. List<Long> inputChemicals = Arrays.asList(inputChemicalsArray).stream() .filter(c -> !ActData.instance().cofactors.contains(c)).collect(Collectors.toList()); Long[] outputChemicalsArray = ArrayUtils.addAll(rxn.getProducts(), rxn.getProductCofactors()); // Output chemicals, only real ones. Also remove all of the cofactors as we don't care if those are produced. List<Long> outputChemicals = Arrays.asList(outputChemicalsArray).stream() .filter(p -> !ActData.instance().metaCycBigMolsOrRgrp.contains(p) && !ActData.instance().cofactors.contains(p)) .collect(Collectors.toList()); // Don't bother if we don't get any new chemicals from this. if (outputChemicals.isEmpty()) { logProgress(String.format("Skipping reaction %d as it has no non-abstract products.", rxnid)); return; } if (inputChemicals.isEmpty()) { logProgress(String.format( "Undoing filtering on reaction %d substrates as it has only cofactor substrates.", rxnid)); // These will be substrate only inputChemicals = Arrays.asList(inputChemicalsArray); } // Load all the nodeMapping. inputChemicals.stream().distinct().forEach(s -> { Node sub = Node.get(s, true); ActData.instance().chemsInAct.put(s, sub); ActData.instance().Act.addNode(sub, s); outputChemicals.stream().distinct().forEach(p -> { Node prd = Node.get(p, true); ActData.instance().Act.addNode(prd, p); ActData.instance().chemsInAct.put(p, prd); Edge r = Edge.get(sub, prd, true); ActData.instance().Act.addEdge(r); }); }); Set<Long> inputSet = new HashSet<>(inputChemicals); Set<Long> outputSet = new HashSet<>(outputChemicals); /* --------------- Update ActData ------------------ */ ActData.instance().rxnSubstrates.put(rxnid, inputSet); ActData.instance().rxnProducts.put(rxnid, outputSet); inputSet.stream().forEach(ActData.instance().chemsReferencedInRxns::add); outputSet.stream().forEach(ActData.instance().chemsReferencedInRxns::add); inputSet.stream().forEach(s -> { Set<Long> pSet = ActData.instance().rxnsThatConsumeChem.getOrDefault(s, new HashSet<>()); pSet.add(rxnid); ActData.instance().rxnsThatConsumeChem.put(s, pSet); }); outputSet.stream().forEach(p -> { Set<Long> pSet = ActData.instance().rxnsThatProduceChem.getOrDefault(p, new HashSet<>()); pSet.add(rxnid); ActData.instance().rxnsThatProduceChem.put(p, pSet); }); // add to internal copy of network ActData.instance().rxnHasSeq.put(rxnid, rxn.hasProteinSeq()); /* -------- Reaction Classes ------- */ Pair<Set<Long>, Set<Long>> rxnClass = Pair.of(inputSet, outputSet); if (!ActData.instance().rxnClasses.contains(rxnClass)) { // the first reaction that shows up in this class, get to // represent the entire class. So we install it in the // datasets mirroring the non-class structures... ActData.instance().rxnClassesSubstrates.put(rxnid, inputSet); ActData.instance().rxnClassesProducts.put(rxnid, outputSet); ActData.instance().rxnClasses.add(rxnClass); } }
From source file:io.github.vdubois.codechecker.check.CheckService.java
/** * Pass all checks//from w ww . j av a2 s .c o m * @param checks checks to pass */ public void checkAll(Set<Check> checks) { checks.stream().forEach(this::checkUnitary); }
From source file:nu.yona.server.subscriptions.service.migration.AddFirstDevice.java
private void addDevicesAnonymizedToUserAnonymizedIfNotDoneYet(User user) { UserAnonymized userAnonymized = user.getAnonymized(); Set<UserDevice> devices = user.getDevices(); devices.stream().map(UserDevice::getDeviceAnonymized) .forEach(d -> addDeviceAnonymizedToUserAnonymizedIfNotDoneYet(userAnonymized, d)); }
From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java
/** * Finds all a processes children, kills the process then recursively calls this on the children. * /*from ww w . j a v a2 s . c om*/ * @param pid * @param kill_signal * @return * @throws IOException */ private static boolean killProcessAndChildren(final String pid, final Optional<Integer> kill_signal) throws IOException { //first find any children via pgrep -P pid final ProcessBuilder pb_children = new ProcessBuilder("pgrep", "-P", pid.toString()); final BufferedReader br = new BufferedReader(new InputStreamReader(pb_children.start().getInputStream())); final Set<String> child_pids = new HashSet<String>(); String line; while ((line = br.readLine()) != null) { child_pids.add(line); } logger.debug("children of pid: " + pid + " are: " + child_pids.toString()); //kill pid w/ signal killProcess(pid, kill_signal); //if still alive kill with -9, give it 5s to try and die the old way for (int i = 0; i < 5; i++) { try { Thread.sleep(1000L); } catch (Exception e) { } if (!isProcessRunning(pid)) { break; } } if (isProcessRunning(pid)) { killProcess(pid, Optional.of(9)); } //call this on all children return !child_pids.stream().filter(child_pid -> { try { return killProcessAndChildren(child_pid, kill_signal); } catch (Exception ex) { return false; } }).anyMatch(result -> false); }
From source file:io.curly.tagger.service.DefaultTagService.java
/** * Save and if there is already a tag with the name, suppress it! * * @param tags to be saved//from www . j av a 2s .c o m */ @Override public void save(Set<Tag> tags) { tags.stream().forEach(tag -> { try { this.repository.save(tag); } catch (DuplicateKeyException e) { //just log and ignore log.debug("Received duplicated key", e); } }); }