List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:com.nulli.openam.plugins.NeoUniversalCondition.java
private static String getStringValue(Set<String> set) { return ((set == null) || set.isEmpty()) ? null : set.iterator().next(); }
From source file:com.doculibre.constellio.services.SearchServicesImpl.java
private static void addTagsTo(SimpleSearch simpleSearch, SolrQuery query) { StringBuffer sb = new StringBuffer(); Set<String> tags = simpleSearch.getTags(); if (!tags.isEmpty()) { sb.append("("); for (Iterator<String> it = tags.iterator(); it.hasNext();) { String tag = it.next(); sb.append("("); sb.append(IndexField.FREE_TEXT_TAGGING_FIELD + ":" + tag); sb.append(" OR "); sb.append(IndexField.THESAURUS_TAGGING_FIELD + ":" + tag); sb.append(")"); if (it.hasNext()) { sb.append(" AND "); }/*from ww w . j a va2 s. c o m*/ } sb.append(")"); } query.addFilterQuery(sb.toString()); }
From source file:jeeves.xlink.Processor.java
/** * Uncaches an xlink//from ww w.j a v a2 s . c om */ public static void uncacheXLinkUri(String uri) throws CacheException { JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS); String mappedURI = mapURI(uri); Set groupKeys = xlinkCache.getGroupKeys(mappedURI); if (groupKeys == null || groupKeys.isEmpty()) { xlinkCache.remove(uri); } else { for (Object key : groupKeys) { xlinkCache.remove(key, mappedURI); } } }
From source file:musite.ProteinsUtil.java
/** * * @param proteinsList/*w w w .java 2 s . co m*/ * @param ptm * @param aminoAcids * @return Map: * Key: protein accession; * Value: Map * Key: location * Value: index of the Proteins */ public static Map<String, Map<Integer, Set<Integer>>> siteOverlap(List<Proteins> proteinsList, PTM ptm, Set<AminoAcid> aminoAcids) { if (proteinsList == null || proteinsList.size() < 2) { throw new IllegalArgumentException(); } Map<String, Map<Integer, Set<Integer>>> result = new HashMap(); int n = proteinsList.size(); for (int i = 0; i < n; i++) { Proteins proteins = proteinsList.get(i); Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Protein protein = it.next(); String acc = protein.getAccession(); Set<Integer> sites = musite.PTMAnnotationUtil.getSites(protein, ptm, aminoAcids); if (sites == null || sites.isEmpty()) continue; Map<Integer, Set<Integer>> map = result.get(acc); if (map == null) { map = new TreeMap(); result.put(acc, map); } for (Integer site : sites) { Set<Integer> set = map.get(site); if (set == null) { set = new TreeSet(); map.put(site, set); } set.add(i); } } } return result; }
From source file:org.agiso.core.lang.util.ClassUtils.java
/** * Wyszukuje dla wskazanej klasy publiczn metod o okrelonej sygnaturze. Jeli * metoda nie zostanie naleziona wyrzuca wyjtek {@code IllegalStateException}. * <p>W przypadku gdy nie jest okrelona tablica parametrw wywoania, zwraca metod * tylko gdy wynik wyszukiwania jest unikatowy, tj. istnieje tylko jedna publiczna * metoda o wskazanej nazwie.//from w w w . j a v a 2 s . c om * * <p>Based on: * org.springframework.util.ClassUtils.getMethod(Class<?>, String, Class<?>...) * * @param clazz Klasa do sprawdzenia * @param methodName Nazwa wyszukiwanej metody * @param paramTypes Tablica typw parametrw wywoania metody * (moe by {@code null} w celu wyszukania dowolnej metody o wskazanej nazwie) * @return Znaleziona metoda (niegdy {@code null}) * @throws IllegalStateException jeli nie znaleziono metody lub nie jest unikatowa * @see Class#getMethod */ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) { if (clazz == null) { throw new NullPointerException("Klasa musi by okrelona"); } if (methodName == null) { throw new NullPointerException("Nazwa metody musi by okrelona"); } if (paramTypes != null) { try { return clazz.getMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { throw new IllegalStateException("Expected method not found: " + ex); } } else { Set<Method> candidates = new HashSet<Method>(1); Method[] methods = clazz.getMethods(); for (Method method : methods) { if (methodName.equals(method.getName())) { candidates.add(method); } } if (candidates.size() == 1) { return candidates.iterator().next(); } else if (candidates.isEmpty()) { throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName); } else { throw new IllegalStateException("No unique method found: " + clazz + "." + methodName); } } }
From source file:backtype.storm.blobstore.BlobStoreTest.java
public static void assertStoreHasExactly(BlobStore store, Subject who, String... keys) throws IOException, KeyNotFoundException, AuthorizationException { Set<String> expected = new HashSet<String>(Arrays.asList(keys)); Set<String> found = new HashSet<String>(); Iterator<String> c = store.listKeys(); while (c.hasNext()) { String keyName = c.next(); found.add(keyName);/*from ww w .j a v a2 s .c o m*/ } Set<String> extra = new HashSet<String>(found); extra.removeAll(expected); assertTrue("Found extra keys in the blob store " + extra, extra.isEmpty()); Set<String> missing = new HashSet<String>(expected); missing.removeAll(found); assertTrue("Found keys missing from the blob store " + missing, missing.isEmpty()); }
From source file:se.uu.it.cs.recsys.service.preference.ConstraintSolverPreferenceBuilder.java
private static boolean inPlanYear(Course course, Set<CourseSchedule> scheduleInfo) { Set<Boolean> bingo = new HashSet<>(); scheduleInfo.forEach(schedule -> { if (Short.compare(course.getTaughtYear(), schedule.getTaughtYear()) == 0 && Short.compare(course.getStartPeriod(), schedule.getStartPeriod()) == 0) { bingo.add(Boolean.TRUE); }/*from w ww . j a v a 2 s. co m*/ }); return !bingo.isEmpty(); }
From source file:net.lldp.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 *///www . j a va2 s . co m 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 AlgorithmResults[][] matrix = new AlgorithmResults[inputSubmissions.size()][inputSubmissions.size()]; //Ordering sortBy = Ordering.natural(); Ordering<Submission> sortBy = Ordering.from(new Comparator<Submission>() { public int compare(Submission a, Submission b) { return ((Double) b.getTotalCopyScore()).compareTo(a.getTotalCopyScore()); } }); // Order the submissions List<Submission> orderedSubmissions = sortBy.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 AlgorithmResults(Pair.of(s, s), Real.ONE, Real.ONE); } // 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) { if (!result.a.testFlag("invalid")) { throw new InternalAlgorithmError( "Processed Algorithm Result with submission not in given input submissions with name \"" + result.a.getName() + "\""); } } else if (bIndex == -1) { if (!result.b.testFlag("invalid")) { throw new InternalAlgorithmError( "Processed Algorithm Result with submission not in given input submissions with name \"" + result.b.getName() + "\""); } } else { matrix[aIndex][bIndex] = result.inverse(); matrix[bIndex][aIndex] = result; } } // 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:com.evolveum.midpoint.repo.sql.util.RUtil.java
public static List<ObjectReferenceType> safeSetReferencesToList(Set<? extends RObjectReference> set, PrismContext prismContext) {//from www. j av a2 s . co m if (set == null || set.isEmpty()) { return new ArrayList<>(); } List<ObjectReferenceType> list = new ArrayList<>(); for (RObjectReference str : set) { ObjectReferenceType ort = new ObjectReferenceType(); RObjectReference.copyToJAXB(str, ort, prismContext); list.add(ort); } return list; }
From source file:expansionBlocks.ProcessCommunities.java
private static Set<Entity> removableAccordingToCategories(Map<Entity, Double> community) { community = MapUtils.sortByValue(community); Set<Entity> firstLevel = new HashSet<>(); double lastSize = 0.0; for (Map.Entry<Entity, Double> e : community.entrySet()) { if (firstLevel.isEmpty() || lastSize == e.getValue()) { firstLevel.add(e.getKey());/*w ww .j av a 2s. c o m*/ lastSize = e.getValue(); } else break; } println("First level entities: " + firstLevel); Set<Category> firstLevelCategories = new HashSet<>(); for (Entity e : firstLevel) { firstLevelCategories.addAll(e.getCategories()); } println("First Level Categories = " + firstLevelCategories); Set<Category> secondLevelCategories = new HashSet<>(); for (Category c : firstLevelCategories) { secondLevelCategories.addAll(Category.getFathers(c)); } println("Second Level Categories = " + secondLevelCategories); Set<Category> thirdLevelCategories = new HashSet<>(); for (Category c : secondLevelCategories) { thirdLevelCategories.addAll(Category.getFathers(c)); } println("Third Level Categories = " + thirdLevelCategories); Set<Entity> susceptibleToBeRemoved = new HashSet<>(); for (Map.Entry<Entity, Double> e : community.entrySet()) { Entity entity = e.getKey(); Set<Category> entityCategory = entity.getCategories(); boolean maintainEntity = false; for (Category c : entityCategory) { maintainEntity |= (firstLevelCategories.contains(c) || secondLevelCategories.contains(c) || thirdLevelCategories.contains(c) || isSonOf(secondLevelCategories, c) || isGrandSon(thirdLevelCategories, c)); } if (!maintainEntity) susceptibleToBeRemoved.add(entity); } return susceptibleToBeRemoved; }