List of usage examples for java.util Set add
boolean add(E e);
From source file:com.github.jrh3k5.plugin.maven.l10n.data.AuthoritativeMessagesProperties.java
/** * Parse the translation keys into their respective class representations. * //from ww w. j a v a2s. c om * @param translationKeys * The keys to be parsed. * @return A {@link Collection} of {@link TranslationClass} objects representing the classes represented by the given translation keys. */ private static Collection<TranslationClass> parseTranslationClasses(Collection<String> translationKeys) { final Map<String, Set<String>> classStaging = new HashMap<>(); for (String translationKey : translationKeys) { final int lastPeriodPos = translationKey.lastIndexOf('.'); if (lastPeriodPos < 0) { continue; } final String className = sanitizeClassName(translationKey.substring(0, lastPeriodPos)); final String keyName = translationKey.substring(lastPeriodPos + 1); if (classStaging.containsKey(className)) { classStaging.get(className).add(keyName); } else { final Set<String> keys = new HashSet<>(); keys.add(keyName); classStaging.put(className, keys); } } final Collection<TranslationClass> translationClasses = new ArrayList<>(); for (Entry<String, Set<String>> stagedClass : classStaging.entrySet()) { translationClasses.add(new TranslationClass(stagedClass.getKey(), stagedClass.getValue())); } return translationClasses; }
From source file:com.netflix.nicobar.core.testutil.CoreTestResourceUtil.java
/** * This method normalizes given paths to a standard format. * The input may contain separators in either Unix or Windows format. * The output will contain separators in the format of the system. * @param contentPaths set of paths to normalize * @return set of normalized paths// w ww . j a va 2 s . com */ public static Set<String> normalizeFilenames(Set<String> contentPaths) { Set<String> normalized = new LinkedHashSet<>(); for (String path : contentPaths) { normalized.add(normalize(path)); } return normalized; }
From source file:com.titilink.camel.rest.util.ValidationUtil.java
/** * ??JSR-303bean/*w w w .j a va 2 s . c om*/ * * @param instance * @return */ public static <T> Set<String> validate(T instance, Class<?>... groups) { Set<ConstraintViolation<T>> set = validateBean(instance, groups); Set<String> errorCodeSet = new HashSet<String>(set.size()); for (ConstraintViolation<T> c : set) { errorCodeSet.add(c.getMessage()); } return errorCodeSet; }
From source file:Main.java
public static void deletePersonGroups(List<String> personGroupIdsToDelete, Context context) { SharedPreferences personGroupIdNameMap = context.getSharedPreferences("PersonGroupIdNameMap", Context.MODE_PRIVATE); SharedPreferences.Editor personGroupIdNameMapEditor = personGroupIdNameMap.edit(); for (String personGroupId : personGroupIdsToDelete) { personGroupIdNameMapEditor.remove(personGroupId); }/*from ww w .ja v a2s. c o m*/ personGroupIdNameMapEditor.commit(); Set<String> personGroupIds = getAllPersonGroupIds(context); Set<String> newPersonGroupIds = new HashSet<>(); for (String personGroupId : personGroupIds) { if (!personGroupIdsToDelete.contains(personGroupId)) { newPersonGroupIds.add(personGroupId); } } SharedPreferences personGroupIdSet = context.getSharedPreferences("PersonGroupIdSet", Context.MODE_PRIVATE); SharedPreferences.Editor personGroupIdSetEditor = personGroupIdSet.edit(); personGroupIdSetEditor.putStringSet("PersonGroupIdSet", newPersonGroupIds); personGroupIdSetEditor.commit(); }
From source file:Main.java
public static <T> T getFirstDuplicateValue(Collection<T> collection) { Set<T> set = new HashSet<T>(); // Set#add returns false if the set does not change, which // indicates that a duplicate element has been added. for (T each : collection) { if (!set.add(each)) return each; }//from www . jav a2 s. c o m return null; }
From source file:Main.java
private static Set<Character> strToSet(final String str) { Set<Character> set; if (str == null) { return new HashSet<Character>(); }/*from w w w . j ava 2 s . c o m*/ set = new HashSet<Character>(str.length()); for (int i = 0; i < str.length(); i++) { set.add(str.charAt(i)); } return set; }
From source file:Main.java
/** * Internal function to realize the mathematical combination of given * values. This method creates the next sub-tree by iterating over values * given by parameter set./* ww w . j a v a 2s .c om*/ * * @param <E> * the type of the given and returned values * @param set * the possible values for next iteration * @param combination * the current path of the abstract combination tree * @param combinations * overall combinations */ private static <E extends Object> void combination(Set<E> set, Set<E> combination, Set<Set<E>> combinations) { for (E value : set) { Set<E> combination_ = new HashSet<E>(); combination_.addAll(combination); combination_.add(value); combinations.add(combination_); Set<E> set_ = new HashSet<E>(); set_.addAll(set); long size = set_.size(); set_.remove(value); if (set_.size() == size) { for (E v : set_) { if (v.equals(value)) { set_.remove(v); break; } } } if (!set_.isEmpty()) { combination(set_, combination_, combinations); } } }
From source file:com.intuit.tank.script.ScriptStepFactory.java
public static ScriptStep createVariable(String key, String value) { ScriptStep step = new ScriptStep(); step.setType(ScriptConstants.VARIABLE); RequestData reqData = new RequestData(); reqData.setKey(key);/* ww w.j a va2s . c om*/ reqData.setValue(value); Set<RequestData> set = new HashSet<RequestData>(); set.add(reqData); step.setData(set); return step; }
From source file:com.intuit.tank.script.ScriptStepFactory.java
public static ScriptStep createSleepTime(String delay) { ScriptStep sleep = new ScriptStep(); sleep.setType(ScriptConstants.SLEEP); sleep.setComments("SLEEP " + delay); RequestData data = new RequestData(); data.setType(ScriptConstants.SLEEP); data.setKey(ScriptConstants.TIME);/*from w w w . j ava2 s . c o m*/ data.setValue(delay); Set<RequestData> ds = new HashSet<RequestData>(); ds.add(data); sleep.setData(ds); return sleep; }
From source file:Main.java
public static Set<Node> findChildElementsByTag(Node node, String tag) { final Set<Node> result = new LinkedHashSet<>(); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (tag.equals(child.getNodeName())) { result.add(child); } else if (child.hasChildNodes()) { result.addAll(findChildElementsByTag(child, tag)); }/* w w w.j a va 2 s . c om*/ } return result; }