Example usage for com.google.common.collect Lists newLinkedList

List of usage examples for com.google.common.collect Lists newLinkedList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newLinkedList.

Prototype

@GwtCompatible(serializable = true)
public static <E> LinkedList<E> newLinkedList() 

Source Link

Document

Creates a mutable, empty LinkedList instance (for Java 6 and earlier).

Usage

From source file:com.twitter.common.net.http.handlers.ContentionPrinter.java

@Override
public Iterable<String> getLines(HttpServletRequest request) {
    List<String> lines = Lists.newLinkedList();
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();

    Map<Long, StackTraceElement[]> threadStacks = Maps.newHashMap();
    for (Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
        threadStacks.put(entry.getKey().getId(), entry.getValue());
    }/*  w  w  w . j  av  a  2s  .  c om*/

    Set<Long> lockOwners = Sets.newHashSet();

    lines.add("Locked threads:");
    for (ThreadInfo t : bean.getThreadInfo(bean.getAllThreadIds())) {
        switch (t.getThreadState()) {
        case BLOCKED:
        case WAITING:
        case TIMED_WAITING:
            lines.addAll(getThreadInfo(t, threadStacks.get(t.getThreadId())));
            if (t.getLockOwnerId() != -1)
                lockOwners.add(t.getLockOwnerId());
            break;
        }
    }

    if (lockOwners.size() > 0) {
        lines.add("\nLock Owners");
        for (ThreadInfo t : bean.getThreadInfo(Longs.toArray(lockOwners))) {
            lines.addAll(getThreadInfo(t, threadStacks.get(t.getThreadId())));
        }
    }

    return lines;
}

From source file:de.tuberlin.uebb.jdae.simulation.ResultStorage.java

public ResultStorage(ExecutableDAE dae) {
    super();
    this.dae = dae;
    results = Lists.newLinkedList();
}

From source file:com.textocat.textokit.ml.SuffixFeatureExtractor.java

@Override
public List<Feature> extract(JCas view, Annotation focusAnnotation) throws CleartkExtractorException {
    if (focusAnnotation instanceof Token) {
        if (!(focusAnnotation instanceof W)) {
            return ImmutableList.of();
        }//from   w ww.j ava2s . c  o m
    }
    String str = focusAnnotation.getCoveredText();
    List<Feature> result = Lists.newLinkedList();
    for (int suffixLength = 1; suffixLength <= maxSuffixLength; suffixLength++) {
        String val;
        if (str.length() <= suffixLength) {
            val = str;
        } else {
            val = "*" + str.substring(str.length() - suffixLength);
        }
        result.add(new Feature(getFeatureName(suffixLength), val));
        if (str.length() <= suffixLength) {
            // suffix length increasing so there is no point to produce other features with different name
            break;
        }
    }
    return result;
}

From source file:org.onosproject.drivers.barefoot.TofinoPipelineProgrammable.java

@Override
public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) {

    List<ByteBuffer> buffers = Lists.newLinkedList();
    try {//from   w  ww  .j a va  2 s  .  com
        buffers.add(nameBuffer(pipeconf));
        buffers.add(extensionBuffer(pipeconf, TOFINO_BIN));
        buffers.add(extensionBuffer(pipeconf, TOFINO_CONTEXT_JSON));
    } catch (ExtensionException e) {
        return null;
    }

    // Concatenate buffers (flip so they can be read).
    int len = buffers.stream().mapToInt(Buffer::limit).sum();
    ByteBuffer deviceData = ByteBuffer.allocate(len);
    buffers.forEach(b -> deviceData.put((ByteBuffer) b.flip()));
    deviceData.flip();

    return deviceData.asReadOnlyBuffer();
}

From source file:org.auraframework.impl.java.controller.AuraStorageTestController.java

