List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:com.opengamma.financial.view.HistoricalViewEvaluationTarget.java
private static Set<Currency> getCurrencyCalendars(FudgeDeserializer deserializer, FudgeMsg message) { Set<Currency> currencies = new HashSet<Currency>(); for (FudgeField ccyField : message.getAllByName(CURRENCY_CALENDAR_FIELD)) { Currency ccy = deserializer.fieldValueToObject(Currency.class, ccyField); currencies.add(ccy);//w w w . j a v a2 s.c om } return !currencies.isEmpty() ? currencies : null; }
From source file:me.vertretungsplan.objects.SubstitutionSchedule.java
/** * Filter a set of substitutions by excluding a set of subjects * * @param excludedSubjects a set of subjects to exclude * @param substitutions a set of {@link Substitution}s * @return the substitutions from the set that are not for one of the specified subjects *//*from w w w. jav a 2s. c om*/ public static Set<Substitution> filterBySubject(Set<String> excludedSubjects, Set<Substitution> substitutions) { if (excludedSubjects == null || excludedSubjects.isEmpty()) return substitutions; Set<Substitution> filteredSubstitutions = new HashSet<>(); for (Substitution substitution : substitutions) { if (substitution.getPreviousSubject() != null) { if (!excludedSubjects.contains(substitution.getPreviousSubject())) { filteredSubstitutions.add(substitution); } } else if (substitution.getSubject() != null) { if (!excludedSubjects.contains(substitution.getSubject())) { filteredSubstitutions.add(substitution); } } else { filteredSubstitutions.add(substitution); } } return filteredSubstitutions; }
From source file:com.netflix.genie.core.jpa.specifications.JpaClusterSpecs.java
/** * Get all the clusters given the specified parameters. * * @param commandId The id of the command that is registered with this cluster * @param statuses The status of the cluster * @return The specification//from w w w . ja v a 2 s .c o m */ public static Specification<ClusterEntity> findClustersForCommand(final String commandId, final Set<ClusterStatus> statuses) { return (final Root<ClusterEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); final Join<ClusterEntity, CommandEntity> commands = root.join(ClusterEntity_.commands); predicates.add(cb.equal(commands.get(CommandEntity_.id), commandId)); if (statuses != null && !statuses.isEmpty()) { //Could optimize this as we know size could use native array final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(ClusterEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:hoot.services.models.osm.Way.java
/** * Returns all node records for the specified ways from the services * database// w w w . j av a 2s . com * * @param mapId * ID of the map owning the ways * @param wayIds * a collection of way IDs for which to retrieve node records * @param dbConn * JDBC Connection * @return a list of node records */ static List<CurrentNodes> getNodesForWays(long mapId, Set<Long> wayIds, Connection dbConn) { if (!wayIds.isEmpty()) { return new SQLQuery<>(dbConn, DbUtils.getConfiguration(mapId)).select(currentNodes) .from(currentWayNodes, currentNodes).join(currentNodes) .on(currentWayNodes.nodeId.eq(currentNodes.id)).where(currentWayNodes.wayId.in(wayIds)).fetch(); } return new ArrayList<>(); }
From source file:musite.ProteinsUtil.java
/** * //from w ww .j a va 2 s . c o m * @param proteins * @param ptm * @param enzymes * @param aminoAcids * @return */ public static int countProteins(Proteins proteins, PTM ptm, Set<String> enzymes, Set<AminoAcid> aminoAcids) { if (proteins == null) throw new IllegalArgumentException(); if (ptm == null) return proteins.proteinCount(); int count = 0; Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Set<Integer> sites = PTMAnnotationUtil.getSites(it.next(), ptm, aminoAcids, enzymes); if (sites != null && !sites.isEmpty()) { count++; } } return count; }
From source file:edu.wpi.checksims.algorithm.similaritymatrix.SimilarityMatrix.java
/** * Generate a similarity matrix from a given set of submissions. * * @param inputSubmissions Submissions to generate from * @param results Results to build from. Must contain results for every possible unordered pair of input submissions * @return Similarity Matrix built from given results * @throws InternalAlgorithmError Thrown on missing results, or results containing a submission not in the input *///ww w . j a v a 2 s.com public static SimilarityMatrix generateMatrix(Set<Submission> inputSubmissions, Set<AlgorithmResults> results) throws InternalAlgorithmError { checkNotNull(inputSubmissions); checkNotNull(results); checkArgument(!inputSubmissions.isEmpty(), "Must provide at least 1 submission to build matrix from"); checkArgument(!results.isEmpty(), "Must provide at least 1 AlgorithmResults to build matrix from!"); // Generate the matrix we'll use MatrixEntry[][] matrix = new MatrixEntry[inputSubmissions.size()][inputSubmissions.size()]; // Order the submissions List<Submission> orderedSubmissions = Ordering.natural().immutableSortedCopy(inputSubmissions); // Generate the matrix // Start with the diagonal, filling with 100% similarity for (int i = 0; i < orderedSubmissions.size(); i++) { Submission s = orderedSubmissions.get(i); matrix[i][i] = new MatrixEntry(s, s, s.getNumTokens()); } // Now go through all the results, and build appropriate two MatrixEntry objects for each for (AlgorithmResults result : results) { int aIndex = orderedSubmissions.indexOf(result.a); int bIndex = orderedSubmissions.indexOf(result.b); if (aIndex == -1) { throw new InternalAlgorithmError( "Processed Algorithm Result with submission not in given input submissions with name \"" + result.a.getName() + "\""); } else if (bIndex == -1) { throw new InternalAlgorithmError( "Processed Algorithm Result with submission not in given input submissions with name \"" + result.b.getName() + "\""); } matrix[aIndex][bIndex] = new MatrixEntry(result.a, result.b, result.identicalTokensA); matrix[bIndex][aIndex] = new MatrixEntry(result.b, result.a, result.identicalTokensB); } // Verification pass: Go through and ensure that the entire array was populated for (int x = 0; x < orderedSubmissions.size(); x++) { for (int y = 0; y < orderedSubmissions.size(); y++) { if (matrix[x][y] == null) { throw new InternalAlgorithmError("Missing Algorithm Results for comparison of submissions \"" + orderedSubmissions.get(x).getName() + "\" and \"" + orderedSubmissions.get(y).getName() + "\""); } } } return new SimilarityMatrix(matrix, orderedSubmissions, orderedSubmissions, results); }
From source file:musite.ProteinsUtil.java
/** * * @param proteins//from w ww . ja v a2s . com * @param ptm * @param enzyme * @return */ public static int countSites(Proteins proteins, Set<AminoAcid> aminoAcids, PTM ptm, Set<String> enzymes) { if (proteins == null || aminoAcids == null || aminoAcids.isEmpty()) throw new IllegalArgumentException(); int count = 0; if (ptm == null) { // residue Iterator<Protein> it = proteins.proteinIterator(); Set<Character> aas = AminoAcid.oneLetters(aminoAcids); while (it.hasNext()) { Protein protein = it.next(); String proteinSeq = protein.getSequence().toUpperCase(); for (char aa : aas) { count += StringUtils.countMatches(proteinSeq, "" + aa); } } } else { Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Set<Integer> sites = PTMAnnotationUtil.getSites(it.next(), ptm, aminoAcids, enzymes); if (sites != null && !sites.isEmpty()) { count += sites.size(); } } } return count; }
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Given a set of edges, creates a new <tt>Graph</tt> that contains all * of those edges, and at least all the vertices that are attached to them. * Uses <tt>{@link edu.uci.ics.jung.graph.filters.UnassembledGraph UnassembledGraph}</tt> * mechanism to create the graph. The parameter decides what to do with * disconnected vertices: <tt>true</tt> says that they should be * retained, <tt>false</tt> says that they should be discarded (with a * {@link edu.uci.ics.jung.graph.filters.impl.DropSoloNodesFilter DropSoloNodesFilter}). * // w ww.j a v a 2 s. c o m * @param edges * A set of <tt>Edge</tt> s that want to be a part of a new * <tt>Graph</tt> * @param retain * Is true if all isolated vertices should be retained; is false if they * should be discarded. * @return A graph, created with <tt>{@link edu.uci.ics.jung.graph.Graph#newInstance Graph.newInstance}</tt>, * containing edges equivalent to (and that are copies of!) all the * edges in the input set. Note that if the input is an empty set, * <tt>null</tt> is returned. */ public static Graph edgeSetToGraph(Set edges, boolean retain) { if (edges.isEmpty()) return null; Edge e = (Edge) edges.iterator().next(); Graph g = (Graph) e.getGraph(); Graph retval = new UnassembledGraph("edgeSetToGraph", g.getVertices(), edges, g).assemble(); if (retain) return retval; else { return DropSoloNodesFilter.getInstance().filter(retval).assemble(); } }
From source file:org.springframework.xd.distributed.util.ServerProcessUtils.java
/** * Block the executing thread until all of the indicated process IDs * have been identified in the list of runtime containers as indicated * by the admin server. If an empty list is provided, the executing * thread will block until there are no containers running. * * @param template REST template used to communicate with the admin server * @param pids set of process IDs for the expected containers * @return map of process id to container id * @throws InterruptedException if the executing thread is interrupted * @throws java.lang.IllegalStateException if the number of containers identified * does not match the number of PIDs provided *///from ww w . j av a 2 s . c o m public static Map<Long, String> waitForContainers(SpringXDTemplate template, Set<Long> pids) throws InterruptedException, IllegalStateException { int pidCount = pids.size(); Map<Long, String> mapPidUuid = getRunningContainers(template); long expiry = System.currentTimeMillis() + 3 * 60000; while (mapPidUuid.size() != pidCount && System.currentTimeMillis() < expiry) { Thread.sleep(500); mapPidUuid = getRunningContainers(template); } if (mapPidUuid.size() == pidCount && mapPidUuid.keySet().containsAll(pids)) { return mapPidUuid; } Set<Long> missingPids = new HashSet<Long>(pids); missingPids.removeAll(mapPidUuid.keySet()); Set<Long> unexpectedPids = new HashSet<Long>(mapPidUuid.keySet()); unexpectedPids.removeAll(pids); StringBuilder builder = new StringBuilder(); if (!missingPids.isEmpty()) { builder.append("Admin server did not find the following container PIDs:").append(missingPids); } if (!unexpectedPids.isEmpty()) { if (builder.length() > 0) { builder.append("; "); } builder.append("Admin server found the following unexpected container PIDs:").append(unexpectedPids); } throw new IllegalStateException(builder.toString()); }
From source file:com.nulli.openam.plugins.NeoUniversalCondition.java
private static String getInitStringValue(Set<String> set) { return ((set == null) || set.isEmpty()) ? "" : set.iterator().next(); }