Example usage for java.util TreeSet descendingSet

List of usage examples for java.util TreeSet descendingSet

Introduction

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

Prototype

public NavigableSet<E> descendingSet() 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);/* w  w  w  .  j  ava  2s .c  om*/
    treeadd.add(13);
    treeadd.add(17);
    treeadd.add(2);

    // creating reverse set
    TreeSet<Integer> treereverse = (TreeSet<Integer>) treeadd.descendingSet();

    // create descending set
    Iterator<Integer> iterator = treereverse.iterator();

    //Tree set data in reverse order
    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:br.bireme.ngrams.NGrams.java

public static Set<String> searchJson(final NGIndex index, final NGSchema schema, final String text)
        throws IOException, ParseException {
    if (index == null) {
        throw new NullPointerException("index");
    }//from  w w w  .j av a2 s .  co  m
    if (schema == null) {
        throw new NullPointerException("schema");
    }
    if (text == null) {
        throw new NullPointerException("text");
    }
    final IndexSearcher searcher = index.getIndexSearcher();
    final NGAnalyzer analyzer = (NGAnalyzer) index.getAnalyzer();
    final Parameters parameters = schema.getParameters();
    final NGramDistance ngDistance = new NGramDistance(analyzer.getNgramSize());
    final Set<String> id_id = new HashSet<>();
    final TreeSet<Result> results = new TreeSet<>();
    final String ttext = text.replace(':', ' ').trim();

    searchRaw(parameters, searcher, analyzer, ngDistance, ttext, true, id_id, results);
    searcher.getIndexReader().close();

    return results2json(parameters, results.descendingSet());
}

From source file:org.apilytic.currency.service.impl.DefaultTwitterService.java

/** {@inheritDoc} */
@Override/*w  w  w.j  av  a2  s .c om*/
public SortedSet<TwitterMessage> getTwitterMessages(Long tweetId, SortOrder sortOrder) {

    final TreeSet<TwitterMessage> tweets = new TreeSet<TwitterMessage>();

    if (tweetId != null) {

        final Map<Long, TwitterMessage> twitterMessagesAsMap = twitterMessages.asMap();

        for (Long id : twitterMessagesAsMap.keySet()) {
            if (id.compareTo(tweetId) > 0) {
                tweets.add(twitterMessages.getIfPresent(id));
            }
        }

    } else {
        tweets.addAll(this.twitterMessages.asMap().values());
    }

    if (SortOrder.DESCENDING.equals(sortOrder)) {
        return tweets.descendingSet();
    }

    return tweets;
}

From source file:br.bireme.ngrams.NGrams.java

private static Set<String> results2pipe(final Parameters parameters, final Set<Result> results) {
    assert parameters != null;
    assert results != null;

    final TreeSet<String> ret = new TreeSet<>();

    for (Result result : results) {
        final String[] param = result.param;
        final Document doc = result.doc;
        final String itext = (String) doc.get(parameters.indexed.name + "~notnormalized").replace('|', '!');
        final String stext = param[parameters.indexed.pos].trim().replace('|', '!');
        final String id1 = param[parameters.id.pos];
        final String id2 = (String) doc.get("id~notnormalized");
        final String src1 = param[parameters.db.pos];
        final String src2 = (String) doc.get("database");
        final String str = result.score + "|" + result.similarity + "|" + id1 + "|" + id2 + "|" + stext + "|"
                + itext + "|" + src1 + "|" + src2;
        //System.out.println("! " + result.compare);
        ret.add(str);/*from  w w  w.  ja va 2  s  .  c  om*/
    }
    return ret.descendingSet();
}

From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePattern.java

/**
 * Recursive method called in order to create the normalized tree pattern.
 * //from   w ww  . j a  v  a2 s.  c  om
 * @param node a tree pattern node, we will order its children
 * @param counter the value of the counter that we are using for renumbering the tree pattern nodes
 * @return the counter that we are using for renumbering the tree pattern nodes
 */
private int recGetNormalizedTreePattern(NavigationTreePatternNode node, int counter) {
    if (node.getEdges().isEmpty())
        return counter;

    TreeSet<NavigationTreePatternNode> sortedSetChildrenNodes = new TreeSet<NavigationTreePatternNode>();
    int newCounter = counter + node.getEdges().size();
    for (NavigationTreePatternEdge edge : node.getEdges()) {
        newCounter = recGetNormalizedTreePattern(edge.n2, newCounter);
        sortedSetChildrenNodes.add(edge.n2);
    }

    node.cleanEdges();
    for (NavigationTreePatternNode child : sortedSetChildrenNodes.descendingSet()) {

        child.setNodeCode(counter);
        counter++;
        child.getParentEdge().n1.addEdge(child.getParentEdge());
    }

    return newCounter;
}

From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePattern.java

