Example usage for com.google.common.collect ImmutableSortedSet last

List of usage examples for com.google.common.collect ImmutableSortedSet last

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet last.

Prototype

public E last() 

Source Link

Usage

From source file:com.ibm.common.geojson.BoundingBox.java

private static BoundingBox buildBoundingBox(ImmutableSortedSet<Float> xs, ImmutableSortedSet<Float> ys,
        ImmutableSortedSet<Float> zs) {
    BoundingBox.Builder bbox = new BoundingBox.Builder().add(xs.first()).add(ys.first());
    if (!zs.isEmpty())
        bbox.add(zs.first());//  w w  w . ja  v  a 2  s .  c  o  m
    bbox.add(xs.last());
    bbox.add(ys.last());
    if (!zs.isEmpty())
        bbox.add(zs.last());
    return bbox.get();
}

From source file:org.voltcore.utils.COWNavigableSet.java

@Override
public E pollLast() {
    while (true) {
        ImmutableSortedSet<E> snapshot = m_set.get();
        E last = null;//from   w  ww. ja  v a  2  s .c  o  m
        if (snapshot.size() > 0) {
            last = snapshot.last();
        } else {
            return null;
        }
        ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder();
        builder.addAll(snapshot.headSet(last, false));
        if (m_set.compareAndSet(snapshot, builder.build())) {
            return last;
        }
    }
}

From source file:org.sosy_lab.cpachecker.cpa.location.LocationStateFactory.java

public LocationStateFactory(CFA pCfa, AnalysisDirection pLocationType, Configuration config)
        throws InvalidConfigurationException {
    config.inject(this);
    locationType = checkNotNull(pLocationType);

    ImmutableSortedSet<CFANode> allNodes;
    Collection<CFANode> tmpNodes = pCfa.getAllNodes();
    if (tmpNodes instanceof ImmutableSortedSet) {
        allNodes = (ImmutableSortedSet<CFANode>) tmpNodes;
    } else {/*from  w w w .  j a  v a 2 s.com*/
        allNodes = ImmutableSortedSet.copyOf(tmpNodes);
    }

    int maxNodeNumber = allNodes.last().getNodeNumber();
    states = new LocationState[maxNodeNumber + 1];
    for (CFANode node : allNodes) {
        LocationState state = createLocationState(node);
        states[node.getNodeNumber()] = state;
    }
}

From source file:com.zulily.omicron.sla.TimeSinceLastSuccess.java

@Override
protected Alert generateAlert(final Job job) {
    // The task has never been evaluated to run because it's new or it's not considered to be runnable to begin with
    // We cannot logically evaluate this alert
    if (!job.isRunnable() || !job.isActive()) {
        return createNotApplicableAlert(job);
    }/*www.j a  v a 2  s . c  o m*/

    final ImmutableSortedSet<TaskLogEntry> logView = job.filterLog(STATUS_FILTER);

    // No observable status changes in the task log - still nothing to do
    if (logView.isEmpty()) {
        return createNotApplicableAlert(job);
    }

    // Just succeed if the last log status is complete
    // This also avoids false alerts during schedule gaps
    if (logView.last().getTaskStatus() == TaskStatus.Complete) {
        return createAlert(job, logView.last(), AlertStatus.Success);
    }

    // Avoid spamming alerts during gaps in the schedule
    if (alertedOnceSinceLastActive(logView.last().getTimestamp(), job.getJobId())) {
        return createNotApplicableAlert(job);
    }

    // The last status is either error or failed start
    // so find that last time there was a complete, if any
    final Optional<TaskLogEntry> latestComplete = logView.descendingSet().stream()
            .filter(entry -> entry.getTaskStatus() == TaskStatus.Complete).findFirst();

    // If we've seen at least one success in recent history and a task is running,
    // do not alert until a final status is achieved to avoid noise before potential recovery
    if (logView.last().getTaskStatus() == TaskStatus.Started && latestComplete.isPresent()) {
        return createNotApplicableAlert(job);
    }

    final int minutesBetweenSuccessThreshold = job.getConfiguration().getInt(ConfigKey.SLAMinutesSinceSuccess);

    final long currentTimestamp = Clock.systemUTC().millis();

    final TaskLogEntry baselineTaskLogEntry = latestComplete.isPresent() ? latestComplete.get()
            : logView.first();

    final long minutesIncomplete = TimeUnit.MILLISECONDS
            .toMinutes(currentTimestamp - baselineTaskLogEntry.getTimestamp());

    if (minutesIncomplete <= minutesBetweenSuccessThreshold) {
        return createAlert(job, baselineTaskLogEntry, AlertStatus.Success);
    } else {
        return createAlert(job, baselineTaskLogEntry, AlertStatus.Failure);
    }

}

From source file:edu.mit.streamjit.impl.compiler2.Storage.java

/**
 * Returns a range spanning the indices written in this storage during an
 * execution of the given schedule. (Note that, as a span, not every
 * contained index will be written.) The returned range will be
 * {@link Range#canonical(com.google.common.collect.DiscreteDomain) canonical}.
 * The range is not cached so as to be responsive to changes in output index
 * functions.//  www . j a v a2  s.  c  om
 * @param externalSchedule the schedule
 * @return a range spanning the indices written during the given schedule
 * under the current index functions
 * @see #writeIndices(java.util.Map)
 */
public Range<Integer> writeIndexSpan(Map<ActorGroup, Integer> externalSchedule) {
    Range<Integer> range = null;
    for (Actor a : upstream()) {
        //just the first and last iteration
        int maxIteration = a.group().schedule().get(a) * externalSchedule.get(a.group()) - 1;
        if (maxIteration >= 0)
            for (int iteration : new int[] { 0, maxIteration }) {
                ImmutableSortedSet<Integer> writes = a.writes(this, iteration);
                Range<Integer> writeRange = writes.isEmpty() ? range
                        : Range.closed(writes.first(), writes.last());
                range = range == null ? writeRange : range.span(writeRange);
            }
    }
    range = (range != null ? range : Range.closedOpen(0, 0));
    return range.canonical(DiscreteDomain.integers());
}