List of usage examples for com.google.common.collect Lists newLinkedList
@GwtCompatible(serializable = true) public static <E> LinkedList<E> newLinkedList()
From source file:com.google.devcoin.wallet.KeyTimeCoinSelector.java
@Override public Wallet.CoinSelection select(BigInteger target, LinkedList<TransactionOutput> candidates) { try {//from www . ja v a2 s. c om LinkedList<TransactionOutput> gathered = Lists.newLinkedList(); BigInteger valueGathered = BigInteger.ZERO; for (TransactionOutput output : candidates) { if (ignorePending && !isConfirmed(output)) continue; // Find the key that controls output, assuming it's a regular pay-to-pubkey or pay-to-address output. // We ignore any other kind of exotic output on the assumption we can't spend it ourselves. final Script scriptPubKey = output.getScriptPubKey(); ECKey controllingKey; if (scriptPubKey.isSentToRawPubKey()) { controllingKey = wallet.findKeyFromPubKey(scriptPubKey.getPubKey()); } else if (scriptPubKey.isSentToAddress()) { controllingKey = wallet.findKeyFromPubHash(scriptPubKey.getPubKeyHash()); } else { log.info("Skipping tx output {} because it's not of simple form.", output); continue; } if (controllingKey.getCreationTimeSeconds() >= unixTimeSeconds) continue; // It's older than the cutoff time so select. valueGathered = valueGathered.add(output.getValue()); gathered.push(output); if (gathered.size() >= MAX_SIMULTANEOUS_INPUTS) { log.warn("Reached {} inputs, going further would yield a tx that is too large, stopping here.", gathered.size()); break; } } return new Wallet.CoinSelection(valueGathered, gathered); } catch (ScriptException e) { throw new RuntimeException(e); // We should never have problems understanding scripts in our wallet. } }
From source file:org.sonar.scanner.scan.measure.DefaultMetricFinder.java
@Override public Collection<Metric<Serializable>> findAll(List<String> metricKeys) { List<Metric<Serializable>> result = Lists.newLinkedList(); for (String metricKey : metricKeys) { Metric<Serializable> metric = findByKey(metricKey); if (metric != null) { result.add(metric);//from w ww . j ava2 s. c o m } } return result; }
From source file:de.iteratec.iteraplan.elasticeam.util.ListFilterHelper.java
/** * Filters a given collection to instances of a given type. if the type is comparable, the resulting list is sorted. * @param input the input collection//from www.j a v a 2 s . c o m * @param type the type of elements to be filtered * @return the (ordered) list of instances of the given type */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <I, O> List<O> filter(Collection<I> input, Class<O> type) { if (Comparable.class.isAssignableFrom(type)) { return (List<O>) filterAndSort(input, (Class<? extends Comparable>) type); } else { List<O> result = Lists.newLinkedList(); collect(input, type, result); return result; } }
From source file:org.apache.helix.common.ClusterEventBlockingQueue.java
/** * Instantiate the queue */ public ClusterEventBlockingQueue() { _eventMap = Maps.newHashMap(); _eventQueue = Lists.newLinkedList(); }
From source file:org.impressivecode.depress.mr.jacoco.JaCoCoEntriesParser.java
public List<JaCoCoEntry> parseEntries(final String path) throws ParserConfigurationException, SAXException, IOException { Preconditions.checkArgument(!isNullOrEmpty(path), "Path has to be set."); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(path); NodeList nList = getSourceFileNodes(doc); int size = nList.getLength(); List<JaCoCoEntry> jacocoEntries = Lists.newLinkedList(); for (int i = 0; i < size; i++) { Node item = nList.item(i); JaCoCoEntry entry = parse(item); jacocoEntries.add(entry);//from w ww. jav a 2 s .c om } return jacocoEntries; }
From source file:edu.umn.msi.tropix.common.jobqueue.execution.DelegatingExecutionJobQueueImpl.java
public Collection<ExecutionJobInfo<JobDescription>> listJobs() { final List<ExecutionJobInfo<JobDescription>> jobs = Lists.newLinkedList(); for (final ExecutionJobQueue<JobDescription> executionJobQueue : executionJobQueueMap.values()) { jobs.addAll(executionJobQueue.listJobs()); }//from w w w.j a v a 2 s . c om return jobs; }
From source file:org.axonframework.ext.eventstore.MemoryEventStore.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a2 s . com public void appendEvents(String type, DomainEventStream events) { Map<Object, List<DomainEventMessage<T>>> typeStorage = m_storage.get(type); if (typeStorage == null) { typeStorage = Maps.newHashMap(); m_storage.put(type, typeStorage); } if (events.hasNext()) { DomainEventMessage<T> message = events.next(); Object aggregateId = message.getAggregateIdentifier(); List<DomainEventMessage<T>> messages = typeStorage.get(aggregateId); if (message.getSequenceNumber() == 0 || messages == null) { messages = Lists.newLinkedList(); typeStorage.put(aggregateId, messages); } messages.add(message); while (events.hasNext()) { messages.add(events.next()); } } }
From source file:com.google.dart.ui.test.driver.OperationExecutor.java
/** * Runs the scheduled {@link Operation}s, waits for the given time at most. *//*from w w w . j a v a2s. co m*/ public void runUiOperations(long waitFor, TimeUnit unit) throws Exception { display.timerExec(5, new Runnable() { private LinkedList<Operation> finishOperations = Lists.newLinkedList(); @Override public void run() { // are we done? if (operationsDone.get()) { return; } // schedule again display.timerExec(5, this); // run single operation try { // wait for current operation done if (!finishOperations.isEmpty()) { Operation operation = finishOperations.getFirst(); if (operation.isDone(context)) { finishOperations.removeFirst(); operation.done(context); maybeDone(); } return; } // prepare new operation if (operations.isEmpty()) { return; } Operation operation = operations.getFirst(); // wait for new operation ready if (operation.isReady(context)) { operations.removeFirst(); try { operation.run(context); // done operation if (operation.isDone(context)) { operation.done(context); } else { finishOperations.addLast(operation); } // may be done execution maybeDone(); } catch (Throwable e) { operation.onError(context); ExecutionUtils.propagate(e); } } } catch (Throwable e) { if (exception == null) { exception = e; } // we are done - with failure operationsDone.set(true); } } private void maybeDone() { if (operations.isEmpty() && finishOperations.isEmpty()) { operationsDone.set(true); } } }); // wait for successful completion or failure { long end = System.nanoTime() + unit.toNanos(waitFor); while (!operationsDone.get()) { if (System.nanoTime() >= end) { throw new TimeoutException(); } UiContext.runEventLoop(10); } } // check for exception if (exception != null) { ExecutionUtils.propagate(exception); } // OK }
From source file:org.artifactory.support.core.compression.CompressionServiceImpl.java
/** * Compresses given directory into zip file * * @param directory the content to compress * @param size default archive size/*from www . j a v a 2 s. c om*/ * * @return zipped archive/s */ @Override public List<File> compress(File directory, int size) { List<File> destinationArchives = Lists.newLinkedList(); try { File destinationArchive = new File( directory.getPath() + File.separator + directory.getName() + "." + ARCHIVE_EXTENSION); ZipUtils.archive(directory, destinationArchive, true); destinationArchives.add(destinationArchive); } catch (IOException e) { log.error("Content compression has failed, - " + e.getMessage()); log.debug("Cause: {}", e); } finally { cleanup(directory); } return destinationArchives; }
From source file:com.google.sha1coin.wallet.KeyTimeCoinSelector.java
@Override public CoinSelection select(Coin target, LinkedList<TransactionOutput> candidates) { try {/*from w ww .j a va 2 s. co m*/ LinkedList<TransactionOutput> gathered = Lists.newLinkedList(); Coin valueGathered = Coin.ZERO; for (TransactionOutput output : candidates) { if (ignorePending && !isConfirmed(output)) continue; // Find the key that controls output, assuming it's a regular pay-to-pubkey or pay-to-address output. // We ignore any other kind of exotic output on the assumption we can't spend it ourselves. final Script scriptPubKey = output.getScriptPubKey(); ECKey controllingKey; if (scriptPubKey.isSentToRawPubKey()) { controllingKey = wallet.findKeyFromPubKey(scriptPubKey.getPubKey()); } else if (scriptPubKey.isSentToAddress()) { controllingKey = wallet.findKeyFromPubHash(scriptPubKey.getPubKeyHash()); } else { log.info("Skipping tx output {} because it's not of simple form.", output); continue; } checkNotNull(controllingKey, "Coin selector given output as candidate for which we lack the key"); if (controllingKey.getCreationTimeSeconds() >= unixTimeSeconds) continue; // It's older than the cutoff time so select. valueGathered = valueGathered.add(output.getValue()); gathered.push(output); if (gathered.size() >= MAX_SIMULTANEOUS_INPUTS) { log.warn("Reached {} inputs, going further would yield a tx that is too large, stopping here.", gathered.size()); break; } } return new CoinSelection(valueGathered, gathered); } catch (ScriptException e) { throw new RuntimeException(e); // We should never have problems understanding scripts in our wallet. } }