Example usage for java.util NavigableSet descendingSet

List of usage examples for java.util NavigableSet descendingSet

Introduction

In this page you can find the example usage for java.util NavigableSet descendingSet.

Prototype

NavigableSet<E> descendingSet();

Source Link

Document

Returns a reverse order view of the elements contained in this set.

Usage

From source file:Main.java

public static void main(String[] args) {
    NavigableSet<Integer> ns = new TreeSet<>();
    ns.add(0);//from   ww w. j  a v  a  2  s. c o  m
    ns.add(1);
    ns.add(2);
    ns.add(3);
    ns.add(4);
    ns.add(5);
    ns.add(6);

    // Get a reverse view of the navigable set
    NavigableSet<Integer> reverseNs = ns.descendingSet();

    // Print the normal and reverse views
    System.out.println("Normal order: " + ns);
    System.out.println("Reverse order: " + reverseNs);

    NavigableSet<Integer> threeOrMore = ns.tailSet(3, true);
    System.out.println("3 or  more:  " + threeOrMore);
    System.out.println("lower(3): " + ns.lower(3));
    System.out.println("floor(3): " + ns.floor(3));
    System.out.println("higher(3): " + ns.higher(3));
    System.out.println("ceiling(3): " + ns.ceiling(3));

    System.out.println("pollFirst(): " + ns.pollFirst());
    System.out.println("Navigable Set:  " + ns);

    System.out.println("pollLast(): " + ns.pollLast());
    System.out.println("Navigable Set:  " + ns);

    System.out.println("pollFirst(): " + ns.pollFirst());
    System.out.println("Navigable Set:  " + ns);

    System.out.println("pollFirst(): " + ns.pollFirst());
    System.out.println("Navigable Set:  " + ns);

    System.out.println("pollFirst(): " + ns.pollFirst());
    System.out.println("Navigable Set:  " + ns);

    System.out.println("pollFirst(): " + ns.pollFirst());
    System.out.println("pollLast(): " + ns.pollLast());
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

public void testDescendingSet() {
    NavigableSet<E> set = createNavigableSet();
    set.add(getKeys()[0]);//from  ww  w.j  a  va 2  s.  co  m

    NavigableSet<E> descendingSet = set.descendingSet();
    _assertEquals(descendingSet, descendingSet);
    _assertEquals(set.descendingSet(), descendingSet);

    set.add(getKeys()[1]);
    set.add(getKeys()[2]);
    _assertEquals(reverseCollection(set), descendingSet);
    _assertEquals(set, descendingSet.descendingSet());

    set.remove(getKeys()[1]);
    _assertEquals(reverseCollection(set), descendingSet);

    descendingSet.add(getKeys()[0]);
    _assertEquals(reverseCollection(set), descendingSet);

    descendingSet.remove(getKeys()[1]);
    _assertEquals(reverseCollection(set), descendingSet);

    descendingSet.clear();
    assertEquals(0, descendingSet.size());
    _assertEquals(set, descendingSet);
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

public void testDescendingKeySet() {
    K[] keys = getSortedKeys();//from   w w  w. jav a 2s . co m
    V[] values = getSortedValues();
    NavigableMap<K, V> map = createNavigableMap();
    map.put(keys[0], values[0]);

    NavigableSet<K> keySet = map.descendingKeySet();
    _assertEquals(keySet, map.descendingKeySet());

    map.put(keys[1], values[1]);
    map.put(keys[2], values[2]);
    _assertEquals(reverseCollection(keySet), keySet);
    _assertEquals(map.keySet(), keySet.descendingSet());
}

From source file:org.apache.hadoop.hbase.master.LoadBalancer.java

/**
 * Find the block locations for all of the files for the specified region.
 *
 * Returns an ordered list of hosts that are hosting the blocks for this
 * region.  The weight of each host is the sum of the block lengths of all
 * files on that host, so the first host in the list is the server which
 * holds the most bytes of the given region's HFiles.
 *
 * TODO: Make this work.  Need to figure out how to match hadoop's hostnames
 *       given for block locations with our HServerAddress.
 * TODO: Use the right directory for the region
 * TODO: Use getFileBlockLocations on the files not the directory
 *
 * @param fs the filesystem//from  w  w  w  .  j  a  v a  2 s . c o m
 * @param region region
 * @return ordered list of hosts holding blocks of the specified region
 * @throws IOException if any filesystem errors
 */
@SuppressWarnings("unused")
private List<String> getTopBlockLocations(FileSystem fs, HRegionInfo region) throws IOException {
    String encodedName = region.getEncodedName();
    Path path = new Path("/hbase/table/" + encodedName);
    FileStatus status = fs.getFileStatus(path);
    BlockLocation[] blockLocations = fs.getFileBlockLocations(status, 0, status.getLen());
    Map<HostAndWeight, HostAndWeight> hostWeights = new TreeMap<HostAndWeight, HostAndWeight>(
            new HostAndWeight.HostComparator());
    for (BlockLocation bl : blockLocations) {
        String[] hosts = bl.getHosts();
        long len = bl.getLength();
        for (String host : hosts) {
            HostAndWeight haw = hostWeights.get(host);
            if (haw == null) {
                haw = new HostAndWeight(host, len);
                hostWeights.put(haw, haw);
            } else {
                haw.addWeight(len);
            }
        }
    }
    NavigableSet<HostAndWeight> orderedHosts = new TreeSet<HostAndWeight>(new HostAndWeight.WeightComparator());
    orderedHosts.addAll(hostWeights.values());
    List<String> topHosts = new ArrayList<String>(orderedHosts.size());
    for (HostAndWeight haw : orderedHosts.descendingSet()) {
        topHosts.add(haw.getHost());
    }
    return topHosts;
}

From source file:org.dllearner.algorithms.probabilistic.structure.unife.leap.AbstractLEAP.java

private <T extends OWLAxiom> List<T> convertIntoAxioms(Class<T> type, OWLOntologyManager manager,
        NavigableSet<? extends EvaluatedDescription> evaluatedDescriptions) {
    List<T> axioms = new LinkedList<>();
    OWLDataFactory factory = manager.getOWLDataFactory();
    for (EvaluatedDescription description : evaluatedDescriptions.descendingSet()) {
        OWLClassExpression ce = (OWLClassExpression) description.getDescription();
        ce = OWLClassExpressionSimplifierVisitorImpl.getOWLClassExpression(ce, manager);
        OWLAnnotation annotation = factory.getOWLAnnotation(BundleUtilities.PROBABILISTIC_ANNOTATION_PROPERTY,
                factory.getOWLLiteral(description.getAccuracy()));
        //            if (classAxiomType.equalsIgnoreCase("subClassOf") || classAxiomType.equalsIgnoreCase("both")) {
        T axiom;/*from   ww w  .j  av a  2  s  .c om*/
        if (type == OWLEquivalentClassesAxiom.class) {
            axiom = (T) factory.getOWLEquivalentClassesAxiom(ce, dummyClass, Collections.singleton(annotation));

        } else if (type == OWLSubClassOfAxiom.class) {
            axiom = (T) factory.getOWLSubClassOfAxiom(ce, dummyClass, Collections.singleton(annotation));
        } else {
            throw new RuntimeException(
                    "convertIntoAxioms only works with " + "equivalent and subclassOf axioms");
        }
        axioms.add(axiom);
    }
    return axioms;
}