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:co.mitro.core.crypto.GenerateKeysToFile.java

/**
 * @param args/*from   w w  w  .ja v a  2s.  c om*/
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    long start = System.currentTimeMillis();
    if (args.length < 2) {
        throw new Exception("Need 2 args: numKeys outputFileName");
    }
    KeyczarKeyFactory kz = new KeyczarKeyFactory();
    final int numKeys = Integer.valueOf(args[0]);

    List<String> keys = Lists.newLinkedList();
    for (int i = 0; i < numKeys; ++i) {
        System.out.println("generating key " + i);
        keys.add(kz.generate().toString());
    }
    Gson gson = new Gson();
    String out = gson.toJson(keys);
    Files.write(out, new File(args[1]), Charset.forName("UTF-8"));

    System.out.println("done in " + (System.currentTimeMillis() - start) + " ms.");

}

From source file:org.eclipse.buildship.core.util.string.StringUtils.java

/**
 * Removes adjacent duplicates.// w w w  .  ja  v  a  2  s  .  c om
 *
 * @param elements the elements to filter
 * @return the result with adjacent duplicates removed
 */
public static ImmutableList<String> removeAdjacentDuplicates(List<String> elements) {
    Deque<String> result = Lists.newLinkedList();
    for (String element : elements) {
        if (result.isEmpty() || !result.getLast().equals(element)) {
            result.addLast(element);
        }
    }
    return ImmutableList.copyOf(result);
}

From source file:org.locationtech.geogig.storage.StagingDbCompositionHelper.java

public static Iterator<RevObject> getAll(final ObjectDatabase objectDb, final ObjectDatabase stagingDb,
        final Iterable<ObjectId> ids, final BulkOpListener listener) {

    final List<ObjectId> missingInStaging = Lists.newLinkedList();

    final int limit = 10000;

    final BulkOpListener stagingListener = new BulkOpListener.ForwardingListener(listener) {
        @Override/*from  w w w  . ja  va2s  .  com*/
        public void notFound(ObjectId id) {
            missingInStaging.add(id);
        }
    };

    final Iterator<RevObject> foundInStaging = stagingDb.getAll(ids, stagingListener);

    Iterator<RevObject> compositeIterator = new AbstractIterator<RevObject>() {

        Iterator<RevObject> forwardedToObjectDb = Iterators.emptyIterator();

        @Override
        protected RevObject computeNext() {
            if (forwardedToObjectDb.hasNext()) {
                return forwardedToObjectDb.next();
            }
            if (missingInStaging.size() >= limit) {
                List<ObjectId> missing = new ArrayList<ObjectId>(missingInStaging);
                missingInStaging.clear();

                forwardedToObjectDb = objectDb.getAll(missing, listener);
                return computeNext();
            }
            if (foundInStaging.hasNext()) {
                return foundInStaging.next();
            } else if (forwardedToObjectDb.hasNext()) {
                return forwardedToObjectDb.next();
            } else if (!missingInStaging.isEmpty()) {
                List<ObjectId> missing = new ArrayList<ObjectId>(missingInStaging);
                missingInStaging.clear();
                forwardedToObjectDb = objectDb.getAll(missing, listener);
                return computeNext();
            }
            return endOfData();
        }
    };

    return compositeIterator;
}

From source file:org.locationtech.geogig.storage.impl.StagingDbCompositionHelper.java

public static Iterator<RevObject> getAll(final ObjectStore objectDb, final ObjectStore stagingDb,
        final Iterable<ObjectId> ids, final BulkOpListener listener) {

    final List<ObjectId> missingInStaging = Lists.newLinkedList();

    final int limit = 10000;

    final BulkOpListener stagingListener = new BulkOpListener.ForwardingListener(listener) {
        @Override//  w w w .  jav  a  2s .  c om
        public void notFound(ObjectId id) {
            missingInStaging.add(id);
        }
    };

    final Iterator<RevObject> foundInStaging = stagingDb.getAll(ids, stagingListener);

    Iterator<RevObject> compositeIterator = new AbstractIterator<RevObject>() {

        Iterator<RevObject> forwardedToObjectDb = Collections.emptyIterator();

        @Override
        protected RevObject computeNext() {
            if (forwardedToObjectDb.hasNext()) {
                return forwardedToObjectDb.next();
            }
            if (missingInStaging.size() >= limit) {
                List<ObjectId> missing = new ArrayList<ObjectId>(missingInStaging);
                missingInStaging.clear();

                forwardedToObjectDb = objectDb.getAll(missing, listener);
                return computeNext();
            }
            if (foundInStaging.hasNext()) {
                return foundInStaging.next();
            } else if (forwardedToObjectDb.hasNext()) {
                return forwardedToObjectDb.next();
            } else if (!missingInStaging.isEmpty()) {
                List<ObjectId> missing = new ArrayList<ObjectId>(missingInStaging);
                missingInStaging.clear();
                forwardedToObjectDb = objectDb.getAll(missing, listener);
                return computeNext();
            }
            return endOfData();
        }
    };

    return compositeIterator;
}

