Example usage for com.google.common.collect ImmutableList listIterator

List of usage examples for com.google.common.collect ImmutableList listIterator

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList listIterator.

Prototype

@Override
    public UnmodifiableListIterator<E> listIterator(int index) 

Source Link

Usage

From source file:org.glowroot.api.internal.ThrowableInfo.java

private static ThrowableInfo from(Throwable t, @Nullable List<StackTraceElement> causedStackTrace) {
    int framesInCommon = 0;
    ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(t.getStackTrace());
    if (causedStackTrace != null) {
        ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size());
        ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size());
        while (i.hasPrevious() && j.hasPrevious()) {
            StackTraceElement element = i.previous();
            StackTraceElement causedElement = j.previous();
            if (!element.equals(causedElement)) {
                break;
            }/*  w w w .  java  2  s  .  c  o m*/
            framesInCommon++;
        }
        if (framesInCommon > 0) {
            // strip off common frames
            stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommon);
        }
    }
    ImmutableThrowableInfo.Builder builder = ImmutableThrowableInfo.builder().display(t.toString())
            .addAllStackTrace(stackTrace).framesInCommonWithCaused(framesInCommon);
    Throwable cause = t.getCause();
    if (cause != null) {
        // pass t's original stack trace to construct the nested cause
        // (not stackTraces, which now has common frames removed)
        builder.cause(from(cause, Arrays.asList(t.getStackTrace())));
    }
    return builder.build();
}

From source file:org.glowroot.agent.model.ErrorMessage.java

private static StackTraceWithoutCommonFrames getStackTraceAndFramesInCommon(
        StackTraceElement[] stackTraceElements, @Nullable List<StackTraceElement> causedStackTrace,
        AtomicInteger transactionThrowableFrameCount) {
    if (transactionThrowableFrameCount.get() >= TRANSACTION_THROWABLE_FRAME_LIMIT) {
        return ImmutableStackTraceWithoutCommonFrames.builder().build();
    }//from  www .j  a va  2s.  c  o  m
    if (causedStackTrace == null) {
        return ImmutableStackTraceWithoutCommonFrames.builder().addStackTrace(stackTraceElements).build();
    }
    ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(stackTraceElements);
    int framesInCommonWithEnclosing = 0;
    ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size());
    ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size());
    while (i.hasPrevious() && j.hasPrevious()) {
        StackTraceElement element = i.previous();
        StackTraceElement causedElement = j.previous();
        if (!element.equals(causedElement)) {
            break;
        }
        framesInCommonWithEnclosing++;
    }
    if (framesInCommonWithEnclosing > 0) {
        // strip off common frames
        stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommonWithEnclosing);
    }
    return ImmutableStackTraceWithoutCommonFrames.builder().stackTrace(stackTrace)
            .framesInCommonWithEnclosing(framesInCommonWithEnclosing).build();
}

From source file:com.skelril.nitro.droptable.roller.SlipperySingleHitDiceRoller.java

@Override
public <T extends DropTableEntry> Collection<T> getHits(ImmutableList<T> input, double modifier) {
    ListIterator<T> it = input.listIterator(input.size());

    T cur = null;/*from   w w w . j a  va2s  .  c om*/
    while (it.hasPrevious()) {
        cur = it.previous();

        // Slip through until something which is >= the chance is hit, unless a modifier is applied
        // this is equivalent to a 1 / chance probability
        if (cur.getChance() <= Probability.getRandom(modiFunc.apply(cur.getChance(), modifier))) {
            break;
        }

        cur = null;
    }

    return cur == null ? Collections.emptySet() : Collections.singleton(cur);
}