Java Code Examples for java.util.TreeSet#subSet()

The following examples show how to use java.util.TreeSet#subSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpectMaxExecutionTimeAnnotationFormatter.java    From quickperf with Apache License 2.0 6 votes vote down vote up
private SortedSet<TimeUnit> findUnitsToDisplay(ExpectMaxExecutionTime annotation) {

        TimeUnit minUnitToDisplay = findMinUnitToDisplay(annotation);
        TimeUnit maxUnitToDisplay = findMaxUnitToDisplay(annotation);

        TreeSet<TimeUnit> timeUnits = new TreeSet<>();
        timeUnits.add(TimeUnit.HOURS);
        timeUnits.add(TimeUnit.MINUTES);
        timeUnits.add(TimeUnit.SECONDS);
        timeUnits.add(TimeUnit.MILLISECONDS);
        timeUnits.add(TimeUnit.MICROSECONDS);
        timeUnits.add(TimeUnit.NANOSECONDS);

        return timeUnits.subSet( minUnitToDisplay, true
                , maxUnitToDisplay, true);
    }
 
Example 2
Source File: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void testSubSetContents2() {
    TreeSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
 
Example 3
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new set of given size containing consecutive
 * Integers 0 ... n - 1.
 */
private NavigableSet<Integer> populatedSet(int n) {
    TreeSet<Integer> q = new TreeSet<>();
    assertTrue(q.isEmpty());

    for (int i = n - 1; i >= 0; i -= 2)
        assertTrue(q.add(new Integer(i)));
    for (int i = (n & 1); i < n; i += 2)
        assertTrue(q.add(new Integer(i)));
    assertTrue(q.add(new Integer(-n)));
    assertTrue(q.add(new Integer(n)));
    NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
    assertFalse(s.isEmpty());
    assertEquals(n, s.size());
    return s;
}
 
Example 4
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testSubSetSerialization() {
    String s = "aced0005737200116a6176612e7574696c2e54726565536574dd98509395ed87"
            + "5b03000078707372002a6a6176612e6c616e672e537472696e672443617365496"
            + "e73656e736974697665436f6d70617261746f7277035c7d5c50e5ce0200007870"
            + "770400000002740001617400016278";
    TreeSet<String> set = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    final SortedSet<String> subSet = set.subSet("a", "c");
    new SerializationTester<SortedSet<String>>(subSet, s) {
        @Override protected void verify(SortedSet<String> deserialized) {
            assertBounded(deserialized, deserialized == subSet);
        }
    }.test();
}
 
Example 5
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testNavigableSubSetSerialization() {
    String s = "aced0005737200116a6176612e7574696c2e54726565536574dd98509395ed87"
            + "5b03000078707372002a6a6176612e6c616e672e537472696e672443617365496"
            + "e73656e736974697665436f6d70617261746f7277035c7d5c50e5ce0200007870"
            + "770400000002740001627400016378";
    TreeSet<String> set = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    final SortedSet<String> subSet = set.subSet("a", false, "c", true);
    new SerializationTester<SortedSet<String>>(subSet, s) {
        @Override protected void verify(SortedSet<String> deserialized) {
            assertBounded(deserialized, deserialized == subSet);
        }
    }.test();
}
 
Example 6
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testSubSetContents2() {
    TreeSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
 
Example 7
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new set of given size containing consecutive
 * Integers 0 ... n.
 */
private NavigableSet<Integer> populatedSet(int n) {
    TreeSet<Integer> q = new TreeSet<Integer>();
    assertTrue(q.isEmpty());

    for (int i = n - 1; i >= 0; i -= 2)
        assertTrue(q.add(new Integer(i)));
    for (int i = (n & 1); i < n; i += 2)
        assertTrue(q.add(new Integer(i)));
    assertTrue(q.add(new Integer(-n)));
    assertTrue(q.add(new Integer(n)));
    NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
    assertFalse(s.isEmpty());
    assertEquals(n, s.size());
    return s;
}
 
Example 8
Source File: HBaseSalter.java    From SpyGlass with Apache License 2.0 6 votes vote down vote up
private static byte[][] getAllKeysWithStartStop(byte[] originalKey, String prefixList, byte startPrefix, byte stopPrefix) {
    LOG.debug("".format("getAllKeysWithStartStop: OKEY (%s) PLIST (%s) PSRT (%s) PSTP (%s)",
            Bytes.toString(originalKey), prefixList, startPrefix, stopPrefix));

    char[] prefixArray = prefixList.toCharArray();
 TreeSet<Byte> prefixSet = new TreeSet<Byte>();
 
 for( char c : prefixArray ) {
  prefixSet.add((byte)c);
 }
 
 SortedSet<Byte> subSet = prefixSet.subSet(startPrefix, true, stopPrefix, true);

    LOG.debug("".format("Prefix subset (%s)", subSet));
 
 return getAllKeys(originalKey, subSet.toArray(new Byte[]{}));
}
 
Example 9
Source File: SimpleSubsetting.java    From Java-for-Data-Science with MIT License 5 votes vote down vote up
public static void treeSubSetMethod(){

		//sub set is not populating - not sure why
		//http://www.tutorialspoint.com/java/util/treeset_subset.htm

		Integer[] nums = {12,46,52,34,87,123,14,44};
		TreeSet <Integer> fullNumsList = new TreeSet<Integer>(new ArrayList<>(Arrays.asList(nums)));
		TreeSet <Integer> partNumsList = new TreeSet<Integer>();
		out.println("Original List: " + fullNumsList.toString());
		partNumsList = (TreeSet<Integer>) fullNumsList.subSet(1,3); 
		out.println("SubSet of List: " + partNumsList.toString());
		out.println(partNumsList.size());


	}
 
Example 10
Source File: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * subSet returns set with keys in requested range
 */
public void testSubSetContents() {
    TreeSet set = set5();
    SortedSet sm = set.subSet(two, four);
    assertEquals(two, sm.first());
    assertEquals(three, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.first());
    assertEquals(three, sm.last());
    assertTrue(sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, set.size());
}
 
Example 11
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new set of first 5 ints.
 */
private NavigableSet set5() {
    TreeSet q = new TreeSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}
 
Example 12
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * subSet returns set with keys in requested range
 */
public void testSubSetContents() {
    TreeSet set = set5();
    SortedSet sm = set.subSet(two, four);
    assertEquals(two, sm.first());
    assertEquals(three, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.first());
    assertEquals(three, sm.last());
    assertTrue(sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, set.size());
}
 
Example 13
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new set of first 5 ints.
 */
private NavigableSet set5() {
    TreeSet q = new TreeSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}
 
Example 14
Source File: DeclarationGenerator.java    From clutz with MIT License 4 votes vote down vote up
private Set<String> getSubNamespace(TreeSet<String> symbols, String namespace) {
  return symbols.subSet(namespace + ".", namespace + ".\uFFFF");
}