List of usage examples for java.util TreeSet tailSet
public SortedSet<E> tailSet(E fromElement)
From source file:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; TreeSet set = new TreeSet(Arrays.asList(elements)); System.out.println(set.tailSet("C")); System.out.println(set.headSet("C")); System.out.println(set.headSet("C\0")); System.out.println(set.tailSet("C\0")); System.out.println(set.subSet("C", "F\0")); System.out.println(set.subSet("C", "C\0")); System.out.println(set.subSet("C", "C")); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; TreeSet set = new TreeSet(Arrays.asList(elements)); System.out.println(set.headSet("D")); System.out.println(set.tailSet("")); }
From source file:Main.java
public static void main(String args[]) throws Exception { String elements[] = { "java2s.com", "C", "D", "G", "F" }; TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements)); System.out.println(set.headSet("D")); System.out.println(set.tailSet("")); }
From source file:Main.java
public static void main(String args[]) throws Exception { String elements[] = { "A", "C", "D", "G", "F" }; TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements)); System.out.println(set.headSet("D")); System.out.println(set.tailSet("")); }
From source file:Main.java
public static void main(String[] args) { TreeSet<String> tSet = new TreeSet<String>(); tSet.add("1"); tSet.add("2"); tSet.add("3"); tSet.add("5"); tSet.add("4"); SortedSet sortedSet = tSet.tailSet("2"); System.out.println("Tail Set Contains : " + sortedSet); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);// w w w . ja v a 2 s. co m treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treetailset = (TreeSet<Integer>) treeadd.tailSet(4); Iterator<Integer> iterator = treetailset.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:TreeSetDemo.java
public static void main(String[] argv) { //+/*from ww w . j ava 2s .com*/ /* * A TreeSet keeps objects in sorted order. We use a Comparator * published by String for case-insensitive sorting order. */ TreeSet tm = new TreeSet(String.CASE_INSENSITIVE_ORDER); tm.add("Gosling"); tm.add("da Vinci"); tm.add("van Gogh"); tm.add("Java To Go"); tm.add("Vanguard"); tm.add("Darwin"); tm.add("Darwin"); // TreeSet is Set, ignores duplicates. // Since it is sorted we can ask for various subsets System.out.println("Lowest (alphabetically) is " + tm.first()); // Print how many elements are greater than "k" System.out.println(tm.tailSet("k").toArray().length + " elements higher than \"k\""); // Print the whole list in sorted order System.out.println("Sorted list:"); java.util.Iterator t = tm.iterator(); while (t.hasNext()) System.out.println(t.next()); //- }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Sets the specified field of the given callendar to the next scheduled * value. Returns whether the new value has been set and is valid. * /*from w w w . java2s . c o m*/ * @param cal * Calendar to adjust. * @param field * Field to adjust. * @return Returns whether the new value has been set and is valid. * @throws ImplementationException * Almost any error. */ private boolean setToNextScheduledValue(final GregorianCalendar cal, final int field) throws ImplementationExceptionResponse { int next; TreeSet<Integer> vals = getValues(field); if (vals.isEmpty()) { next = cal.get(field) + 1; } else { try { // get next scheduled value which is bigger than current int incrValue = cal.get(field) + 1; next = vals.tailSet(new Integer(incrValue)).first().intValue(); } catch (NoSuchElementException nse) { // there is no bigger scheduled value return false; } } if (next > cal.getActualMaximum(field) || next < cal.getActualMinimum(field)) { return false; } // all is well, set it to next cal.set(field, next); return true; }
From source file:org.hyperic.hq.measurement.server.session.AvailabilityManagerImpl.java
private AvailabilityDataRLE findAvailAfter(DataPoint state, Map<Integer, TreeSet<AvailabilityDataRLE>> currAvails) { final Integer mId = state.getMeasurementId(); final TreeSet<AvailabilityDataRLE> rles = currAvails.get(mId); final long start = state.getTimestamp(); final AvailabilityDataRLE tmp = new AvailabilityDataRLE(); // tailSet is inclusive so we need to add 1 to start tmp.setStartime(start + 1);//from w w w .jav a 2 s. c o m final SortedSet<AvailabilityDataRLE> set = rles.tailSet(tmp); if (set.size() == 0) { return null; } return (AvailabilityDataRLE) set.first(); }