List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:Main.java
public static Date get(List<Date> otherDates, Date dateToApproach) { final TreeSet<Date> set = new TreeSet<Date>(otherDates); set.add(dateToApproach); final ArrayList<Date> list = new ArrayList<Date>(set); final int indexOf = list.indexOf(dateToApproach); if (indexOf == 0) return null; return list.get(indexOf - 1); }
From source file:Main.java
public static <T> TreeSet<T> toTreeSet(Collection<T> collection, Comparator<T> comparator) { final TreeSet<T> treeSet = new TreeSet<T>(comparator); for (T t : collection) { treeSet.add(t); }//from ww w. ja va 2 s.co m return treeSet; }
From source file:Main.java
public static <T> SortedSet<T> sortTopN(Iterable<T> iterable, int n, Comparator<T> comparator) { TreeSet<T> r = Sets.newTreeSet(comparator); for (T t : iterable) { r.add(t); if (r.size() > n) { r.pollLast();/*from w w w . jav a2 s. c o m*/ } } return r; }
From source file:Main.java
public static <T> TreeSet<T> treeSet(final T item) { final TreeSet<T> treeSet = new TreeSet<>(); if (null != item) { treeSet.add(item); }//from w w w. ja v a 2 s . c o m return treeSet; }
From source file:Main.java
public static SortedSet reverseSortedSet(int[] ints) { TreeSet sortedSet = new TreeSet(Collections.reverseOrder()); for (int i = 0; i < ints.length; i++) { sortedSet.add(new Integer(ints[i])); }/*w w w .j ava 2 s . c o m*/ return sortedSet; }
From source file:Main.java
public static <T, V extends T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, V... args) { TreeSet<T> set = new TreeSet<T>(comparator); if (args != null) { for (V v : args) { set.add(v); }/*from w w w .j a va 2s . c om*/ } return set; }
From source file:Main.java
public static <T, V extends T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, V... args) { TreeSet<T> set = new TreeSet<T>(comparator); if (args != null) { for (V v : args) { set.add(v); }/* w w w. j a v a 2 s . c o m*/ } return set; }
From source file:Main.java
public static <T> TreeSet<T> treeSet(final T[] items) { final TreeSet<T> treeSet = new TreeSet<>(); if (null != items) { for (final T item : items) { if (null != item) { treeSet.add(item); }/* ww w . ja v a 2s . c o m*/ } } return treeSet; }
From source file:gemlite.core.internal.admin.AdminUtil.java
/** * ?RegionNames,Set<String>/*from w ww . j a v a 2 s . c om*/ * * @param cache * @return */ public static TreeSet<String> getRegionNames(Cache cache) { try { Set<Region<?, ?>> regions = cache.rootRegions(); if ((regions.isEmpty()) || (regions == null)) { return null; } else { TreeSet regionInformationSet = new TreeSet(); for (Region region : regions) { regionInformationSet.add(region.getFullPath().substring(1)); } return regionInformationSet; } } catch (CacheClosedException e) { LogUtil.getAppLog().error("error CacheClosedException:", e); } catch (Exception e) { LogUtil.getAppLog().error("error:", e); } return null; }
From source file:com.cyberway.issue.net.PublicSuffixes.java
/** * Converts SURT-ordered list of public prefixes into a Java regex which * matches the public-portion "plus one" segment, giving the domain on which * cookies can be set or other policy grouping should occur. Also adds to * regex a fallback matcher that for any new/unknown TLDs assumes the * second-level domain is assignable. (Eg: 'zzz,example,'). * // w ww. j a v a2 s .c om * @param list * @return */ private static String surtPrefixRegexFromSurtList(List<String> list) { StringBuilder regex = new StringBuilder(); regex.append("(?ix)^\n"); TreeSet<String> prefixes = new TreeSet<String>(Collections.reverseOrder()); prefixes.addAll(list); prefixes.add("*,"); // for new/unknown TLDs buildRegex("", regex, prefixes); regex.append("\n([\\-\\w]+,)"); String rstring = regex.toString(); // convert glob-stars to word-char-runs rstring = rstring.replaceAll("\\*", "[\\\\-\\\\w]+"); return rstring; }