Example usage for java.util NavigableSet ceiling

List of usage examples for java.util NavigableSet ceiling

Introduction

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

Prototype

E ceiling(E e);

Source Link

Document

Returns the least element in this set greater than or equal to the given element, or null if there is no such element.

Usage

From source file:Main.java

public static void main(String[] args) {
    String[] cities = { "A", "B", "C", "D", "E", "F" };
    NavigableSet<String> citiesSet = new TreeSet<String>();
    for (String city : cities)
        citiesSet.add(city);//from   www . j  a v  a 2  s  .  co  m
    System.out.println(citiesSet.ceiling("A"));
}

From source file:Main.java

public static void main(String[] args) {
    NavigableSet<Integer> ns = new TreeSet<>();
    ns.add(0);/*from   w  w w .jav  a 2 s  . c  om*/
    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.DimensionEntries.java

public DimensionRange<T> getRange(int start, int end) {
    if (start > end) {
        throw new IllegalArgumentException(start + " > " + end);
    }//from w  w  w  .j  av  a2s.co m
    if (start <= DimensionEntry.MINUS_INF) {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_START_OUT_OF_RANGE, new Object[] { start });
    }
    if (end >= DimensionEntry.PLUS_INF) {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_END_OUT_OF_RANGE, new Object[] { end });
    }

    T startKey = control.entryKey(start);
    T floor = entries.floor(startKey);
    assert floor != null;

    NavigableSet<T> tailSet = entries.tailSet(floor, true);

    T endKey = control.entryKey(end);
    T ceiling = tailSet.ceiling(endKey);

    NavigableSet<T> rangeSet;
    if (ceiling == null) {
        rangeSet = tailSet;
    } else {
        rangeSet = tailSet.headSet(ceiling, false);
    }

    return new DimensionRange<T>(start, end, floor, ceiling, rangeSet);
}

From source file:ch.algotrader.service.CalendarServiceImpl.java

@Override
public Date getNextOpenTime(final long exchangeId, final Date dateTime) {

    Validate.notNull(dateTime, "DateTime is null");

    Exchange exchange = this.exchangeDao.get(exchangeId);
    Validate.notNull(exchange, "exchange not found");

    Date date = DateUtils.truncate(dateTime, Calendar.DATE);
    Date openTime;/*from   w w w  .  j a  va  2  s  .c  om*/
    NavigableSet<Date> openTimes = new TreeSet<>();
    while ((openTime = openTimes.ceiling(dateTime)) == null) {
        openTimes.addAll(getOpenTimes(exchange, date));
        date = DateUtils.addDays(date, 1);
    }
    return openTime;

}

From source file:ch.algotrader.service.CalendarServiceImpl.java

@Override
public Date getNextCloseTime(final long exchangeId, final Date dateTime) {

    Validate.notNull(dateTime, "DateTime is null");

    Exchange exchange = this.exchangeDao.get(exchangeId);
    Validate.notNull(exchange, "exchange not found");

    Date date = DateUtils.addDays(DateUtils.truncate(dateTime, Calendar.DATE), -1);
    Date closeTime;//  w  ww  .  j  a v  a  2s .c  om
    NavigableSet<Date> closeTimes = new TreeSet<>();
    while ((closeTime = closeTimes.ceiling(dateTime)) == null) {
        closeTimes.addAll(getCloseTimes(exchange, date));
        date = DateUtils.addDays(date, 1);
    }
    return closeTime;

}

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

public void testCeiling() {
    NavigableSet<E> set = createNavigableSet();

    set.add(getKeys()[0]);/*from www. java2  s . c o m*/
    assertEquals(getKeys()[0], set.ceiling(getKeys()[0]));
    assertEquals(getKeys()[0], set.ceiling(getLessThanMinimumKey()));
    assertEquals(set.toArray()[0], set.ceiling(getLessThanMinimumKey()));

    set.add(getKeys()[1]);
    assertEquals(getKeys()[0], set.ceiling(getLessThanMinimumKey()));
    assertEquals(getKeys()[0], set.ceiling(getKeys()[0]));
    assertEquals(getKeys()[1], set.ceiling(getKeys()[1]));
    assertEquals(null, set.ceiling(getGreaterThanMaximumKey()));
}