List of usage examples for com.google.common.collect Lists newLinkedList
@GwtCompatible(serializable = true) public static <E> LinkedList<E> newLinkedList()
From source file:ch.ethz.tik.graphgenerator.algorithms.BidirectionalSearch.java
protected List<Node> makeNodeList(Node source, Node target) { if (intersectionId == -1) { throw new IllegalStateException("Intersection must be set before computing optimal path."); }/*from w w w . ja v a 2s .c o m*/ List<Node> path = Lists.newLinkedList(); List<Node> pathFromSource = fromSource.traceBackPath(); List<Node> pathFromTarget = fromTarget.traceBackPath(); // Remove center from target-list and reverse it to obtain list // [center+1 ... target] pathFromTarget.remove(pathFromTarget.get(pathFromTarget.size() - 1)); Collections.reverse(pathFromTarget); // Put everything together, including start and target nodes, that are // not in the graph. path.add(source); path.addAll(pathFromSource); path.addAll(pathFromTarget); path.add(target); return path; }
From source file:com.epam.reportportal.utils.queue.FlushableQueue.java
@Override public void flush() throws IOException { Queue<E> flushed = delegate; delegate = Lists.newLinkedList(); performFlush(flushed); }
From source file:us.physion.ovation.ui.editor.EntityUtilities.java
public static List<Resource> insertResources(Folder folder, File[] files) { List<Resource> result = Lists.newLinkedList(); for (File f : files) { try {/*from w w w . jav a2 s.c o m*/ Resource r = folder.addResource(f.getName(), f.toURI().toURL(), ContentTypes.getContentType(f)); result.add(r); } catch (IOException ex) { throw new OvationException("Unable to add Resource(s)", ex); } } return result; }
From source file:com.griddynamics.jagger.engine.e1.reporting.WorkloadSessionComparisonReporter.java
@Override public JRDataSource getDataSource(Collection<Verdict<WorkloadComparisonResult>> key) { getContext().getParameters().put("jagger.workloadsessioncomparator.statusImageProvider", statusImageProvider);// w ww.j a va 2 s.c o m List<WorkloadSessionComparisonDto> result = Lists.newLinkedList(); for (Verdict<WorkloadComparisonResult> verdict : key) { WorkloadSessionComparisonDto dto = new WorkloadSessionComparisonDto(); dto.setName(verdict.getDescription()); dto.setDecision(verdict.getDecision()); WorkloadComparisonResult details = verdict.getDetails(); dto.setAvgLatencyDeviation(details.getAvgLatencyDeviation()); dto.setStdDevLatencyDeviation(details.getStdDevLatencyDeviation()); dto.setThroughputDeviation(details.getThroughputDeviation()); dto.setTotalDurationDeviation(details.getTotalDurationDeviation()); dto.setSuccessRateDeviation(details.getSuccessRateDeviation()); result.add(dto); } return new JRBeanCollectionDataSource(result); }
From source file:org.apache.streams.local.test.writer.DatumCounterWriter.java
@Override public void write(StreamsDatum entry) { ++this.counter; SEEN_DATA.add(this.id); synchronized (RECEIVED) { List<Object> documents = RECEIVED.get(this.writerId); if (documents == null) { List<Object> docs = Lists.newLinkedList(); docs.add(entry.getDocument()); RECEIVED.put(this.writerId, docs); } else {/*from w ww. j a v a2 s.c om*/ documents.add(entry.getDocument()); } } }
From source file:fr.obeo.releng.targetplatform.resolved.ResolvedTargetPlatform.java
public static ResolvedTargetPlatform create(TargetPlatform targetPlatform, LocationIndexBuilder indexBuilder) throws URISyntaxException { Preconditions.checkArgument(targetPlatform != null); LinkedList<ResolvedLocation> locations = Lists.newLinkedList(); ListMultimap<String, Location> locationIndex = indexBuilder.getLocationIndex(targetPlatform); for (String locationUri : locationIndex.keySet()) { List<UnresolvedIU> ius = Lists.newArrayList(); Set<String> ids = Sets.newHashSet(); List<Location> list = locationIndex.get(locationUri); for (Location location : list) { EList<IU> iuList = location.getIus(); for (IU iu : iuList) { if (!ids.contains(iu.getID())) { ids.add(iu.getID()); ius.add(new UnresolvedIU(iu.getID(), Strings.emptyToNull(iu.getVersion()))); }/* ww w .j a v a 2 s .c om*/ } } Location firstLocation = locationIndex.get(locationUri).get(0); ResolvedLocation resolvedLocation = new ResolvedLocation(firstLocation.getID(), firstLocation.getUri(), ius, getOptionSet(firstLocation.getOptions())); locations.addFirst(resolvedLocation); } final EnumSet<Option> options = getOptionSet(targetPlatform.getOptions()); return new ResolvedTargetPlatform(targetPlatform.getName(), locations, options, Environment.create(targetPlatform)); }
From source file:com.textocat.textokit.commons.io.axml.AXMLReader.java
/** * Populate the specified CAS by a text and annotations from the specified * input assuming that it is formatted as described above. * * @param in input Reader. It is a caller's responsibility to close this * reader instance./*from ww w. ja v a 2 s .c o m*/ * @param cas CAS * @throws IOException * @throws SAXException */ public static void read(Reader in, final CAS cas) throws IOException, SAXException { XMLReader xmlReader = XMLReaderFactory.createXMLReader(); AXMLContentHandler contentHandler = new AXMLContentHandler(cas.getTypeSystem()); xmlReader.setContentHandler(contentHandler); InputSource inputSource = new InputSource(in); xmlReader.parse(inputSource); cas.setDocumentText(contentHandler.getText()); // from axml ID to CAS FS final Map<Annotation, FeatureStructure> mapped = Maps.newHashMap(); List<Runnable> delayedFeatureAssignments = Lists.newLinkedList(); // for (Annotation _anno : contentHandler.getAnnotations()) { String typeName = _anno.getType(); Type type = cas.getTypeSystem().getType(typeName); if (type == null) { throw new IllegalStateException(String.format("Unknown type: %s", typeName)); } final AnnotationFS anno = cas.createAnnotation(type, _anno.getBegin(), _anno.getEnd()); // set primitive features for (String featName : _anno.getFeatureNames()) { final Feature feat = type.getFeatureByBaseName(featName); if (feat == null) throw new IllegalStateException( String.format("%s does not have feature %s", type.getName(), featName)); if (feat.getRange().isPrimitive()) { String featValStr = _anno.getFeatureStringValue(featName); if (featValStr != null) { anno.setFeatureValueFromString(feat, featValStr); } } else { if (feat.getRange().isArray()) { final List<Annotation> srcFSes = _anno.getFeatureFSArrayValue(featName); delayedFeatureAssignments.add(new Runnable() { @Override public void run() { List<FeatureStructure> mappedFSes = Lists.transform(srcFSes, new Function<Annotation, FeatureStructure>() { @Override public FeatureStructure apply(Annotation srcFS) { FeatureStructure mappedFS = mapped.get(srcFS); if (mappedFS == null) throw new IllegalStateException(); return mappedFS; } }); anno.setFeatureValue(feat, FSCollectionFactory.createArrayFS(cas, mappedFSes)); } }); } else { final Annotation srcFS = _anno.getFeatureFSValue(featName); delayedFeatureAssignments.add(new Runnable() { @Override public void run() { FeatureStructure mappedFS = mapped.get(srcFS); if (mappedFS == null) throw new IllegalStateException(); anno.setFeatureValue(feat, mappedFS); } }); } } } cas.addFsToIndexes(anno); mapped.put(_anno, anno); } // PHASE II -- set FS and FSArray features for (Runnable r : delayedFeatureAssignments) { r.run(); } }
From source file:com.google.jenkins.plugins.googlecontainerregistryauth.GoogleContainerRegistryCredentialProvider.java
/** {@inheritDoc} */ @Override/*w ww . ja v a 2 s . c o m*/ @NonNull public <C extends Credentials> List<C> getCredentials(@NonNull Class<C> type, ItemGroup itemGroup, Authentication authentication, @NonNull List<DomainRequirement> domainRequirements) { if (!ACL.SYSTEM.equals(authentication)) { return ImmutableList.of(); } // This provider only provides // {@link GoogleContainerRegistryCredential} // instances (and not, for example, the GoogleRobotCredentials we depend on, // which endangers an infinite loop). We can stop fast if this Credential // type is not useful to the query. if (!type.isAssignableFrom(GoogleContainerRegistryCredential.class)) { return ImmutableList.of(); } List<C> derived = Lists.newLinkedList(); // GoogleContainerRegistryCredential can only be used from contexts // consistent with is access needs. This is the first line of Domain access // protection; we won't even suggest these credentials for contexts where // it is not plausibly appropriate to. if (!GoogleContainerRegistryCredentialModule.matches(domainRequirements)) { return derived; } // The second line of Domain protection propagates the requirements when // looking up existing GoogleRobotCredentials to ensure we do not suggest // elevating an inappropriate GoogleRobotCredentials instance. Iterable<GoogleRobotCredentials> availableGoogleCredentials = lookupCredentials( GoogleRobotCredentials.class, itemGroup, ACL.SYSTEM, ImmutableList.<DomainRequirement>of(GoogleContainerRegistryCredentialModule.getScope())); for (GoogleRobotCredentials credentials : availableGoogleCredentials) { // Second line of Domain protection; we will not suggest a // the credential we create must have // its implementation constraints satisfied by the DomainRequirements // input (if any; empty lists create no tests). derived.add((C) new GoogleContainerRegistryCredential(credentials.getId(), new GoogleContainerRegistryCredentialModule())); } return derived; }
From source file:org.opennms.newts.cassandra.search.CassandraResourceTreeWalker.java
/** * Visits all nodes in the resource tree bellow the given resource using * breadth-first search.// w w w. j a va 2 s . c o m */ public void breadthFirstSearch(Context context, SearchResultVisitor visitor, Resource root) { Queue<Resource> queue = Lists.newLinkedList(); queue.add(root); while (!queue.isEmpty()) { Resource r = queue.remove(); for (SearchResults.Result result : m_searcher.search(context, matchKeyAndValue(Constants.PARENT_TERM_FIELD, r.getId()))) { if (!visitor.visit(result)) { return; } queue.add(result.getResource()); } } }
From source file:javastory.game.quest.QuestRequirement.java
/** Creates a new instance of MapleQuestRequirement */ public QuestRequirement(final int questId, final QuestRequirementType type, final WzData data) { this.type = type; this.questId = questId; switch (type) { case JOB: {/*from www . ja va2s . c o m*/ final List<WzData> child = data.getChildren(); this.dataStore = Lists.newLinkedList(); for (int i = 0; i < child.size(); i++) { final int value = WzDataTool.getInt(child.get(i), -1); final Entry entry = new Entry(i, value); this.dataStore.add(entry); } break; } case SKILL: { final List<WzData> child = data.getChildren(); this.dataStore = Lists.newLinkedList(); for (int i = 0; i < child.size(); i++) { final WzData childdata = child.get(i); this.dataStore.add(new Entry(WzDataTool.getInt(childdata.getChildByPath("id"), 0), WzDataTool.getInt(childdata.getChildByPath("acquire"), 0))); } break; } case QUEST: { final List<WzData> child = data.getChildren(); this.dataStore = Lists.newLinkedList(); for (int i = 0; i < child.size(); i++) { final WzData childdata = child.get(i); this.dataStore.add(new Entry(WzDataTool.getInt(childdata.getChildByPath("id")), WzDataTool.getInt(childdata.getChildByPath("state"), 0))); } break; } case ITEM: { final List<WzData> child = data.getChildren(); this.dataStore = Lists.newLinkedList(); for (int i = 0; i < child.size(); i++) { final WzData childdata = child.get(i); this.dataStore.add(new Entry(WzDataTool.getInt(childdata.getChildByPath("id")), WzDataTool.getInt(childdata.getChildByPath("count"), 0))); } break; } case NPC: case QUEST_COMPLETED: case FAME: case INTERVAL: case MIN_MONSTER_BOOK: case MAX_LEVEL: case MIN_LEVEL: { this.intStore = WzDataTool.getInt(data, -1); break; } case AVAILABLE_UNTIL: { this.stringStore = WzDataTool.getString(data, null); break; } case MONSTER: { final List<WzData> child = data.getChildren(); this.dataStore = Lists.newLinkedList(); for (int i = 0; i < child.size(); i++) { final WzData childdata = child.get(i); this.dataStore.add(new Entry(WzDataTool.getInt(childdata.getChildByPath("id"), 0), WzDataTool.getInt(childdata.getChildByPath("count"), 0))); } break; } case FIELD_ENTER: { final WzData zeroField = data.getChildByPath("0"); if (zeroField != null) { this.intStore = WzDataTool.getInt(zeroField); } else { this.intStore = -1; } break; } } }