@AuraEnabled
public static List<Object> execute(@Key("commands") String commands) throws Exception {
    String testName = Aura.get(TestContextAdapter.class).getTestContext().getName();
    List<Object> result = Lists.newLinkedList();
    getExecutorLock(testName);/*from   ww  w  .  j ava 2s.c  o  m*/
    try {
        for (String command : commands.split(";")) {
            String args[] = command.trim().split(" ", 2);
            String cmdArg = args.length > 1 ? args[1].trim() : "";
            Command cmd = Command.valueOf(args[0].trim().toUpperCase());
            switch (cmd) {
            case RESET:
                /*
                 * When releasing blocked threads, those threads may continue running a set of commands that may
                 * create, remove, or update more semaphores. So, release blocked threads, clean up dangling
                 * semaphores, and repeat until all semaphores are gone.
                 */
                for (Map<String, Semaphore> sems = pending.get(testName); sems != null
                        && !sems.isEmpty(); sems = pending.get(testName)) {
                    for (Iterator<Entry<String, Semaphore>> iterator = sems.entrySet().iterator(); iterator
                            .hasNext();) {
                        Semaphore current = iterator.next().getValue();
                        if (current.hasQueuedThreads()) {
                            current.release();
                        } else {
                            iterator.remove();
                        }
                    }
                    releaseExecutorLock(testName);
                    Thread.yield();
                    getExecutorLock(testName);
                }
                buffer.remove(testName);
                break;
            case WAIT:
                Semaphore sem = getSemaphore(testName, cmdArg, true);
                releaseExecutorLock(testName);
                try {
                    if (!sem.tryAcquire(30, TimeUnit.SECONDS)) {
                        throw new AuraRuntimeException(
                                "Timed out waiting to acquire " + testName + ":" + cmdArg);
                    }
                } finally {
                    getExecutorLock(testName);
                    if (!sem.hasQueuedThreads()) {
                        removeSemaphore(testName, cmdArg);
                    }
                }
                break;
            case RESUME:
                getSemaphore(testName, cmdArg, true).release();
                break;
            case APPEND:
                getBuffer(testName).add(cmdArg);
                break;
            case READ:
                List<Object> temp = buffer.remove(testName);
                if (temp != null) {
                    result.addAll(temp);
                }
                break;
            case STAMP:
                getBuffer(testName).add(new Date().getTime());
                break;
            case SLEEP:
                long millis = 500;
                try {
                    millis = Long.parseLong(cmdArg);
                } catch (Throwable t) {
                }
                try {
                    releaseExecutorLock(testName);
                    Thread.sleep(millis);
                } finally {
                    getExecutorLock(testName);

                }
                break;
            }
        }
        return result;
    } finally {
        releaseExecutorLock(testName);
    }
}

From source file:org.apache.drill.exec.server.rest.DrillRoot.java

@GET
@Path("/stats.json")
@Produces(MediaType.APPLICATION_JSON)/* w w w .j av  a2s  .  co m*/
public List<Stat> getStatsJSON() {
    List<Stat> stats = Lists.newLinkedList();
    stats.add(new Stat("Number of Drill Bits", work.getContext().getBits().size()));
    int number = 0;
    for (CoordinationProtos.DrillbitEndpoint bit : work.getContext().getBits()) {
        String initialized = bit.isInitialized() ? " initialized" : " not initialized";
        stats.add(new Stat("Bit #" + number, bit.getAddress() + initialized));
        ++number;
    }
    stats.add(new Stat("Data Port Address", work.getContext().getEndpoint().getAddress() + ":"
            + work.getContext().getEndpoint().getDataPort()));
    stats.add(new Stat("User Port Address", work.getContext().getEndpoint().getAddress() + ":"
            + work.getContext().getEndpoint().getUserPort()));
    stats.add(new Stat("Control Port Address", work.getContext().getEndpoint().getAddress() + ":"
            + work.getContext().getEndpoint().getControlPort()));
    stats.add(new Stat("Maximum Direct Memory", DrillConfig.getMaxDirectMemory()));

    return stats;
}

From source file:eu.numberfour.n4js.scoping.imports.AmbiguousImportDescription.java

/**
 * Wraps an existing description for a type with an ambiguous import error message.
 *//*from w  ww. jav a2s .  c  o  m*/
public AmbiguousImportDescription(IEObjectDescription delegate, String issueCode, EObject context) {
    super(delegate);
    this.issueCode = issueCode;
    this.context = context;
    elements = Lists.newLinkedList();
    originatingImports = Lists.newLinkedList();
}

From source file:org.b1.pack.cli.FileTools.java

public static List<String> getPath(File file) {
    LinkedList<String> result = Lists.newLinkedList();
    do {//from   w w w.jav  a2  s  .  co m
        String name = file.getName();
        if (name.isEmpty() || name.equals(".") || name.equals("..")) {
            return result;
        }
        result.addFirst(name);
        file = file.getParentFile();
    } while (file != null);
    return result;
}

From source file:com.romeikat.datamessie.core.statistics.task.StatisticsToBeRebuilt.java

StatisticsToBeRebuilt() {
    publishedDatesToBeRebuilt = Lists.newLinkedList();
    sourcesToBeRebuilt = Lists.newLinkedList();
    sourcesAndPublishedTatesToBeRebuilt = new StatisticsRebuildingSparseTable();
}

From source file:org.richfaces.resource.optimizer.resource.handler.impl.StaticResourceHandler.java

private Collection<VirtualFile> findLibraries(String libraryName) {
    List<VirtualFile> libraryDirs = Lists.newLinkedList();
    for (VirtualFile file : roots) {
        VirtualFile child = file.getChild(libraryName);
        if (child == null) {
            continue;
        }// ww  w  .j  a  va2  s  .co m

        VirtualFile libraryDir = ResourceUtil.getLatestVersion(child, true);
        if (libraryDir != null) {
            libraryDirs.add(libraryDir);
        }
    }

    return libraryDirs;
}