Java Code Examples for java.util.LinkedList#add()
The following examples show how to use
java.util.LinkedList#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Hypothesis.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
public Hypothesis subsume(Hypothesis otherHypothesis) { LinkedList<Literal> newLiterals = new LinkedList<>(); for (Literal otherLiteral : otherHypothesis.literalMap.values()) { Literal correspondingLiteral = literalMap.get(otherLiteral.getAttribute()); if (correspondingLiteral == null) { continue; } if (otherLiteral.equals(correspondingLiteral)) { newLiterals.add(otherLiteral); continue; } if (otherLiteral.contradicts(literalMap.get(otherLiteral.getAttribute()))) { return null; } } return new Hypothesis(newLiterals); }
Example 2
Source File: ProfileStackNode.java From skywalking with Apache License 2.0 | 6 votes |
/** * combine from other {@link ProfileStackNode} */ public ProfileStackNode combine(ProfileStackNode node) { // combine this node this.combineDetectedStacks(node); // merge tree using LDR to traversal tree node // using stack to avoid recursion // merge key.children <- value.children LinkedList<Pair<ProfileStackNode, ProfileStackNode>> stack = new LinkedList<>(); stack.add(new Pair<>(this, node)); while (!stack.isEmpty()) { Pair<ProfileStackNode, ProfileStackNode> needCombineNode = stack.pop(); // merge value children to key // add to stack if need to keep traversal combineChildrenNodes(needCombineNode.key, needCombineNode.value, stack::add); } return this; }
Example 3
Source File: LeetCode60.java From Project with Apache License 2.0 | 6 votes |
private LinkedList<Integer> backTrace(int n, int k, boolean[] used, LinkedList<Integer> path) { if (path.size() == n) { ++count; return path; } for (int i = 1; i <= n; i++) { if (!used[i]) { used[i] = true; path.add(i); path = backTrace(n, k, used, path); if (count == k) { return path; } used[i] = false; path.removeLast(); } } return path; }
Example 4
Source File: ParserTest.java From promregator with Apache License 2.0 | 6 votes |
@Test public void testCounterWithTimestampAndEmptyLine() { String textToParse = "# Simple metric without labels:\n" + "# TYPE metric_without_labels counter\n" + "\n"+ "metric_without_labels 12.47 123456789012345600\n"; Parser subject = new Parser(textToParse); HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse(); Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values()); // creating expected result LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>(); List<Sample> samples = new LinkedList<>(); Sample sample = new Sample("metric_without_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47); samples.add(sample); Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.COUNTER, "", samples); expectedList.add(expectedMFS); Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList); // compare compareEMFS(expected, result); }
Example 5
Source File: ElementRenderer.java From text-ui with GNU General Public License v3.0 | 6 votes |
@Override public LineRenderer renderer(Iterator<Element> stream) { if (stream.hasNext()) { Element element = stream.next(); if (stream.hasNext()) { LinkedList<LineRenderer> renderers = new LinkedList<LineRenderer>(); renderers.add(element.renderer()); while (stream.hasNext()) { element = stream.next(); renderers.add(element.renderer()); } return LineRenderer.vertical(renderers); } else { return element.renderer(); } } else { throw new UnsupportedOperationException("todo"); } }
Example 6
Source File: CladeTraversal.java From act with GNU General Public License v3.0 | 5 votes |
/** * The function creates a ordered list of chemicals from src to dst. * * @param src - The src id * @param dst - The dst id * @return Returns a list of ids from src to dst. */ public LinkedList<Long> pathFromSrcToDerivativeOfSrc(Long src, Long dst) { LinkedList<Long> result = new LinkedList<>(); Long id = dst; result.add(id); while (!id.equals(src)) { Long newId = this.actData.getActTree().parents.get(id); result.add(newId); id = newId; } Collections.reverse(result); return result; }
Example 7
Source File: InstructionComparator.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
public static List<AbstractInsnNode> insnListFindEnd(InsnList haystack, InsnList needle) { LinkedList<AbstractInsnNode> callNodes = new LinkedList<AbstractInsnNode>(); for (int callPoint : insnListFind(haystack, needle)) { callNodes.add(haystack.get(callPoint + needle.size() - 1)); } return callNodes; }
Example 8
Source File: ParcelableTester.java From mv2m with Apache License 2.0 | 5 votes |
private static void writeList(LinkedList<Object> parcelData, InvocationOnMock invocation, List<Parcelable> list) { if (list == null) { parcelData.add(-1); } else { parcelData.add(list.size()); for (Parcelable item : list) { writeParcelable(parcelData, item, (Parcel) invocation.getMock()); } } }
Example 9
Source File: MismatchValues.java From pattern-matching with Apache License 2.0 | 5 votes |
private void addLinkToMismatchMap(HashMap<String, HashMap<Integer, TreeSet<MismatchValueAndRelationship>>> map, String key1, int key2, double mismatch, String relationshipID) { if (map.containsKey(key1)) { // If there are multiple links from i to j, store the smallest mismatch value (naturally sorted by treeset) if (map.get(key1).containsKey(key2)) { if (map.get(key1).get(key2).size() >= 2 && mismatch >= map.get(key1).get(key2).first().getMismatch()) { return; // already have top 2, no need to update } // need to populate first two or mismatch is actually lower map.get(key1).get(key2).add(new MismatchValueAndRelationship(mismatch, relationshipID)); LinkedList<MismatchValueAndRelationship> removeList = new LinkedList<MismatchValueAndRelationship>(); int count = 0; for (MismatchValueAndRelationship mvr : map.get(key1).get(key2)) { count++; if (count > 2) { removeList.add(mvr); // take top 2 } } for (MismatchValueAndRelationship remove : removeList) { map.get(key1).get(key2).remove(remove); } } else { map.get(key1).put(key2, new TreeSet<MismatchValueAndRelationship>()); // init map.get(key1).get(key2).add(new MismatchValueAndRelationship(mismatch, relationshipID)); } } else { // list init map.put(key1, new HashMap<Integer, TreeSet<MismatchValueAndRelationship>>()); map.get(key1).put(key2, new TreeSet<MismatchValueAndRelationship>()); map.get(key1).get(key2).add(new MismatchValueAndRelationship(mismatch, relationshipID)); } }
Example 10
Source File: DB.java From jelectrum with MIT License | 5 votes |
public void addScriptHashToTxMap(Collection<Map.Entry<ByteString, Sha256Hash> > lst) { LinkedList<Map.Entry<ByteString, ByteString>> out = new LinkedList<>(); for(Map.Entry<ByteString, Sha256Hash> me : lst) { out.add(new SimpleEntry<ByteString, ByteString>(me.getKey(), ByteString.copyFrom(me.getValue().getBytes()))); } pubkey_to_tx_map.addAll(out); }
Example 11
Source File: ModularParser.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
/** * Building a ContentElement from a single line. But the result is given, so * e.g. a NestedListElement can be filled with information... */ private ContentElement parseContentElement(SpanManager sm, ContentElementParsingParameters cepp, Span lineSpan, ContentElement result) { LinkedList<Span> lineSpans = new LinkedList<Span>(); lineSpans.add(lineSpan); return parseContentElement(sm, cepp, lineSpans, result); }
Example 12
Source File: BrooklynJacksonSerializerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testLinkedListSerialization() throws Exception { LinkedList<Object> ll = new LinkedList<Object>(); ll.add(1); ll.add("two"); String result = checkSerializesAs(ll, null); log.info("LLIST json is: "+result); Assert.assertFalse(result.contains("error"), "Shouldn't have had an error, instead got: "+result); Assert.assertEquals(Strings.collapseWhitespace(result, ""), "[1,\"two\"]"); }
Example 13
Source File: NestedClassProcessor.java From javaide with GNU General Public License v3.0 | 5 votes |
private static Statement findFirstBlock(Statement stat, Set<Statement> setStats) { LinkedList<Statement> stack = new LinkedList<>(); stack.add(stat); while (!stack.isEmpty()) { Statement st = stack.remove(0); if (stack.isEmpty() || setStats.contains(st)) { if (st.isLabeled() && !stack.isEmpty() || st.getExprents() != null) { return st; } stack.clear(); //noinspection Duplicates switch (st.type) { case Statement.TYPE_SEQUENCE: stack.addAll(0, st.getStats()); break; case Statement.TYPE_IF: case Statement.TYPE_ROOT: case Statement.TYPE_SWITCH: case Statement.TYPE_SYNCRONIZED: stack.add(st.getFirst()); break; default: return st; } } } return null; }
Example 14
Source File: Beatmap.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Sets the {@link #combo} field from a string. * @param s the string */ public void comboFromString(String s) { if (s == null) return; LinkedList<Color> colors = new LinkedList<Color>(); String[] tokens = s.split("\\|"); for (int i = 0; i < tokens.length; i++) { String[] rgb = tokens[i].split(","); colors.add(new Color(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))); } if (!colors.isEmpty()) this.combo = colors.toArray(new Color[colors.size()]); }
Example 15
Source File: GroupEventTimeBatchWindow.java From PoseidonX with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected void processGroupedEvent(Object subViews, IDataCollection subCollection, Object groupKey, IEvent theEvent) { @SuppressWarnings("unchecked") LinkedList<IEvent> curData = (LinkedList<IEvent>)curDataPerKey.get(groupKey); Long oldestTime = curOldestTimePerKey.get(groupKey); long timestamp = getTimestamp(theEvent); IEvent[] curBatch = null; if (oldestTime != null && curData != null) { if (timestamp - oldestTime >= getKeepTime()) { curBatch = curData.toArray(new IEvent[curData.size()]); curData.clear(); oldestTime = null; } } if (curData == null) { curData = new LinkedList<IEvent>(); curDataPerKey.put(groupKey, curData); } curData.add(theEvent); if (oldestTime == null) { oldestTime = timestamp; } curOldestTimePerKey.put(groupKey, oldestTime); if (curBatch != null) { IEvent[] lastBatch = (IEvent[])lastBatchPerKey.get(groupKey); if (subCollection != null) { subCollection.update(curBatch, lastBatch); } if (null != subViews) { if (subViews instanceof IView) { ((IView)subViews).update(curBatch, lastBatch); } } lastBatch = curBatch; lastBatchPerKey.put(groupKey, lastBatch); } }
Example 16
Source File: DownloadManager.java From MHViewer with Apache License 2.0 | 4 votes |
public DownloadManager(Context context) { mContext = context; // Get all labels List<DownloadLabel> labels = EhDB.getAllDownloadLabelList(); mLabelList = labels; // Create list for each label HashMap<String, LinkedList<DownloadInfo>> map = new HashMap<>(); mMap = map; for (DownloadLabel label : labels) { map.put(label.getLabel(), new LinkedList<DownloadInfo>()); } // Create default for non tag mDefaultInfoList = new LinkedList<>(); // Get all info List<DownloadInfo> allInfoList = EhDB.getAllDownloadInfo(); mAllInfoList = new LinkedList<>(allInfoList); // Create all info map HashMap<String,DownloadInfo> allInfoMap = new HashMap<>(allInfoList.size() + 10); mAllInfoMap = allInfoMap; for (int i = 0, n = allInfoList.size(); i < n; i++) { DownloadInfo info = allInfoList.get(i); // Add to all info map allInfoMap.put(info.gid, info); // Add to each label list LinkedList<DownloadInfo> list = getInfoListForLabel(info.label); if (list == null) { // Can't find the label in label list list = new LinkedList<>(); map.put(info.label, list); if (!containLabel(info.label)) { // Add label to DB and list labels.add(EhDB.addDownloadLabel(info.label)); } } list.add(info); } mWaitList = new LinkedList<>(); mSpeedReminder = new SpeedReminder(); mDownloadInfoListeners = new ArrayList<>(); }
Example 17
Source File: LeftSQLTemplate.java From quetzal with Eclipse Public License 2.0 | 4 votes |
LinkedList<String> getTargetMapping(){ LinkedList<String> targetMapping = new LinkedList<String>(); targetMapping.add(wrapper.getPlanNodeCTE(left, true)); targetMapping.add(wrapper.getPlanNodeCTE(right, true)); return targetMapping; }
Example 18
Source File: SwitchStringRewriter.java From cfr with MIT License | 4 votes |
private StructuredSwitch rewriteSwitch(StructuredSwitch original, SwitchStringMatchResultCollector matchResultCollector) { Op04StructuredStatement body = original.getBody(); BlockIdentifier blockIdentifier = original.getBlockIdentifier(); StructuredStatement inner = body.getStatement(); if (!(inner instanceof Block)) { throw new FailedRewriteException("Switch body is not a block, is a " + inner.getClass()); } Block block = (Block) inner; Map<Integer, List<String>> replacements = matchResultCollector.getValidatedHashes(); List<Op04StructuredStatement> caseStatements = block.getBlockStatements(); LinkedList<Op04StructuredStatement> tgt = ListFactory.newLinkedList(); InferredJavaType typeOfSwitch = matchResultCollector.getStringExpression().getInferredJavaType(); for (Op04StructuredStatement op04StructuredStatement : caseStatements) { inner = op04StructuredStatement.getStatement(); if (!(inner instanceof StructuredCase)) { throw new FailedRewriteException("Block member is not a case, it's a " + inner.getClass()); } StructuredCase structuredCase = (StructuredCase) inner; List<Expression> values = structuredCase.getValues(); List<Expression> transformedValues = ListFactory.newList(); for (Expression value : values) { Integer i = getInt(value); List<String> replacementStrings = replacements.get(i); if (replacementStrings == null) { throw new FailedRewriteException("No replacements for " + i); } for (String s : replacementStrings) { transformedValues.add(new Literal(TypedLiteral.getString(s))); } } StructuredCase replacementStructuredCase = new StructuredCase(transformedValues, typeOfSwitch, structuredCase.getBody(), structuredCase.getBlockIdentifier()); tgt.add(new Op04StructuredStatement(replacementStructuredCase)); } Block newBlock = new Block(tgt, true); Expression switchOn = matchResultCollector.getStringExpression(); // If the literal is a naughty null, we need to expressly force it to a string. // Don't cast to its own type, as this might be a null type. if (switchOn.equals(Literal.NULL)) { switchOn = new CastExpression(new InferredJavaType(TypeConstants.STRING, InferredJavaType.Source.EXPRESSION), switchOn, true); } return new StructuredSwitch( switchOn, new Op04StructuredStatement(newBlock), blockIdentifier, false); }
Example 19
Source File: NodeNormalizerTest.java From semantic-knowledge-graph with Apache License 2.0 | 4 votes |
@Test public void populateNorms() { NodeNormalizer target = new NodeNormalizer(); FacetFieldAdapter adapter = new FacetFieldAdapter("testField"); AggregationWaitable runner = new AggregationWaitable(context, adapter, "testField", 0, 1); runner.buckets = new LinkedList<>(); runner.adapter = adapter; SimpleOrderedMap<Object> bucket1 = new SimpleOrderedMap<>(); bucket1.add("val", "testValue1"); bucket1.add("id", "1"); SimpleOrderedMap<Object> bucket2 = new SimpleOrderedMap<>(); bucket2.add("val", "testValue2"); bucket2.add("id", "2"); SimpleOrderedMap<Object> bucket3 = new SimpleOrderedMap<>(); bucket3.add("val", "value3"); bucket3.add("id", "3"); runner.buckets.add(bucket1); runner.buckets.add(bucket2); runner.buckets.add(bucket3); String requestValue1 = "testValue1"; String requestValue2 = "testValue2"; LinkedList<String> normalizedStrings = new LinkedList<>(); LinkedList<SimpleOrderedMap<String>> normalizedMaps = new LinkedList<>(); String [] expectedStrings = new String [] {"testValue1", "testValue2"}; LinkedList<SimpleOrderedMap<String>> expectedMaps = new LinkedList<>(); SimpleOrderedMap<String> map1 = new SimpleOrderedMap<>(); map1.add("name", "testValue1"); map1.add("id", "1"); SimpleOrderedMap<String> map2 = new SimpleOrderedMap<>(); map2.add("name", "testValue2"); map2.add("id", "2"); expectedMaps.add(map1); expectedMaps.add(map2); Deencapsulation.invoke(target, "populateNorms", runner, requestValue1, normalizedStrings, normalizedMaps); Deencapsulation.invoke(target, "populateNorms", runner, requestValue2, normalizedStrings, normalizedMaps); Assert.assertEquals(2, normalizedStrings.size()); Assert.assertEquals(2, normalizedMaps.size()); for(int i = 0; i < expectedStrings.length ; ++i) { Assert.assertEquals(expectedMaps.get(i),normalizedMaps.get(i)); Assert.assertEquals(expectedStrings[i],normalizedStrings.get(i)); } }
Example 20
Source File: FinallyProcessor.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
private boolean processStatementEx(StructMethod mt, RootStatement root, ControlFlowGraph graph) { int bytecode_version = mt.getClassStruct().getBytecodeVersion(); LinkedList<Statement> stack = new LinkedList<>(); stack.add(root); while (!stack.isEmpty()) { Statement stat = stack.removeLast(); Statement parent = stat.getParent(); if (parent != null && parent.type == Statement.TYPE_CATCHALL && stat == parent.getFirst() && !parent.isCopied()) { CatchAllStatement fin = (CatchAllStatement) parent; BasicBlock head = fin.getBasichead().getBlock(); BasicBlock handler = fin.getHandler().getBasichead().getBlock(); if (catchallBlockIDs.containsKey(handler.id)) { // do nothing } else if (finallyBlockIDs.containsKey(handler.id)) { fin.setFinally(true); Integer var = finallyBlockIDs.get(handler.id); fin.setMonitor(var == null ? null : new VarExprent(var.intValue(), VarType.VARTYPE_INT, varProcessor)); } else { Record inf = getFinallyInformation(mt, root, fin); if (inf == null) { // inconsistent finally catchallBlockIDs.put(handler.id, null); } else { if (DecompilerContext.getOption(IFernflowerPreferences.FINALLY_DEINLINE) && verifyFinallyEx(graph, fin, inf)) { finallyBlockIDs.put(handler.id, null); } else { int varindex = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER); insertSemaphore(graph, getAllBasicBlocks(fin.getFirst()), head, handler, varindex, inf, bytecode_version); finallyBlockIDs.put(handler.id, varindex); } DeadCodeHelper.removeDeadBlocks(graph); // e.g. multiple return blocks after a nested finally DeadCodeHelper.removeEmptyBlocks(graph); DeadCodeHelper.mergeBasicBlocks(graph); } return true; } } stack.addAll(stat.getStats()); } return false; }