List of usage examples for java.util Set size
int size();
From source file:org.openmrs.module.reportingrest.web.resource.AdHocQueryResourceTest.java
private static Matcher<IdSet<?>> hasExactlyIds(final Integer... expectedMemberIds) { return new BaseMatcher<IdSet<?>>() { @Override// www. j a v a 2 s .c o m public boolean matches(Object o) { Set<Integer> actual = ((IdSet<?>) o).getMemberIds(); return (actual.size() == expectedMemberIds.length) && containsInAnyOrder(expectedMemberIds).matches(actual); } @Override public void describeTo(Description description) { description.appendValue("IdSet with " + expectedMemberIds.length + " members: " + OpenmrsUtil.join(Arrays.asList(expectedMemberIds), ", ")); } }; }
From source file:dk.statsbiblioteket.alto.AnagramHashing.java
public static void dumpAnagramTerms(AnagramDictionary anagramDictionary, int minVariants, int maxVariants, int maxLev, boolean onlyStrongPrimaries) { System.out.println("minTerms=" + minVariants + ", maxTerms=" + maxVariants + ", maxLev=" + (maxLev < 0 ? "N/A" : maxLev)); List<Pair<Integer, String>> values = new ArrayList<Pair<Integer, String>>(); primaryLoop: for (Map.Entry<String, AnagramDictionary.Word> entry : anagramDictionary.getPrimaryDict() .entrySet()) {//from ww w . j a v a 2s . com AnagramDictionary.Word word = entry.getValue(); Set<String> secondaries = maxLev < 0 ? word.getSecondaries() : word.getSecondaries(maxLev); if (secondaries.size() + 1 < minVariants || secondaries.size() + 1 > maxVariants) { continue; } String output = word.getPrimary() + "(" + word.getPrimaryOccurrences() + "):"; for (String secondary : secondaries) { int secondaryOccurrences = anagramDictionary.get(secondary).getPrimaryOccurrences(); if (onlyStrongPrimaries) { if (secondaryOccurrences > word.getPrimaryOccurrences()) { continue primaryLoop; } } output += " " + secondary + "(" + secondaryOccurrences + ")"; } values.add(new Pair<Integer, String>(word.getPrimaryOccurrences(), output)); } Collections.sort(values); Collections.reverse(values); for (Pair<Integer, String> value : values) { System.out.println(value.getPayload()); } }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override//w w w . j a v a2s .c o m public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:Main.java
public static <T> Set<? extends T> interSubtype(final Set<? extends T> a, final Set<? extends T> b) { if (a == b)/* www . ja va2 s .c o m*/ return a; else if (a == null) return b; else if (b == null) return a; else if (a.size() > b.size()) { return interSubtype(b, a); } final Set<T> res = new HashSet<T>(); for (final T item : a) { if (b.contains(item)) res.add(item); } return res; }
From source file:com.walmartlabs.mupd8.application.Config.java
private static HashMap<String, JSONObject> extractWorkerJSONs(JSONObject configuration) { HashMap<String, JSONObject> performers = new HashMap<String, JSONObject>(); JSONObject applications = (JSONObject) getScopedValue(configuration, new String[] { "mupd8", "application" }); if (applications == null) { // Lost cause: No applications found. System.err.println("No mupd8:application found; Config.workerJSONs not set."); return performers; }//from ww w . j a v a 2 s .c o m Set<?> applicationNames = applications.keySet(); if (applicationNames.size() != 1) { System.err.println("Exactly one application definition expected, but got " + Integer.toString(applicationNames.size()) + " instead; Config.workerJSONs not set."); return performers; } String applicationName = applicationNames.toArray(new String[] {})[0]; JSONObject performerSection = (JSONObject) getScopedValue(applications, new String[] { applicationName, "performers" }); for (Object k : performerSection.keySet()) { String key = (String) k; performers.put(key, (JSONObject) performerSection.get(key)); } return performers; }
From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java
public static Class[] findAnnotatedClasses(String path, String packageName, String annotation) throws IOException, ClassNotFoundException { URL url = new URL("jar", "", "file:" + path + "!/"); Set<Class> classes = findClasses(new File(url.getFile()), packageName, Class.forName(annotation)); return classes.toArray(new Class[classes.size()]); }
From source file:be.uclouvain.multipathcontrol.stats.JSONSender.java
/** * Get all sets of data that have to be send, prepare the JSON and send it. * If correctly sent, clear data from settings. *//*from ww w.j av a 2 s. co m*/ public static void sendAll(Context context) { if (!trySending()) return; SharedPreferences settings = context.getSharedPreferences(Config.PREFS_NAME, Context.MODE_PRIVATE); for (StatsCategories category : StatsCategories.values()) { String key = Config.PREFS_STATS_SET + '_' + category; Set<String> statsSet = settings.getStringSet(key, null); if (statsSet == null) continue; JSONSender jsonSenders[] = new JSONSender[statsSet.size()]; int i = 0; // Get all data sets and send them for (String name : statsSet) jsonSenders[i++] = new JSONSender(context, name, category); JSONSenderTask jsonSenderTask = new JSONSenderTask(settings, category); jsonSenderTask.execute(jsonSenders); } }
From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java
private static List<Long> getMutations(String prefix, int limit) { logger.info("Trying to fetch " + limit + " mutations"); Set<Long> covered = MutationCoverageFile.getCoveredMutations(); List<Long> mutationIds = QueryManager.getMutationsWithoutResult(covered, limit); logger.info("Covered Mutations " + covered.size()); logger.info("Got " + mutationIds.size() + " mutations"); return mutationIds; }
From source file:Main.java
/** * Implements <em>equals</em> per the contract defined by {@link Set#equals(Object)}. * // w w w. j a v a 2s . c o m * @param set the set * @param o an object to compare to the list * @return true if {@code o} equals {@code list} */ public static boolean equals(Set<?> set, Object o) { if (!(o instanceof Set)) { return false; } if (set == o) { return true; } Set<?> other = (Set<?>) o; if (set.size() != other.size()) { return false; } // The spec for interface Set says a set should never contain itself, but most implementations // do not explicitly block this. So the paranoid code below handles this case. boolean containsItself = false; for (Object element : set) { if (element == set || element == other) { // don't test using contains(...) since that could cause infinite recursion containsItself = true; } else { if (!other.contains(element)) { return false; } } } if (containsItself) { // safely check that other also contains itself for (Object element : other) { if (element == set || element == other) { return true; } } return false; } return true; }
From source file:cc.kave.commons.pointsto.evaluation.cv.CVEvaluator.java
private static Set<ICoReMethodName> getExpectation(Usage validationUsage, Query q) { Set<CallSite> missingCallsites = new HashSet<>(validationUsage.getReceiverCallsites()); missingCallsites.removeAll(q.getAllCallsites()); Set<ICoReMethodName> expectation = new HashSet<>(missingCallsites.size()); for (CallSite callsite : missingCallsites) { expectation.add(callsite.getMethod()); }// w ww . j a va2 s . co m return expectation; }