Example usage for java.util SortedSet last

List of usage examples for java.util SortedSet last

Introduction

In this page you can find the example usage for java.util SortedSet last.

Prototype

E last();

Source Link

Document

Returns the last (highest) element currently in this set.

Usage

From source file:org.apache.hadoop.hbase.zookeeper.lock.HReadLockImpl.java

/**
 * {@inheritDoc}/*from w w w .j a va 2  s.c  o m*/
 */
@Override
protected String getLockPath(String createdZNode, List<String> children)
        throws IOException, InterruptedException {
    TreeSet<String> writeChildren = new TreeSet<String>(new ZNodeComparator(zkWrapper.getIdentifier()));
    for (String child : children) {
        if (isWriteChild(child)) {
            writeChildren.add(child);
        }
    }
    if (writeChildren.isEmpty()) {
        return null;
    }
    SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode);
    if (lowerChildren.isEmpty()) {
        return null;
    }
    String pathToWatch = lowerChildren.last();
    String nodeHoldingLock = lowerChildren.first();
    try {
        handleLockMetadata(nodeHoldingLock);
    } catch (IOException e) {
        LOG.warn("Error processing lock metadata in " + nodeHoldingLock, e);
    }
    return pathToWatch;
}

From source file:com.projity.contrib.calendar.ContribIntervals.java

public boolean add(Object o) {
    DateSpan toAdd = (DateSpan) o;/*w ww .j a v a2  s  .  c o  m*/
    SortedSet set = headSet(o);
    if (set.size() > 0) {
        DateSpan interval = (DateSpan) set.last();
        if (interval.getEnd() >= toAdd.getStart())
            toAdd = mergeIntervals(toAdd, interval);
    }

    set = tailSet(o);
    if (set.size() > 0) {
        DateSpan interval = (DateSpan) set.first();
        if (toAdd.getEnd() >= interval.getStart())
            toAdd = mergeIntervals(toAdd, interval);
    }
    return super.add(toAdd);
}

From source file:com.liveramp.hank.storage.cueball.CueballPartitionUpdater.java

@Override
protected Integer detectCurrentVersionNumber() throws IOException {
    SortedSet<CueballFilePath> localBases = Cueball.getBases(localPartitionRoot);
    if (localBases.size() > 0) {
        return localBases.last().getVersion();
    } else {/*from  www. j  a va  2  s.  com*/
        return null;
    }
}

From source file:org.powertac.common.OrderbookTests.java

@Test
public void testGetBids() {
    Orderbook ob = new Orderbook(timeslot, 20.1, now);
    ob.addBid(new OrderbookOrder(3.3, -20.0)).addBid(new OrderbookOrder(2.1, -18.2))
            .addBid(new OrderbookOrder(5.6, -19.4)).addBid(new OrderbookOrder(6.2, null));
    SortedSet<OrderbookOrder> bids = ob.getBids();
    assertEquals("correct number", 4, bids.size());
    assertEquals("correct first item price", null, bids.first().getLimitPrice());
    assertEquals("correct last item price", -18.2, bids.last().getLimitPrice(), 1e-6);
    SortedSet<OrderbookOrder> asks = ob.getAsks();
    assertEquals("no asks", 0, asks.size());
}

From source file:org.eclipse.gyrex.jobs.internal.storage.CloudPreferncesJobHistoryStorage.java

private void shrinkToSizeLimit(final SortedSet<JobHistoryEntryStorable> entries) {
    // remove the last entries if over size
    while (entries.size() > MAX_HISTORY_SIZE) {
        entries.remove(entries.last());
    }/*  ww  w  .  ja  v  a  2s. c  om*/
}

From source file:org.trellisldp.file.FileMementoService.java

