Example usage for java.util NavigableSet tailSet

List of usage examples for java.util NavigableSet tailSet

Introduction

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

Prototype

NavigableSet<E> tailSet(E fromElement, boolean inclusive);

Source Link

Document

Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement .

Usage

From source file:Main.java

public static void main(String[] args) {
    NavigableSet<Integer> ns = new TreeSet<>();
    ns.add(0);/* w w  w  . j  a va2 s .  com*/
    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:net.sf.jasperreports.engine.export.tabulator.Tabulator.java

protected SpanInfo<Row> getRowCellSpan(NavigableSet<Row> rows, Column column, Row row, Cell cell) {
    int span = 1;
    Row lastRow = row;//  www . ja va2 s.  c  om
    for (Row tailRow : rows.tailSet(row, false)) {
        Cell tailCell = tailRow.getCell(column);
        if (tailCell == null || !cell.accept(spanCheck, tailCell)) {
            break;
        }
        ++span;
        lastRow = tailRow;
    }
    return new SpanInfo<Row>(span, lastRow);
}

From source file:net.sf.jasperreports.engine.export.tabulator.Tabulator.java

protected SpanInfo<Column> getColumnCellSpan(NavigableSet<Column> columns, Column column, Row row, Cell cell) {
    int span = 1;
    Column lastCol = column;/*from www .j  av a  2  s. co m*/
    for (Column tailCol : columns.tailSet(column, false)) {
        Cell tailCell = row.getCell(tailCol);
        if (tailCell == null || !cell.accept(spanCheck, tailCell)) {
            break;
        }
        ++span;
        lastCol = tailCol;
    }
    return new SpanInfo<Column>(span, lastCol);
}

From source file:com.google.cloud.dns.testing.LocalDnsHelper.java

/**
 * Lists changes. Next page token is the ID of the last change listed.
 *//*from  ww  w  .j a  v  a  2 s  . com*/
@VisibleForTesting
Response listChanges(String projectId, String zoneName, String query) {
    Map<String, Object> options = OptionParsers.parseListChangesOptions(query);
    Response response = checkListOptions(options);
    if (response != null) {
        return response;
    }
    ZoneContainer zoneContainer = findZone(projectId, zoneName);
    if (zoneContainer == null) {
        return Error.NOT_FOUND.response(
                String.format("The 'parameters.managedZone' resource named '%s' does not exist", zoneName));
    }
    // take a sorted snapshot of the current change list
    NavigableMap<Integer, Change> changes = new TreeMap<>();
    for (Change c : zoneContainer.changes()) {
        if (c.getId() != null) {
            changes.put(Integer.valueOf(c.getId()), c);
        }
    }
    String[] fields = (String[]) options.get("fields");
    String sortOrder = (String) options.get("sortOrder");
    String pageToken = (String) options.get("pageToken");
    Integer maxResults = options.get("maxResults") == null ? null
            : Integer.valueOf((String) options.get("maxResults"));
    // as the only supported field is change sequence, we are not reading sortBy
    NavigableSet<Integer> keys;
    if ("descending".equals(sortOrder)) {
        keys = changes.descendingKeySet();
    } else {
        keys = changes.navigableKeySet();
    }
    Integer from = null;
    try {
        from = Integer.valueOf(pageToken);
    } catch (NumberFormatException ex) {
        // ignore page token
    }
    keys = from != null ? keys.tailSet(from, false) : keys;
    NavigableMap<Integer, Change> fragment = from != null && changes.containsKey(from)
            ? changes.tailMap(from, false)
            : changes;
    boolean sizeReached = false;
    boolean hasMorePages = false;
    LinkedList<String> serializedResults = new LinkedList<>();
    String lastChangeId = null;
    for (Integer key : keys) {
        Change change = fragment.get(key);
        if (sizeReached) {
            // we do not add this, just note that there would be more and there should be a token
            hasMorePages = true;
            break;
        } else {
            lastChangeId = change.getId();
            try {
                serializedResults.addLast(jsonFactory.toString(OptionParsers.extractFields(change, fields)));
            } catch (IOException e) {
                return Error.INTERNAL_ERROR.response(
                        String.format("Error when serializing change %s in managed zone %s in project %s",
                                lastChangeId, zoneName, projectId));
            }
        }
        sizeReached = maxResults != null && maxResults.equals(serializedResults.size());
    }
    boolean includePageToken = hasMorePages
            && (fields == null || Arrays.asList(fields).contains("nextPageToken"));
    return toListResponse(serializedResults, "changes", lastChangeId, includePageToken);
}