Java Code Examples for java.util.LinkedList#descendingIterator()
The following examples show how to use
java.util.LinkedList#descendingIterator() .
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: IOStorageOperator.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @Override public LinkedList<OutputPort> preAutoWire(LinkedList<OutputPort> ports) throws UndefinedParameterError { Class<? extends IOObject> clazz = getSelectedClass(); if (clazz != null) { OutputPort found = null; Iterator<OutputPort> i = ports.descendingIterator(); int which = isParameterSet(PARAMETER_STORE_WHICH) ? getParameterAsInt(PARAMETER_STORE_WHICH) : 0; int hits = 0; while (i.hasNext()) { OutputPort port = i.next(); if (port.getMetaData() != null && clazz.isAssignableFrom(port.getMetaData().getObjectClass())) { hits++; if (hits == which) { found = port; i.remove(); break; } } } if (found != null) { ports.addLast(found); } } return ports; }
Example 2
Source File: LowestCommonAncestorOfABinaryTree.java From pengyifan-leetcode with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null || p == null || q == null) { return null; } LinkedList<TreeNode> pList = new LinkedList<>(); LinkedList<TreeNode> qList = new LinkedList<>(); findPath(root, p, pList); findPath(root, q, qList); Iterator<TreeNode> itr = qList.descendingIterator(); while (itr.hasNext()) { TreeNode t = itr.next(); if (pList.contains(t)) { return t; } } return null; }
Example 3
Source File: StatsItemAggregationEntry.java From java-trader with Apache License 2.0 | 6 votes |
/** * 计算方式: 统计区间内的数据, 计算平均数 */ private double getInstantAvgValue(LinkedList<SampleValueEntry> values, int averageMinutes) { double tv = 0; int tc = 0; SampleValueEntry lastEntry=null; for( Iterator<SampleValueEntry> it=values.descendingIterator(); it.hasNext(); ) { SampleValueEntry entry = it.next(); if( lastEntry==null ) { lastEntry = entry; } if ( (lastEntry.getTime()-entry.getTime())>averageMinutes*60 ) { break; } tv += entry.getValue(); tc++; } BigDecimal v = new BigDecimal(tv, VALUE_CONTEXT); BigDecimal av = v.divide(new BigDecimal(tc), RoundingMode.HALF_UP); return av.doubleValue(); }
Example 4
Source File: StatsItemAggregationEntry.java From java-trader with Apache License 2.0 | 6 votes |
/** * 计算方式: 区间内开始结束两个数据, 计算差值的分钟平均. */ private double getCumulativeAvgValuePerMinute(LinkedList<SampleValueEntry> values, int maxMinutes) { SampleValueEntry lastEntry = values.peekLast(); SampleValueEntry firstEntry = lastEntry; for( Iterator<SampleValueEntry> it=values.descendingIterator(); it.hasNext(); ) { //从后向前逆序 SampleValueEntry entry = it.next(); if ( (lastEntry.getTime()-entry.getTime())>maxMinutes*60 ) { break; } firstEntry = entry; } BigDecimal v = new BigDecimal((lastEntry.getValue()-firstEntry.getValue()), VALUE_CONTEXT); long minutes = ((lastEntry.getTime()-firstEntry.getTime())+30) / 60; if ( minutes<=0 ) { minutes = 1; } BigDecimal av = v.divide(new BigDecimal(minutes), RoundingMode.HALF_UP); return av.doubleValue(); }
Example 5
Source File: ConcurrentArrayListTest.java From threadly with Mozilla Public License 2.0 | 6 votes |
@Test public void removeLastTest() { LinkedList<String> compareList = new LinkedList<>(); for (int i = 0; i < TEST_QTY; i++) { String str = Integer.toString(i); compareList.add(str); testList.add(str); } Iterator<String> it = compareList.descendingIterator(); int removed = 0; while (it.hasNext()) { String next = it.next(); assertTrue(testList.removeLast() == next); removed++; assertEquals(TEST_QTY - removed, testList.size()); assertFalse(testList.peekLast() == next); } }
Example 6
Source File: LinkedListTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Descending iterator iterates through all elements */ public void testDescendingIterator() { LinkedList q = populatedQueue(SIZE); int i = 0; Iterator it = q.descendingIterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } assertEquals(i, SIZE); assertFalse(it.hasNext()); try { it.next(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 7
Source File: LinkedListTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * Descending iterator iterates through all elements */ public void testDescendingIterator() { LinkedList q = populatedQueue(SIZE); int i = 0; Iterator it = q.descendingIterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } assertEquals(i, SIZE); assertFalse(it.hasNext()); try { it.next(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 8
Source File: LinearScanTreeBuilder.java From talkback with Apache License 2.0 | 5 votes |
@Override public TreeScanNode addViewHierarchyToTree( SwitchAccessNodeCompat root, TreeScanNode treeToBuildOn, boolean includeNonActionableItems) { TreeScanNode tree = (treeToBuildOn != null) ? treeToBuildOn : new ClearFocusNode(); LinkedList<SwitchAccessNodeCompat> talkBackOrderList = getNodesInTalkBackOrder(root); Iterator<SwitchAccessNodeCompat> reverseListIterator = talkBackOrderList.descendingIterator(); while (reverseListIterator.hasNext()) { SwitchAccessNodeCompat next = reverseListIterator.next(); tree = addCompatToTree(next, tree, includeNonActionableItems); next.recycle(); } return tree; }
Example 9
Source File: IOSelectOperator.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override protected LinkedList<OutputPort> preAutoWire(LinkedList<OutputPort> readyOutputs) throws OperatorException { getLogger().info("Simulating IOSelectOperator with old stack: " + readyOutputs); Class<? extends IOObject> clazz = getSelectedClass(); boolean deleteOthers = getParameterAsBoolean(PARAMETER_DELETE_OTHERS); int number = getParameterAsInt(PARAMETER_SELECT_WHICH); int hits = 0; OutputPort myPort = null; Iterator<OutputPort> i = readyOutputs.descendingIterator(); int count = 0; while (i.hasNext()) { OutputPort port = i.next(); if (!port.shouldAutoConnect()) { continue; } if (port.getMetaData() != null && clazz.isAssignableFrom(port.getMetaData().getObjectClass())) { hits++; if (hits == number) { myPort = port; i.remove(); } else if (deleteOthers) { count++; i.remove(); } } } if (myPort != null) { readyOutputs.addLast(myPort); getLogger().info("Bringing output port to front: " + myPort.getSpec()); } if (count > 0) { getLogger().info("Deleted " + myPort.getSpec() + " output ports."); } getLogger().info("New stack is: " + readyOutputs); return readyOutputs; }
Example 10
Source File: LinkedListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Descending iterator ordering is reverse FIFO */ public void testDescendingIteratorOrdering() { final LinkedList q = new LinkedList(); q.add(new Integer(3)); q.add(new Integer(2)); q.add(new Integer(1)); int k = 0; for (Iterator it = q.descendingIterator(); it.hasNext();) { assertEquals(++k, it.next()); } assertEquals(3, k); }
Example 11
Source File: JavaPropertyConfiguration.java From incubator-retired-htrace with Apache License 2.0 | 5 votes |
private JavaPropertyConfiguration(LinkedList<String> prefixes) { this.prefixes = new String[prefixes.size()]; int i = 0; for (Iterator<String> it = prefixes.descendingIterator(); it.hasNext(); ) { this.prefixes[i++] = it.next(); } }
Example 12
Source File: Slf4jLoggingEventListener.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private String formatDetailedSubject( LinkedList<String> subjects ) { StringBuilder string = new StringBuilder(); for ( Iterator<String> it = subjects.descendingIterator(); it.hasNext(); ) { string.append( it.next() ); if ( it.hasNext() ) { string.append( " " ); } } return string.toString(); }
Example 13
Source File: T59.java From cs-summary-reflection with Apache License 2.0 | 5 votes |
public ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) { ArrayList<ArrayList<Integer>> ret = new ArrayList<>(); if (null == pRoot) { return ret; } ArrayList<Integer> list = new ArrayList<>(); LinkedList<TreeNode> queue = new LinkedList<>(); queue.addLast(null); // 层分隔符 queue.addLast(pRoot); boolean leftToRight = true; while (queue.size() != 1) { TreeNode node = queue.removeFirst(); if (null == node) { Iterator<TreeNode> iter = null; if (leftToRight) { iter = queue.iterator(); } else { iter = queue.descendingIterator(); } leftToRight = !leftToRight; while (iter.hasNext()) { TreeNode temp = iter.next(); list.add(temp.val); } ret.add(new ArrayList<>(list)); list.clear(); queue.addLast(null); continue; } if (node.left != null) { queue.addLast(node.left); } if (node.right != null) { queue.addLast(node.right); } } return ret; }
Example 14
Source File: LinkedListTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * descendingIterator.remove removes current element */ public void testDescendingIteratorRemove() { final LinkedList q = new LinkedList(); q.add(three); q.add(two); q.add(one); Iterator it = q.descendingIterator(); it.next(); it.remove(); it = q.descendingIterator(); assertSame(it.next(), two); assertSame(it.next(), three); assertFalse(it.hasNext()); }
Example 15
Source File: PrintBinaryTreeZigzag.java From SwordToOffer with Apache License 2.0 | 5 votes |
public ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); //利用存放多个列表的列表存放最终结果 if (pRoot == null) return result; ArrayList<Integer> list = new ArrayList<Integer>(); //利用一个列表存放每一层的顺序或逆序二叉树元素 LinkedList<TreeNode> queue = new LinkedList<TreeNode>(); //利用双向链表进行顺序和逆序的遍历,模拟队列 queue.addLast(null); //将null作为每层的分隔符 queue.addLast(pRoot); //一开始先放入根节点 boolean leftToRight = true; //第一层只有根节点,算是从左到右遍历 while (queue.size() != 1) { //当“队列”中至少包含一个层分隔符和一个元素时,执行遍历操作 TreeNode node = queue.removeFirst(); //node作为遍历一层层二叉树元素的游标 if (node == null) { //当“队列”中在这一层弹出的第一个元素是层分隔符时,检查遍历顺序应该从左往右还是从右往左 Iterator<TreeNode> iter = null; if (leftToRight) { //如果遍历方式表明从左往右,则将“队列”迭代器置为顺序迭代器 iter = queue.iterator(); } else { //如果遍历方式为从右往左,则将“队列”迭代器置为逆序迭代器 iter = queue.descendingIterator(); } leftToRight = !leftToRight; //下一层遍历时与这一层遍历方式相反,所以要改变遍历方式 while (iter.hasNext()) { //当迭代器表明“队列”中还有下一个元素,将元素值添加进包含这一层元素的列表中 TreeNode temp = (TreeNode) iter.next(); list.add(temp.val); } result.add(new ArrayList<Integer>(list)); //这一层元素添加到列表中后,将该列表添加到结果总列表中,这里要添加新列表对象,否则每一层都指向同一个list list.clear(); //为了节省内存,list作为方法的全局变量,所以一层用过后要将list清空用来存放下一层的元素 queue.addLast(null); //这一层遍历完后,再插入一个层分隔符 continue; //当“队列”遍历到层分隔符null时,此时没指向任何节点元素,就不存在左右子树节点,跳过下面的if判断进行“队列”中下一个元素的判断 } if (node.left != null) { //当前node游标遍历到的元素不是层分隔符,是节点而且该节点有左右子节点时,将左右子节点添加进“队列” queue.addLast(node.left); } if (node.right != null) { queue.addLast(node.right); } } return result; }
Example 16
Source File: MCTSAI.java From magarena with GNU General Public License v3.0 | 5 votes |
private Runnable genBackpropagationTask(final double score, final LinkedList<MCTSGameTree> path) { return () -> { final Iterator<MCTSGameTree> iter = path.descendingIterator(); MCTSGameTree child = null; MCTSGameTree parent = null; while (iter.hasNext()) { child = parent; parent = iter.next(); parent.removeVirtualLoss(); parent.updateScore(child, score); } }; }
Example 17
Source File: Slf4jLoggingEventListener.java From hop with Apache License 2.0 | 5 votes |
private String formatDetailedSubject( LinkedList<String> subjects ) { StringBuilder string = new StringBuilder(); for ( Iterator<String> it = subjects.descendingIterator(); it.hasNext(); ) { string.append( it.next() ); if ( it.hasNext() ) { string.append( " " ); } } return string.toString(); }
Example 18
Source File: ExecutionUnit.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void autoWire(CompatibilityLevel level, InputPorts inputPorts, LinkedList<OutputPort> readyOutputs) throws PortException { boolean success = false; do { Set<InputPort> complete = new HashSet<>(); for (InputPort in : inputPorts.getAllPorts()) { success = false; if (!in.isConnected() && !complete.contains(in) && in.getPorts().getOwner().getOperator().shouldAutoConnect(in)) { Iterator<OutputPort> outIterator; // TODO: Simon: Does the same in both cases. Check again. if (in.simulatesStack()) { outIterator = readyOutputs.descendingIterator(); } else { outIterator = readyOutputs.descendingIterator(); } while (outIterator.hasNext()) { OutputPort outCandidate = outIterator.next(); // TODO: Remove shouldAutoConnect() in later versions Operator owner = outCandidate.getPorts().getOwner().getOperator(); if (owner.shouldAutoConnect(outCandidate) && outCandidate.getMetaData() != null && in.isInputCompatible(outCandidate.getMetaData(), level)) { readyOutputs.remove(outCandidate); outCandidate.connectTo(in); // we cannot continue with the remaining input ports // since connecting may have triggered the creation of new input // ports // which would result in undefined behavior and a // ConcurrentModificationException success = true; break; } } // no port found. complete.add(in); if (success) { break; } } } } while (success); }
Example 19
Source File: SimpleCatalogUtilsService.java From mobi with GNU Affero General Public License v3.0 | 3 votes |
/** * Gets an iterator which contains all of the Commit ids, filtered by a Commit containing the Entity id in its * additions or deletions, in the specified direction, either ascending or descending by date. If descending, * the provided Resource identifying a Commit will be first. * * @param commitId The Resource identifying the Commit that you want to get the chain for. * @param entityId The Resource identifying the Entity that you want to get the chain for. * @param conn The RepositoryConnection which will be queried for the Commits. * @param asc Whether or not the iterator should be ascending by date * @return Iterator of Resource ids for the requested Commits. */ private Iterator<Resource> getCommitChainIterator(Resource commitId, Resource entityId, boolean asc, RepositoryConnection conn) { TupleQuery query = conn.prepareTupleQuery(GET_COMMIT_ENTITY_CHAIN); query.setBinding(COMMIT_BINDING, commitId); query.setBinding(ENTITY_BINDING, entityId); TupleQueryResult result = query.evaluate(); LinkedList<Resource> commits = new LinkedList<>(); result.forEach(bindings -> commits.add(Bindings.requiredResource(bindings, PARENT_BINDING))); return asc ? commits.descendingIterator() : commits.iterator(); }
Example 20
Source File: StreamDefinitionServiceUtils.java From spring-cloud-dataflow with Apache License 2.0 | 2 votes |
/** * Return an iterator that indicates the order of application deployments for this * stream. The application definitions are returned in reverse order; i.e. the sink is * returned first followed by the processors in reverse order followed by the source. * * @return iterator that iterates over the application definitions in deployment order */ public static Iterator<StreamAppDefinition> getDeploymentOrderIterator(LinkedList<StreamAppDefinition> streamAppDefinitions) { return new ReadOnlyIterator<>(streamAppDefinitions.descendingIterator()); }