List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:Main.java
public static <T, V extends T> HashSet<T> createHashSet(V... args) { if (args == null || args.length == 0) { return new HashSet<T>(); } else {//from w w w . j av a2 s . c om HashSet<T> set = new HashSet<T>(args.length); for (V v : args) { set.add(v); } return set; } }
From source file:Main.java
public static <ELEMENT> HashSet<ELEMENT> newHashSet(ELEMENT... elements) { final HashSet<ELEMENT> set = newHashSetSized(elements.length); for (ELEMENT element : elements) { set.add(element); }//from w w w .java2s .c om return set; }
From source file:Main.java
public static ArrayList<Double> stringToDoubleListRemoved(String s, String delimeter, int[] fieldsToBeRemoved) { ArrayList<Double> ret = new ArrayList<Double>(); ArrayList<Double> allFields = stringToDoubleList(s, delimeter); HashSet<Integer> toBeRemoved = new HashSet<Integer>(); for (int i : fieldsToBeRemoved) toBeRemoved.add(i); for (int i = 0; i < allFields.size(); i++) { if (toBeRemoved.contains(i)) continue; ret.add(allFields.get(i));//from w w w. j a va 2 s . c om } return ret; }
From source file:Main.java
/** * Set factory/*from www. java 2 s .c o m*/ */ public static <T> HashSet<T> hashSet(T... values) { if (values != null) { HashSet<T> set = new HashSet<T>(values.length); for (T v : values) { set.add(v); } return set; } return new HashSet<T>(0); }
From source file:Main.java
public static <E, O extends E> HashSet<E> createHashSet(O... args) { if (args == null || args.length == 0) { return new HashSet<E>(); }// www . j av a 2 s.c om HashSet<E> set = new HashSet<E>(args.length); for (O o : args) { set.add(o); } return set; }
From source file:Main.java
/** * Creates <code>Set</code> of <code>TrustAnchor</code>s * containing single element (self signed test certificate). * @return Returns <code>Set</code> of <code>TrustAnchor</code>s *///from w w w .j av a2s . c o m public static Set<TrustAnchor> getTrustAnchorSet() { TrustAnchor ta = getTrustAnchor(); if (ta == null) { return null; } HashSet<TrustAnchor> set = new HashSet<TrustAnchor>(); if (!set.add(ta)) { throw new RuntimeException("Could not create trust anchor set"); } return set; }
From source file:Main.java
public static HashSet<String> stringToHashSet(String str) { HashSet<String> hs = new HashSet<String>(); if (str.equals("") || str == null) return null; if (!str.contains(",")) hs.add(str); else {// ww w . j a v a 2 s .c o m String[] arr = str.split(","); for (String s : arr) hs.add(s); } return hs; }
From source file:Main.java
/** * Removes duplicate objects from the Collection. * @param p_collection a Collection/*from w w w.j av 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; }
From source file:Main.java
public static HashSet<String> getExcludedTags(Context context) { String tags = PreferenceManager.getDefaultSharedPreferences(context).getString("excludeTagsInheritance", null);//from w w w. j a v a2 s.c o m if (tags == null) return null; HashSet<String> tagsSet = new HashSet<String>(); for (String tag : tags.split(":")) { if (TextUtils.isEmpty(tag) == false) tagsSet.add(tag); } return tagsSet; }
From source file:Main.java
@Nullable public static Object valueFromString(String newValue, Object existingValue) throws IllegalArgumentException { if (existingValue instanceof Integer) { return Integer.parseInt(newValue); } else if (existingValue instanceof Long) { return Long.parseLong(newValue); } else if (existingValue instanceof Float) { return Float.parseFloat(newValue); } else if (existingValue instanceof Boolean) { return parseBoolean(newValue); } else if (existingValue instanceof String) { return newValue; } else if (existingValue instanceof Set) { try {/*from w w w.ja v a 2 s .co m*/ JSONArray obj = new JSONArray(newValue); int objN = obj.length(); HashSet<String> set = new HashSet<String>(objN); for (int i = 0; i < objN; i++) { set.add(obj.getString(i)); } return set; } catch (JSONException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException("Unsupported type: " + existingValue.getClass().getName()); } }