@Override
public CompletionStage<Resource> get(final IRI identifier, final Instant time) {
    return supplyAsync(() -> {
        final Instant mementoTime = time.truncatedTo(SECONDS);
        final File resourceDir = FileUtils.getResourceDirectory(directory, identifier);
        final File file = FileUtils.getNquadsFile(resourceDir, mementoTime);
        if (file.exists()) {
            return new FileResource(identifier, file);
        }/*from  w  w  w  .  jav  a 2 s  .c o m*/
        final SortedSet<Instant> possible = listMementos(identifier).headSet(mementoTime);
        if (possible.isEmpty()) {
            return MISSING_RESOURCE;
        }
        return new FileResource(identifier, FileUtils.getNquadsFile(resourceDir, possible.last()));
    });
}

From source file:org.powertac.common.OrderbookTests.java

@Test
public void testGetAsks() {
    Orderbook ob = new Orderbook(timeslot, 20.1, now);
    ob.addAsk(new OrderbookOrder(-3.3, 24.0)).addAsk(new OrderbookOrder(-2.1, 20.2))
            .addAsk(new OrderbookOrder(-5.6, 22.4)).addAsk(new OrderbookOrder(-6.2, null));
    SortedSet<OrderbookOrder> asks = ob.getAsks();
    assertEquals("correct number", 4, asks.size());
    assertEquals("no bids", 0, ob.getBids().size());
    assertNull("correct first", asks.first().getLimitPrice());
    assertEquals("correct last", 24.0, asks.last().getLimitPrice(), 1e-6);
}

From source file:com.liveramp.hank.storage.curly.AbstractCurlyPartitionUpdater.java

@Override
protected Integer detectCurrentVersionNumber() throws IOException {
    SortedSet<CueballFilePath> localCueballBases = Cueball.getBases(localPartitionRoot);
    SortedSet<CurlyFilePath> localCurlyBases = Curly.getBases(localPartitionRoot);
    if (localCueballBases.size() > 0 && localCurlyBases.size() > 0) {
        if (localCueballBases.last().getVersion() == localCurlyBases.last().getVersion()) {
            return localCurlyBases.last().getVersion();
        } else {//from  ww w .ja v a2  s  .  com
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

private <T extends StatisticsInfo> void assertInfoSet(Statistics stats, SortedSet<T> info) {
    assertEquals(info.size(), stats.getSequenceNumber());
    assertEquals(info.last().getSequenceNumber() + 1, stats.getSequenceNumber());
    assertEquals(info.first().getTimestamp(), stats.getStartDate());
    assertEquals(info.last().getTimestamp(), stats.getEndDate());
    int i = 0;//from   w ww.j a va2  s .  c  o  m
    for (T next : info) {
        assertEquals(i, next.getSequenceNumber());
        ++i;
    }
}

From source file:org.stockwatcher.web.StockController.java

@RequestMapping(value = "/{symbol}", method = RequestMethod.GET)
public String displayStockDetail(@PathVariable String symbol, Model model, HttpServletRequest request) {
    model.addAttribute("stock", dao.getStockBySymbol(symbol));
    Date tradeDate = applicationProps.getLastTradeDate();
    SortedSet<Trade> trades = dao.getTradesBySymbolAndDate(symbol, tradeDate);
    model.addAttribute("trades", getUniqueTrades(trades));
    long elapsedTime = trades.size() == 0 ? 0
            : getElapsedTime(trades.first().getTimestamp(), trades.last().getTimestamp());
    User user = (User) request.getSession().getAttribute("user");
    model.addAttribute("watchLists",
            user == null ? Collections.EMPTY_SET : watchListDao.getWatchListsByUserId(user.getId()));
    model.addAttribute("lastClosePrice", dao.getLastClosePriceForSymbol(symbol));
    model.addAttribute("elapsedTime", elapsedTime);
    model.addAttribute("liveTrading", applicationProps.isTradingLive());
    model.addAttribute("watchCount", watchListDao.getWatchCount(symbol));
    dao.incrementStockViewCount(symbol);
    return "stock";
}