List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:Main.java
static Set<String> jsonObjectKeySet(JSONObject jsonObject) { HashSet<String> result = new HashSet<String>(); @SuppressWarnings("unchecked") Iterator<String> keys = (Iterator<String>) jsonObject.keys(); while (keys.hasNext()) { result.add(keys.next()); }/*from www .ja va 2s. c om*/ return result; }
From source file:Main.java
@SuppressLint("NewApi") public static List<Size> getCameraSupportedVideoSizes(android.hardware.Camera camera) { if (camera != null) { if ((Build.VERSION.SDK_INT >= 11) && camera.getParameters().getSupportedVideoSizes() != null) { return camera.getParameters().getSupportedVideoSizes(); } else {// w ww . ja v a 2s .c o m // Video sizes may be null, which indicates that all the supported // preview sizes are supported for video recording. HashSet<String> allSizesLiteral = new HashSet<>(); for (Camera.Size sz : camera.getParameters().getSupportedPreviewSizes()) { allSizesLiteral.add(String.format("%dx%d", sz.width, sz.height)); } // on Samsung Galaxy 3, the supported preview sizes are too many, // but it seems that not all of them can be used as recording video size. // the following set are used by the built-in camera app. Camera.Size[] preferredSizes = { camera.new Size(1920, 1080), camera.new Size(1280, 720), camera.new Size(720, 480), camera.new Size(640, 480), camera.new Size(320, 240) }; List<Size> result = new ArrayList<>(preferredSizes.length); for (Camera.Size sz : preferredSizes) { if (allSizesLiteral.contains(String.format("%dx%d", sz.width, sz.height))) result.add(sz); } return result; } } else { return null; } }
From source file:bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation.java
private static HashSet<Identify> getBestResult(ArrayList<Identify> results) { Collections.sort(results, Identify.ScoreDESC); double bestScore = results.get(0).getScore(); String pep = results.get(0).getPeptide().getSequence(); HashSet<Identify> selectedTops = new HashSet<Identify>(); selectedTops.add(results.get(0)); for (int i = 1; i < results.size(); i++) { Identify ind = results.get(i);//from w ww . j a v a2 s. c o m double tmpScore = ind.getScore(); String tmpPep = ind.getPeptide().getSequence(); // making sure that non-redundant peptide would be only found if (tmpScore == bestScore && !pep.equals(tmpPep)) { bestScore = tmpScore; selectedTops.add(ind); } } return selectedTops; }
From source file:de.kbs.acavis.integration.mas.odata.EntityHelper.java
@SuppressWarnings("unchecked") public static <T> Set<T> extractProperty(Enumerable<OEntity> entities, String propertyName) { HashSet<T> properties = new HashSet<T>(); // We can try to cast the property because getProperty would throw such an exception anyways for (OEntity entity : entities) properties.add((T) (entity.getProperty(propertyName).getValue())); return properties; }
From source file:loci.plugins.util.LibraryChecker.java
/** * Checks whether the given class is available; if not, * adds the specified JAR file name to the hash set * (presumably to report it missing to the user). *//*w w w .jav a 2 s . co m*/ public static void checkLibrary(String className, String jarFile, HashSet<String> missing) { if (!checkClass(className)) missing.add(jarFile); }
From source file:Main.java
/** * Get all threads//from ww w.j a va 2 s . co m * * @return */ public static String[] getThreadNames() { ThreadGroup group = Thread.currentThread().getThreadGroup(); ThreadGroup parent = null; while ((parent = group.getParent()) != null) { group = parent; } Thread[] threads = new Thread[group.activeCount()]; group.enumerate(threads); HashSet<String> set = new HashSet<String>(); for (int i = 0; i < threads.length; ++i) { if (threads[i] != null && threads[i].isAlive()) { try { set.add(threads[i].getThreadGroup().getName() + ", " + threads[i].getName() + ", " + threads[i].getPriority() + ", " + threads[i].getState()); } catch (Throwable e) { e.printStackTrace(); } } } String[] result = (String[]) set.toArray(new String[0]); Arrays.sort(result); for (int i = 0; i < result.length; i++) { // logger.debug(result[i]); } return result; }
From source file:Main.java
/** * Get the interfaces for the specified class. * * @param cls the class to look up, may be {@code null} * @param interfacesFound the {@code Set} of interfaces for the class *//*from ww w . j ava 2 s .c om*/ private static void getAllInterfaces(Class<?> cls, HashSet<Class<?>> interfacesFound) { while (cls != null) { Class<?>[] interfaces = cls.getInterfaces(); for (Class<?> i : interfaces) { if (interfacesFound.add(i)) { getAllInterfaces(i, interfacesFound); } } cls = cls.getSuperclass(); } }
From source file:Main.java
public static <T> List<T> updateList(List<T> toBeUpdated, HashSet<T> updates) { HashSet<T> toBeUpdatedHashSet = new HashSet<T>(toBeUpdated); for (T id : updates) { if (toBeUpdatedHashSet.contains(id)) { toBeUpdatedHashSet.remove(id); } else {//from w w w . j a va2 s .c o m toBeUpdatedHashSet.add(id); } } return new ArrayList<T>(toBeUpdatedHashSet); }
From source file:Main.java
public static HashSet<String> intersectionSet(HashSet<String> setA, HashSet<String> setB) { HashSet<String> intersectionSet = new HashSet<String>(); Iterator<String> iterA = setA.iterator(); while (iterA.hasNext()) { String tempInner = iterA.next(); if (setB.contains(tempInner)) { intersectionSet.add(tempInner); }//from ww w .ja v a 2 s .co m } return intersectionSet; }
From source file:com.examples.with.different.packagename.ClassWithPrivateInterfaces.java
private static void getAllInterfaces(Class<?> cls, final HashSet<Class<?>> interfacesFound) { while (cls != null) { final Class<?>[] interfaces = cls.getInterfaces(); for (final Class<?> i : interfaces) { if (interfacesFound.add(i)) { getAllInterfaces(i, interfacesFound); }//from w w w.j a v a 2 s .c om } cls = cls.getSuperclass(); } }