List of usage examples for java.util Set add
boolean add(E e);
From source file:de.topobyte.utilities.apache.commons.cli.parsing.LineHelper.java
/** * Of a collection of specified option names, find those options that are * present in the {@link CommandLine} argument. * //from w w w . j a v a 2 s . co m * @param line * the command line to inspect. * @param options * the option names to look for. * @return the {@link Set} of option names present in the command line * parameter, a subset of the <code>options</code> supplied. */ public static Set<String> findOptions(CommandLine line, Collection<String> options) { Set<String> results = new HashSet<>(); for (String option : options) { if (line.hasOption(option)) { results.add(option); } } return results; }
From source file:Main.java
/** * Return the elements that have been seen at most nSeen times. * * @param nSeen//from w w w . jav a 2 s .c om * @param baseMultiset * @return */ public static <T> Set<T> getElementsWithLessThanCount(final int nSeen, final Multiset<T> baseMultiset) { checkArgument(nSeen > 0); final Set<T> toKeep = Sets.newHashSet(); for (final Entry<T> entry : checkNotNull(baseMultiset).entrySet()) { if (entry.getCount() < nSeen) { toKeep.add(entry.getElement()); } } return toKeep; }
From source file:Main.java
public static void removeDuplicateWithOrder(List arlList) { Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = arlList.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.add(element)) newList.add(element);// w w w . ja v a 2 s . c om } arlList.clear(); arlList.addAll(newList); }
From source file:Main.java
/** * Answer a set containing all elements that are both in source and in query * Delete these elements from source Creation date: (13.10.2002 16:23:00) * /*from w ww. j av a 2 s .c om*/ * @return java.util.Set * @param source * java.util.Set * @param elements * java.util.Collection */ public static Set extractFrom(Set source, Collection query) { Set answer = new HashSet(); Iterator i = query.iterator(); while (i.hasNext()) { Object o = i.next(); if (source.remove(o)) { answer.add(o); } } return answer; }
From source file:Main.java
public static void deletePersons(List<String> personIdsToDelete, String personGroupId, Context context) { SharedPreferences personIdNameMap = context.getSharedPreferences(personGroupId + "PersonIdNameMap", Context.MODE_PRIVATE); SharedPreferences.Editor personIdNameMapEditor = personIdNameMap.edit(); for (String personId : personIdsToDelete) { personIdNameMapEditor.remove(personId); }/*w w w. j a v a2 s. c o m*/ personIdNameMapEditor.commit(); Set<String> personIds = getAllPersonIds(personGroupId, context); Set<String> newPersonIds = new HashSet<>(); for (String personId : personIds) { if (!personIdsToDelete.contains(personId)) { newPersonIds.add(personId); } } SharedPreferences personIdSet = context.getSharedPreferences(personGroupId + "PersonIdSet", Context.MODE_PRIVATE); SharedPreferences.Editor personIdSetEditor = personIdSet.edit(); personIdSetEditor.putStringSet("PersonIdSet", newPersonIds); personIdSetEditor.commit(); }
From source file:com.espertech.esper.pattern.EvalNodeUtil.java
/** * Returns all child nodes as a set./* w ww. ja v a 2 s.c o m*/ * @param currentNode parent node * @return all child nodes */ public static Set<EvalFactoryNode> recursiveGetChildNodes(EvalFactoryNode currentNode, EvalNodeUtilFactoryFilter filter) { Set<EvalFactoryNode> result = new LinkedHashSet<EvalFactoryNode>(); if (filter.consider(currentNode)) { result.add(currentNode); } recursiveGetChildNodes(result, currentNode, filter); return result; }
From source file:Main.java
private static <T> void computeAllItemCombinationsRecursive(T[] input, Set<List<T>> output, List<T> combination, int pos, int maxLength) { if (pos == input.length && combination.size() == maxLength) { output.add(combination); }//from w w w . j av a2 s . c om if (pos < input.length) { if (combination != null) { combination.add(input[pos]); if (combination.size() == maxLength) { output.add(combination); } else { for (int i = pos; i < input.length; ++i) { computeAllItemCombinationsRecursive(input, output, combination, i + 1, maxLength); } } } int lastPosToStartFrom = input.length - maxLength + 1; for (int i = pos; i < lastPosToStartFrom; ++i) { combination = new ArrayList<>(maxLength); combination.add(input[pos]); computeAllItemCombinationsRecursive(input, output, combination, i + 1, maxLength); } } }
From source file:org.cloudifysource.esc.driver.provisioning.jclouds.ProvisioningUtils.java
public static Set<Integer> delimitedStringToSet(final String componentInstanceIDs) throws NumberFormatException { final String[] delimited = componentInstanceIDs.split(","); final Set<Integer> intSet = new HashSet<Integer>(); for (final String str : delimited) { intSet.add(Integer.valueOf(str)); }// w ww .j a v a2 s .co m return intSet; }
From source file:Main.java
final static private boolean _already_logged(String message) { String today = _logged_fmt.format(Calendar.getInstance().getTime()); if (!_logged_msgs.containsKey(today)) { _logged_msgs.clear();/*from ww w . jav a 2 s. c o m*/ _logged_msgs.put(today, new HashSet<String>()); } Set<String> msgs = _logged_msgs.get(today); if (msgs != null && msgs.contains(message)) { return true; } if (msgs != null) { msgs.add(message); } return false; }
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static List removeDuplicateWithOrder(List list) { Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = list.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.add(element)) newList.add(element);//www . j a v a 2 s. co m } return newList; }