List of usage examples for java.util HashSet size
public int size()
From source file:Main.java
@SuppressWarnings("rawtypes") public static boolean isEmptySet(HashSet target) { if (target == null || target.size() == 0) { return true; }/*from w w w. ja v a2 s.c o m*/ return false; }
From source file:Main.java
/** * Count the number of unique values in a collection *//* ww w.ja va 2 s .c o m*/ public static int countUnique(Collection<?> collection) { HashSet<Object> set = new HashSet<>(collection); return set.size(); }
From source file:Main.java
private static void addNumberToBase(StringBuffer base, boolean bracketed, HashSet<Integer> set) { if (set.size() > 0) { // Limit on the number of auto-generated item numbers to check for int limit = 100; // Check the set for the numbers encountered and generate the // lowest number accordingly if (set.contains(new Integer(0)) == false) { // Use base } else {/*from w w w .j a v a 2 s . co m*/ for (int x = 1; x < limit; x++) { // Check if the number was already used to auto-generate an // existing item if (set.contains(new Integer(x)) == false) { if (bracketed) base.append(" ("); //$NON-NLS-1$ base.append(x); if (bracketed) base.append(")"); //$NON-NLS-1$ break; } } } } }
From source file:Main.java
/** * Extract a set of Integer indices into an int[]. * @param coll {@code HashSet} of {@code Integer} * @return int[]/*from ww w . j av a2 s .c o m*/ * @since 3.0.1 */ private static int[] extractIndices(HashSet<Integer> coll) { int[] result = new int[coll.size()]; int i = 0; for (Integer index : coll) { result[i++] = index.intValue(); } return result; }
From source file:Main.java
/** * Extract a set of Integer indices into an int[]. * //from ww w. ja va 2s . co m * @param coll * {@code HashSet} of {@code Integer} * @return int[] * @since 3.0.1 */ public static int[] extractIndices(HashSet<Integer> coll) { int[] result = new int[coll.size()]; int i = 0; for (Integer index : coll) { result[i++] = index.intValue(); } return result; }
From source file:org.opencyc.util.OcCollectionUtils.java
/** * Returns <tt>true</tt> iff the given {@link Collection} has any * duplicated elements.//from w w w. j a va2 s. c o m * * @param collection the collection under consideration for having duplicate elements * @return <tt>true</tt> the given {@link Collection} has any duplicated elements */ public static boolean hasDuplicates(final Collection collection) { HashSet aSet = new HashSet(collection); return collection.size() != aSet.size(); }
From source file:Main.java
public static int[] divide(int number, int number_of_parts) { HashSet<Integer> uniqueInts = new HashSet<Integer>(); uniqueInts.add(0);// w w w .j av a 2 s . c om uniqueInts.add(number); int array_size = number_of_parts + 1; while (uniqueInts.size() < array_size) { uniqueInts.add(1 + r.nextInt(number - 1)); } Integer[] dividers = uniqueInts.toArray(new Integer[array_size]); Arrays.sort(dividers); int[] results = new int[number_of_parts]; for (int i = 1, j = 0; i < dividers.length; ++i, ++j) { results[j] = dividers[i] - dividers[j]; } return results; }
From source file:Main.java
private static String getControlByType(String prefs, String key, Object type, String value) { String htmlControl = ""; String htmlControlVal = ""; key = prefs + "_debugghostseperator_" + key; if (type instanceof Boolean) { htmlControlVal = (value.equalsIgnoreCase("true")) ? "checked=\"checked\"" : ""; htmlControl = "<input id=\"" + key + "\" type=\"checkbox\" value=\"" + key + "\" " + htmlControlVal + " />"; } else if (type instanceof Integer) { htmlControlVal = value;//from www.j a v a 2s . c o m htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof String) { htmlControlVal = (value != null) ? value : "null"; htmlControl = "<input class=\"form-control\" type=\"text\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof Float) { htmlControlVal = value; htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof Long) { htmlControlVal = value; htmlControl = "<input class=\"form-control\" type=\"number\" value=\"" + htmlControlVal + "\" id=\"" + key + "\">"; } else if (type instanceof HashSet) { StringBuilder sb = new StringBuilder(); HashSet<String> valueSet = (HashSet) type; int rowHeight = Math.min(valueSet.size(), 5); sb.append("<textarea class=\"form-control\" id=\"" + key + "\" rows=\"" + rowHeight + "\" style=\"margin-top: 0px; margin-bottom: 0px;\">"); for (String val : valueSet) { sb.append(val); sb.append("\r\n"); } sb.delete(sb.length() - 2, sb.length()); sb.append("</textarea>"); htmlControl = sb.toString(); } else { htmlControl = "[DebugGhost has no control configured for type '" + type.getClass().getSimpleName() + "']"; } htmlControl += "<input id=\"" + key + "_TYPE\" type=\"hidden\" value=\"" + type.getClass().getSimpleName() + "\" />"; return htmlControl; }
From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java
/** * random select (without replacement) a fraction of indices from an array * @param object[]// w w w. j a va 2 s . c om * @param num_of_selection * @return * @throws IOException */ public static HashSet<Integer> randomSelectIndices(Object[] seqIdSet, int num_of_selection) throws IOException { int n = Math.min(num_of_selection, seqIdSet.length); HashSet<Integer> selectedIndexSet = new HashSet<Integer>(); while (selectedIndexSet.size() < n) { selectedIndexSet.add(random.nextInt(n)); } return selectedIndexSet; }
From source file:Main.java
/** * Removes duplicate objects from the Collection. * @param p_collection a Collection//from w w w . j a v a 2 s . co m * @returns true if one or more duplicate objects were removed. */ public static boolean removeDuplicates(Collection p_collection) { if (p_collection == null) { return false; } HashSet set = new HashSet(p_collection.size()); Iterator it = p_collection.iterator(); while (it.hasNext()) { set.add(it.next()); } if (set.size() != p_collection.size()) { p_collection.clear(); p_collection.addAll(set); return true; } return false; }