From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java

@Nonnull
public static List<TestCase[]> getTestCases(Path baseDirectory) throws ClassNotFoundException, IOException {
    if (!baseDirectory.toFile().exists()) {
        return Lists.newLinkedList();
    }//from  ww  w.j  a va2 s .c  om
    return recursiveGetTestCases(baseDirectory.toFile(), baseDirectory.toString());
}

From source file:org.apache.kylin.common.util.PartialSorter.java

public static <T> void partialSort(List<T> list, List<Integer> items, Comparator<? super T> c) {
    List<T> temp = Lists.newLinkedList();
    for (int index : items) {
        temp.add(list.get(index));// ww  w .  j a va2  s . com
    }
    Collections.sort(temp, c);
    for (int i = 0; i < temp.size(); ++i) {
        list.set(items.get(i), temp.get(i));
    }
}

From source file:org.openqa.selenium.android.events.TouchScreen.java

public static void sendMotion(WebView webview, MotionEvent... events) {
    WebViewAction.clearFocusFromCurrentElement(webview);

    if (Platform.sdk() <= Platform.DONUT) {
        webview.pauseTimers();/*from   w  w  w. jav a 2s .  c o  m*/
    }
    try {
        List<MotionEvent> eventsQueue = Lists.newLinkedList();
        long downTime = SystemClock.uptimeMillis();
        for (MotionEvent event : events) {
            long eventTime = SystemClock.uptimeMillis();
            MotionEvent e = MotionEvent.obtain(downTime, eventTime, event.getAction(), event.getX(),
                    event.getY(), event.getMetaState());
            eventsQueue.add(e);
        }
        for (MotionEvent me : eventsQueue) {
            webview.onTouchEvent(me);
        }
        for (MotionEvent me : eventsQueue) {
            me.recycle();
        }
    } finally {
        if (Platform.sdk() <= Platform.DONUT) {
            webview.resumeTimers();
        }
    }
}

From source file:org.gradle.model.internal.manage.schema.extract.InvalidManagedModelElementTypeException.java

private static String createPathString(ModelSchemaExtractionContext<?> extractionContext) {
    StringBuilder prefix = new StringBuilder("  ");
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);

    Deque<String> descriptions = Lists.newLinkedList();
    ModelSchemaExtractionContext<?> current = extractionContext;
    while (current != null) {
        descriptions.push(current.getDescription());
        current = current.getParent();//w  w w . java2  s.  c om
    }

    writer.println(descriptions.pop());

    while (!descriptions.isEmpty()) {
        writer.print(prefix);
        writer.print("\\--- ");
        writer.print(descriptions.pop());

        if (!descriptions.isEmpty()) {
            writer.println();
            prefix.append("  ");
        }
    }

    return out.toString();
}

From source file:org.artifactory.support.utils.FileUtils.java

/**
 * Converts list of {@link java.io.File} to
 * list of {@link java.lang.String} file names
 *
 * @param files//w  ww .  j a va  2  s . co  m
 *
 * @return List<String>
 */
public static List<String> toFileNames(List<File> files) {
    return files != null && files.size() > 0
            ? files.parallelStream().map(f -> f.getName()).collect(Collectors.toList())
            : Lists.newLinkedList();
}

From source file:exec.examples.IoHelper.java

public static List<Context> readAll(String dir) {
    LinkedList<Context> res = Lists.newLinkedList();

    for (String zip : findAllZips(dir)) {
        res.addAll(read(zip));//from   w  ww .java  2  s.c  o  m
    }
    return res;
}