/**
 * Gets the normal form of a tree pattern.
 * @return the normal tree pattern/*  w  ww .  j  a  v a2s .  c om*/
 */
public NavigationTreePattern getNormalizedTreePattern() {
    NavigationTreePattern normalizedTreePattern = deepCopy();

    int counter = 1;
    TreeSet<NavigationTreePatternNode> sortedSetChildrenNodes = new TreeSet<NavigationTreePatternNode>();
    int newCounter = counter + normalizedTreePattern.root.getEdges().size();
    for (NavigationTreePatternEdge edge : normalizedTreePattern.root.getEdges()) {
        newCounter = recGetNormalizedTreePattern(edge.n2, newCounter);
        sortedSetChildrenNodes.add(edge.n2);
    }

    normalizedTreePattern.root.cleanEdges();
    for (NavigationTreePatternNode node : sortedSetChildrenNodes.descendingSet()) {
        node.setNodeCode(counter);
        counter++;
        node.getParentEdge().n1.addEdge(node.getParentEdge());
    }

    return normalizedTreePattern;
}

From source file:br.bireme.ngrams.NGrams.java

private static Set<String> results2pipeFull(final Parameters parameters, final Set<Result> results) {
    assert parameters != null;
    assert results != null;

    final TreeSet<String> ret = new TreeSet<>();
    final StringBuilder builder = new StringBuilder();
    final Collection<br.bireme.ngrams.Field> flds = parameters.sfields.values();

    for (Result result : results) {
        final String[] param = result.param;
        final Document doc = result.doc;

        builder.setLength(0);// ww w  . j  a  v a  2  s.  c  o  m
        builder.append(result.score).append("|").append(result.similarity);
        for (int idx = 0; idx < flds.size(); idx++) {
            String fld = param[idx];
            fld = (fld == null) ? "" : fld.trim().replace('|', '!');
            builder.append("|").append(fld);
            builder.append("|").append(Tools.limitSize(Tools.normalize(fld, OCC_SEPARATOR), MAX_NG_TEXT_SIZE));
        }
        for (br.bireme.ngrams.Field field : flds) {
            final String fldN = doc.get(field.name);
            final String fld = doc.get(field.name + NGrams.NOT_NORMALIZED_FLD);

            builder.append("|").append((fld == null) ? "" : fld.replace('|', '!'));
            builder.append("|").append((fldN == null) ? "" : fldN.replace('|', '!'));
        }
        ret.add(builder.toString());
    }
    return ret.descendingSet();
}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortIntField() throws Exception {
    final PrimitiveIterator.OfInt intIterator = new Random().ints().iterator();
    final TreeSet<Integer> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (int i = 0; i < NUM_DOCS; i++) {
        int item = 0;
        while (item == 0 || orderedItems.contains(item)) {
            item = intIterator.nextInt();
        }// www .  ja  v  a  2 s.co  m
        orderedItems.add(item);

        final Data data = new Data();
        data.setIntField(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("intField", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getIntField(), orderedItems, Integer.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("intField", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getIntField(), orderedItems.descendingSet(),
            Integer.class);
}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortLongField() throws Exception {
    final PrimitiveIterator.OfLong longIterator = new Random().longs().iterator();
    final TreeSet<Long> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (int i = 0; i < NUM_DOCS; i++) {
        long item = 0L;
        while (item == 0L || orderedItems.contains(item)) {
            item = longIterator.nextLong();
        }//  w  w w .jav  a2 s  .  c  o m
        orderedItems.add(item);

        final Data data = new Data();
        data.setLongField(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("longField", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getLongField(), orderedItems, Long.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("longField", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getLongField(), orderedItems.descendingSet(), Long.class);
}

From source file:com.b2international.index.SortIndexTest.java

@Test
public void sortStringField() throws Exception {
    final TreeSet<String> orderedItems = newTreeSet();
    final Map<String, Data> documents = newHashMap();

    for (int i = 0; i < NUM_DOCS; i++) {
        String item = null;/*from  w  w  w.j  av  a2s . co  m*/
        while (item == null || orderedItems.contains(item)) {
            item = RandomStringUtils.randomAlphabetic(10);
        }
        orderedItems.add(item);

        final Data data = new Data();
        data.setField1(item);
        documents.put(Integer.toString(i), data);
    }

    indexDocuments(documents);

    final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("field1", Order.ASC)).build();

    checkDocumentOrder(ascendingQuery, data -> data.getField1(), orderedItems, String.class);

    final Query<Data> descendingQuery = Query.select(Data.class).where(Expressions.matchAll()).limit(NUM_DOCS)
            .sortBy(SortBy.field("field1", Order.DESC)).build();

    checkDocumentOrder(descendingQuery, data -> data.getField1(), orderedItems.descendingSet(), String.class);
}