List of usage examples for java.util Set add
boolean add(E e);
From source file:Main.java
/** * Many to One way of finding Keys from value * @param map/*from w w w. j a v a 2 s. c o m*/ * @param value * @return keys */ public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) { Set<T> keys = new HashSet<T>(); for (Entry<T, E> entry : map.entrySet()) { if (value.equals(entry.getValue())) { keys.add(entry.getKey()); } } return keys; }
From source file:Main.java
public static Set<Integer> toSet(int... array) { if (isEmpty(array)) { return new HashSet<>(0); }// w w w. j av a2 s . c o m Set<Integer> set = new HashSet<>(array.length); for (int I : array) { set.add(new Integer(I)); } return set; }
From source file:Main.java
public static <T> List<T> copyWithoutDublicates(List<T> l) { final List<T> result = new ArrayList<T>(); final Set<T> set = new HashSet<T>(); for (Iterator<T> it = l.iterator(); it.hasNext();) { final T t = it.next(); if (set.add(t)) { result.add(t);/*w w w. j ava 2s . c om*/ } } return result; }
From source file:me.smoe.adar.analyzer.luence.AnalyzerToy.java
public static Set<String> analyzerByStandard(String sentence) throws Exception { Analyzer analyzer = new StandardAnalyzer(); try {// ww w. j av a 2s . c om TokenStream tokenStream = analyzer.tokenStream(StringUtils.EMPTY, new StringReader(sentence)); tokenStream.addAttribute(CharTermAttribute.class); tokenStream.reset(); Set<String> words = new HashSet<>(); while (tokenStream.incrementToken()) { words.add(((CharTermAttribute) tokenStream.getAttribute(CharTermAttribute.class)).toString()); } return words; } finally { analyzer.close(); } }
From source file:Main.java
public static Set<Double> toSet(double... array) { if (isEmpty(array)) { return new HashSet<>(0); }/*from ww w . j ava 2 s .c om*/ Set<Double> set = new HashSet<>(array.length); for (double d : array) { set.add(new Double(d)); } return set; }
From source file:Main.java
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) { Set<T> keys = new HashSet<T>(); for (Map.Entry<T, E> entry : map.entrySet()) { if (value.equals(entry.getValue())) { keys.add(entry.getKey()); }/*from ww w . j ava 2 s .co m*/ } return keys; }
From source file:org.springmodules.util.Strings.java
/** * Removes duplicates from the given String array. * //from w w w . j a v a 2s . c o m * @param array * the given array * @return a new String array without duplicated entries */ public static String[] removeDuplicates(String[] array) { if (ObjectUtils.isEmpty(array)) { return array; } Set set = new TreeSet(); int arraySize = array.length; for (int i = 0; i < arraySize; i++) { set.add(array[i]); } return (String[]) set.toArray(new String[set.size()]); }
From source file:Main.java
public static Set<Boolean> toSet(boolean... array) { if (isEmpty(array)) { return new HashSet<>(0); }/*from w w w . ja va 2s.c o m*/ Set<Boolean> set = new HashSet<>(array.length); for (boolean b : array) { set.add(Boolean.valueOf(b)); } return set; }
From source file:Main.java
public static long add(Set set) { long start, stop, result = 0; for (int i = 0; i < 100; i++) { start = System.nanoTime(); set.add(set.size() + 1 + i); stop = System.nanoTime(); result += stop - start;//from w w w .ja v a 2s.c o m } return result / 100; }
From source file:com.opengamma.core.region.RegionUtils.java
/** * Creates a set of regions from a region id. * This is useful in the case where the region is compound (e.g. NY+LON). * //from w w w. j a v a 2 s . com * @param regionSource The region source, not null * @param regionId The region id, not null * @return a set of the region(s) */ public static Set<Region> getRegions(RegionSource regionSource, final ExternalId regionId) { Validate.notNull(regionSource, "region source"); Validate.notNull(regionId, "region id"); if (regionId.isScheme(ExternalSchemes.FINANCIAL) && regionId.getValue().contains("+")) { final String[] regions = regionId.getValue().split("\\+"); final Set<Region> resultRegions = new HashSet<Region>(); for (final String region : regions) { resultRegions.add(regionSource.getHighestLevelRegion(ExternalSchemes.financialRegionId(region))); } return resultRegions; } return Collections.singleton(regionSource.getHighestLevelRegion(regionId)); }