// Must move to an element after add(): // it.next(); // Remove the element that was just produced: // it.remove(); // Must move to an element after remove(): // it.next(); // Change the element that was just produced: // it.set("47"); public static void testVisual(List a) { print(a); List b = new ArrayList(); fill(b); System.out.print("b = "); print(b); a.addAll(b); a.addAll(fill(new ArrayList())); print(a); // Shrink the list by removing all the elements beyond the first 1/2 of the list System.out.println(a.size()); System.out.println(a.size() / 2); // a.removeRange(a.size()/2, a.size()/2 + 2); print(a); // Insert, remove, and replace elements // using aListIterator: ListIterator x = a.listIterator(a.size() / 2); x.add("one"); print(a); System.out.println(x.next()); x.remove(); System.out.println(x.next()); x.set("47"); print(a); // Traverse the list backwards: x = a.listIterator(a.size()); while (x.hasPrevious()) System.out.print(x.previous() + " "); System.out.println(); System.out.println("testVisual finished"); }
/** * Adds all ports of given {@link LoopSide} of this component-holder to the current position of * the {@link ListIterator}. The ports are placed, so that source and target ports of an edge * are placed next to each other. The target port of an edge will be places before the source * port of an edge. * * @param loopSide The components of this {@link LoopSide} will be added. * @param itr The {@link ListIterator} to add the ports into. */ public void addInlineTargetsFirst(final LoopSide loopSide, final ListIterator<LPort> itr) { final List<LPort> firstPart = Lists.newArrayList(); final List<LPort> secondPart = Lists.newArrayList(); final Iterator<ConnectedSelfLoopComponent> compItr = LISTS_OF_COMPONENTS.get(loopSide).iterator(); while (compItr.hasNext()) { ConnectedSelfLoopComponent component = compItr.next(); firstPart.addAll(0, component.getSourceLoopPorts()); firstPart.addAll(0, component.getTargetLoopPortsReversed()); if (compItr.hasNext()) { component = compItr.next(); secondPart.addAll(component.getTargetLoopPortsReversed()); secondPart.addAll(component.getSourceLoopPorts()); } } setSideOfPorts(firstPart, loopSide.getTargetSide()); setSideOfPorts(secondPart, loopSide.getSourceSide()); for (final LPort port : firstPart) { itr.add(port); } for (final LPort port : secondPart) { itr.add(port); } }
/** * Adds all target ports and than all source ports of the components of given {@link LoopSide} * of this component-holder to the current position of the {@link ListIterator}. The source * ports will be added in reversed order. * * @param loopSide The components of this {@link LoopSide} will be added. * @param itr The {@link ListIterator} to add the ports into. */ public void addAllPorts( final LoopSide loopSide, final ListIterator<LPort> itr, final boolean sourceFirst) { final List<LPort> secondPart = Lists.newArrayList(); PortSide secondPartSide = null; if (sourceFirst) { for (final ConnectedSelfLoopComponent component : LISTS_OF_COMPONENTS.get(loopSide)) { for (final LPort port : component.getSourceLoopPorts()) { itr.add(port); setSideOfPort(port, loopSide.getSourceSide()); } secondPart.addAll(component.getTargetLoopPorts()); secondPartSide = loopSide.getTargetSide(); } } else { for (final ConnectedSelfLoopComponent component : LISTS_OF_COMPONENTS.get(loopSide)) { for (final LPort port : component.getTargetLoopPorts()) { itr.add(port); setSideOfPort(port, loopSide.getTargetSide()); } secondPart.addAll(component.getSourceLoopPorts()); secondPartSide = loopSide.getSourceSide(); } } Collections.reverse(secondPart); setSideOfPorts(secondPart, secondPartSide); for (final LPort port : secondPart) { itr.add(port); } }
/** * Either adds a value to set or does nothing if value is already present. * * @param val Value to add. * @return The instance of value from this set or {@code null} if value was added. */ @Nullable public V addx(V val) { A.notNull(val, "val"); if (comp == null) { for (V v : vals) if (v.equals(val)) return v; vals.add(val); return null; } if (strict) { for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) { V v = it.next(); // Prefer equals to comparator. if (v.equals(val)) return v; int c = comp.compare(v, val); if (c == 0) throw new IllegalStateException("Inconsistent equals and compare methods."); if (c > 0) { // Back up. it.previous(); it.add(val); return null; } } vals.add(val); return null; } // Full scan first. for (V v : vals) if (v.equals(val)) return v; for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) { V v = it.next(); if (comp.compare(v, val) > 0) { do { // Back up. v = it.previous(); } while (comp.compare(v, val) == 0); it.add(val); return null; } } vals.add(val); return null; }
/** * (Re-)Adds the ports to the node of a component, having at least one port with a non-loop edge. * The ports are added as the direct neighbor of a port they are connected to via an edge. * * @param component The component whose ports have to get re-added. */ public void addComponentWithNonLoopEdges(final ConnectedSelfLoopComponent component) { // the node we are working on final LNode node = component.getNode(); // Set of all ports of the components that are hidden. Initially all ports that CAN be hidden. final Set<LPort> hiddenPorts = Sets.newHashSet(component.getHidablePorts()); // Iterator holding all ports that already have a portSide specified. Initially these are // all ports with an non-loop edge connected to them. While processing the elements, we will // add new ports to this Iterator. So we need a ListIterator. final ListIterator<LPort> portsWithSideIter = Lists.newLinkedList(component.getNonLoopPorts()).listIterator(); while (portsWithSideIter.hasNext()) { final LPort portWithSide = portsWithSideIter.next(); if (portWithSide.getOutgoingEdges().isEmpty()) { // inbound port for (final LEdge edgeWithHiddenPort : portWithSide.getIncomingEdges()) { final LPort hiddenPort = edgeWithHiddenPort.getSource(); if (hiddenPorts.contains(hiddenPort)) { final ListIterator<LPort> nodePortIter = node.getPorts().listIterator(); LPort portOnNode = nodePortIter.next(); // find the port with side ... while (!portOnNode.equals(portWithSide)) { portOnNode = nodePortIter.next(); } // ... and add the hidden port on it's right side nodePortIter.add(hiddenPort); portsWithSideIter.add(hiddenPort); setSideOfPort(hiddenPort, portWithSide.getSide()); // ensure the next element will be our new added element portsWithSideIter.previous(); portsWithSideIter.previous(); hiddenPorts.remove(hiddenPort); } } } else { // outbound port for (final LEdge edgeWithHiddenPort : portWithSide.getOutgoingEdges()) { final LPort hiddenPort = edgeWithHiddenPort.getTarget(); if (hiddenPorts.contains(hiddenPort)) { final ListIterator<LPort> nodePortIter = node.getPorts().listIterator(); LPort portOnNode = nodePortIter.next(); // find the port with side ... while (!portOnNode.equals(portWithSide)) { portOnNode = nodePortIter.next(); } // ... and add the hidden port on it's left side nodePortIter.previous(); nodePortIter.add(hiddenPort); portsWithSideIter.add(hiddenPort); setSideOfPort(hiddenPort, portWithSide.getSide()); // ensure the next element will be our new added element portsWithSideIter.previous(); portsWithSideIter.previous(); hiddenPorts.remove(hiddenPort); } } } } }
/** * ************* 添加指定回合的本时间节点的任务,返回是否添加成功,不成功则表示需要马上执行 * * @author alzq.z * @time Jul 16, 2015 11:26:06 PM */ public boolean addTimingTask(int _round, _IALSynTask _task) { _lock(); try { if (null == _task) return false; // 当本回合的时候,直接进行添加 if (_round == _m_iCurRound) { _m_lCurRoundTimingTaskList.add(_task); return true; } else if (_round == _m_iNextRound) { _m_lNextRoundTimingTaskList.add(_task); return true; } else if (_round > _m_iNextRound) { // 长时间延迟的任务,按照回合顺序放入对应队列 ListIterator<ALSynTimingTaskNodeFarDelayTaskInfo> iterator = _m_lFarDelayTaskList.listIterator(); while (iterator.hasNext()) { ALSynTimingTaskNodeFarDelayTaskInfo taskInfo = iterator.next(); if (taskInfo.getRound() == _round) { // 匹配回合则加入本节点 taskInfo.addSynTask(_task); break; } else if (taskInfo.getRound() < _round) { // 当插入的回合比对应回合早,则需要在对应回合之前插入数据 // 这里采用的做法是将本节点数据重复插入到下一个节点,之后将本节点设置为新数据 iterator.add(taskInfo); // 创建新节点 ALSynTimingTaskNodeFarDelayTaskInfo newInfo = new ALSynTimingTaskNodeFarDelayTaskInfo(_round); iterator.set(newInfo); // 插入任务 newInfo.addSynTask(_task); break; } } // 判断是否已经到了最后节点 if (!iterator.hasNext()) { // 在最后节点则往最后追加数据 // 创建新节点 ALSynTimingTaskNodeFarDelayTaskInfo newInfo = new ALSynTimingTaskNodeFarDelayTaskInfo(_round); iterator.add(newInfo); // 插入任务 newInfo.addSynTask(_task); } return true; } else { // 当回合小于当前回合则表示失败,外部需要直接处理 return false; } } finally { _unlock(); } }
private void addClosureExitBindingStores( IRExecutionScope s, ListIterator<Instr> instrs, Set<LocalVariable> dirtyVars) { for (Variable v : dirtyVars) { if (v instanceof ClosureLocalVariable) { IRClosure definingScope = ((ClosureLocalVariable) v).definingScope; if ((s != definingScope) && s.nestedInClosure(definingScope)) instrs.add(new StoreToBindingInstr(s, v.getName(), v)); } else { instrs.add(new StoreToBindingInstr(s, v.getName(), v)); } } }
private void calculateValueLists() { sequenceValues = new ArrayList<>(); timelineValues = new ArrayList<>(); final Object selectedSequenceColumn = this.sequenceColumnChooser.getSelectedItem(); if (!(selectedSequenceColumn instanceof ManyValuedAttribute)) { return; } final ManyValuedAttribute sequenceAttribute = (ManyValuedAttribute) selectedSequenceColumn; final ManyValuedAttribute timelineAttribute = (ManyValuedAttribute) timelineColumnChooser.getSelectedItem(); for (final FCAElement object : this.context.getObjects()) { Value value = this.context.getRelationship(object, sequenceAttribute); if (!sequenceValues.contains(value) && value != null) { boolean inserted = false; final ListIterator<Value> seqIt = sequenceValues.listIterator(); while (seqIt.hasNext()) { final Value curValue = seqIt.next(); if (value.isLesserThan(curValue)) { if (seqIt.hasPrevious()) { seqIt.previous(); } seqIt.add(value); inserted = true; break; } } if (!inserted) { seqIt.add(value); } } value = this.context.getRelationship(object, timelineAttribute); if (!timelineValues.contains(value) && value != null) { boolean inserted = false; final ListIterator<Value> tlIt = timelineValues.listIterator(); while (tlIt.hasNext()) { final Value curValue = tlIt.next(); if (curValue != null && value.isLesserThan(curValue)) { if (tlIt.hasPrevious()) { tlIt.previous(); } tlIt.add(value); inserted = true; break; } } if (!inserted) { tlIt.add(value); } } } }
/** Test remove() for an immutable ListIterator. */ public void testUnmodifiableListIteratorImmutability() { ListIterator listIterator = getImmutableListIterator(); try { listIterator.remove(); // We shouldn't get to here. fail("remove() should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } try { listIterator.set("a"); // We shouldn't get to here. fail("set(Object) should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } try { listIterator.add("a"); // We shouldn't get to here. fail("add(Object) should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } listIterator.next(); try { listIterator.remove(); // We shouldn't get to here. fail("remove() should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } try { listIterator.set("a"); // We shouldn't get to here. fail("set(Object) should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } try { listIterator.add("a"); // We shouldn't get to here. fail("add(Object) should throw an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // This is correct; ignore the exception. } }
/** Constructs a LinkedList containing the same element as the given Collection. */ public LinkedList(Collection<E> c) { this(); ListIterator<E> iter = this.listIterator(0); for (E item : c) { iter.add(item); } }
public static void main(String[] args) { List<String> a = new LinkedList<>(); a.add("Carl"); a.add("Emma"); a.add("Throl"); List<String> b = new LinkedList<>(); b.add("Robort"); b.add("Lynan"); b.add("Arya"); b.add("Snow"); ListIterator<String> aIterator = a.listIterator(); Iterator<String> bIterator = b.listIterator(); while (bIterator.hasNext()) { if (aIterator.hasNext()) { aIterator.next(); } aIterator.add(bIterator.next()); } System.out.println(a); bIterator = b.iterator(); while (bIterator.hasNext()) { bIterator.next(); if (bIterator.hasNext()) { bIterator.next(); bIterator.remove(); } } System.out.println(b); a.removeAll(b); System.out.println(a); }
/** * Inserts a new {@link Dom} node right after the given DOM element. * * @param reference If null, the new element will be inserted at the very beginning. * @param name The element name of the newly inserted item. "*" to indicate that the element name * be determined by the model of the new node. */ public synchronized void insertAfter(Dom reference, String name, Dom newNode) { // TODO: reparent newNode if (name.equals("*")) name = newNode.model.tagName; NodeChild newChild = new NodeChild(name, newNode); if (children.size() == 0) { children = new ArrayList<Child>(); } if (reference == null) { children.add(0, newChild); newNode.domDescriptor = addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey()); return; } ListIterator<Child> itr = children.listIterator(); while (itr.hasNext()) { Child child = itr.next(); if (child instanceof NodeChild) { NodeChild nc = (NodeChild) child; if (nc.dom == reference) { itr.add(newChild); newNode.domDescriptor = addWithAlias(getHabitat(), newNode, newNode.getProxyType(), newNode.getKey()); return; } } } throw new IllegalArgumentException( reference + " is not a valid child of " + this + ". Children=" + children); }
@Override @Test public void listIterator() { super.listIterator(); CompositeFastList<String> composite = new CompositeFastList<String>(); FastList<String> firstBit = FastList.newListWith("one", "two"); FastList<String> secondBit = FastList.newListWith("three"); composite.addAll(firstBit); composite.addAll(secondBit); ListIterator<String> listIterator = composite.listIterator(); listIterator.add("four"); Verify.assertSize(4, composite); Assert.assertTrue(listIterator.hasNext()); String element = listIterator.next(); Assert.assertEquals("one", element); String element3 = listIterator.next(); Assert.assertEquals("two", element3); String element2 = listIterator.previous(); Assert.assertEquals("two", element2); String element1 = listIterator.next(); Assert.assertEquals("two", element1); listIterator.remove(); Verify.assertSize(3, composite); }
public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) { MethodNode method = getOrAddStaticConstructorNode(); Statement statement = method.getCode(); if (statement instanceof BlockStatement) { BlockStatement block = (BlockStatement) statement; // add given statements for explicitly declared static fields just after enum-special fields // are found - the $VALUES binary expression marks the end of such fields. List<Statement> blockStatements = block.getStatements(); ListIterator<Statement> litr = blockStatements.listIterator(); while (litr.hasNext()) { Statement stmt = litr.next(); if (stmt instanceof ExpressionStatement && ((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) { BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression(); if (bExp.getLeftExpression() instanceof FieldExpression) { FieldExpression fExp = (FieldExpression) bExp.getLeftExpression(); if (fExp.getFieldName().equals("$VALUES")) { for (Statement tmpStmt : staticFieldStatements) { litr.add(tmpStmt); } } } } } } }
public static void addToOrder(String name, Flags after) { List<String> order = FlagComparator.order; boolean added = false; if (after == null) { order.add(name); } else if (after.flags.isEmpty()) { order.add(0, name); } else { for (ListIterator<String> i = order.listIterator(); i.hasNext(); ) { String s = i.next(); after = after.clear(new Flags(s)); if (after.flags.isEmpty()) { i.add(name); added = true; break; } } if (!added) { // shouldn't happen order.add(name); } } }
@Override public boolean incrementToken() throws IOException { while (!done && queue.size() < windowSize) { if (!input.incrementToken()) { done = true; break; } // reverse iterating for better efficiency since we know the // list is already sorted, and most token start offsets will be too. ListIterator<OrderedToken> iter = queue.listIterator(queue.size()); while (iter.hasPrevious()) { if (offsetAtt.startOffset() >= iter.previous().startOffset) { // insertion will be before what next() would return (what // we just compared against), so move back one so the insertion // will be after. iter.next(); break; } } OrderedToken ot = new OrderedToken(); ot.state = captureState(); ot.startOffset = offsetAtt.startOffset(); iter.add(ot); } if (queue.isEmpty()) { return false; } else { restoreState(queue.removeFirst().state); return true; } }
@Override protected void invalidateNode(SNode sNode) { NodePath affPath = NodePath.forSNode(sNode); SModel containingModel = sNode.getContainingModel(); if (containingModel == null) return; SModelReference mref = containingModel.getReference(); List<NodePath> nodePaths = nodePaths(mref); ListIterator<NodePath> npathIt = nodePaths.listIterator(); while (npathIt.hasNext()) { NodePath path = npathIt.next(); NodePath lcp = affPath.findLowestCommonParent(path); if (lcp != null) { if (lcp.equals(path)) break; // replace with the LCP and stop npathIt.remove(); npathIt.add(lcp); break; } } if (!npathIt.hasNext()) { // not found -> just add nodePaths.add(affPath); } }
private List<ChatMessage> sanitizeMap(final SortedMap<Date, ChatMessage> aMap) { if (aMap.isEmpty() || aMap.size() == 1) return Lists.newArrayList(aMap.values()); final LinkedList<ChatMessage> ret = Lists.newLinkedList(aMap.values()); final ListIterator<ChatMessage> i = ret.listIterator(); ChatMessage prevMsg = i.next(); do { ChatMessage msg = i.next(); if (!msg.getPreviousMessageDate().equals(prevMsg.getDate())) { if (msg.getPreviousMessageDate().before(prevMsg.getDate())) { msg.setPreviousMessageDate(prevMsg.getDate()); } else { final ChatMessage tmp = createLostMessageBetween( msg.getRoom(), prevMsg.getDate(), msg.getPreviousMessageDate()); aMap.put(tmp.getDate(), tmp); i.previous(); i.add(tmp); i.next(); msg = tmp; } } prevMsg = msg; } while (i.hasNext()); return ret; }
/** * Overlays this fragment list by some {@link Fragment}. That means that parts that overlap are * taken from the fragment passed. * * @param fragment The fragment. * @return A fragment list storing the overlay result. */ public FragmentList overlayBy(final Fragment fragment) { final FragmentList result = new FragmentList(); try { result.addFragment(fragment); } catch (final IncompatibleFragmentException e) { throw new Error(e); } final PositionInText posTo = fragment.getTo(); final ListIterator<Fragment> it = this.fragments.listIterator(); while (it.hasNext()) { final Fragment oldFragment = it.next(); if (posTo.lessThan(oldFragment.getFrom())) { break; } final ListIterator<Fragment> fIt = result.fragments.listIterator(); while (fIt.hasNext()) { final Fragment f = fIt.next(); final FragmentList rest = f.subtract(oldFragment); fIt.remove(); for (final Fragment newFragment : rest.fragments) { fIt.add(newFragment); } } } try { result.addFragmentList(this); } catch (final IncompatibleFragmentException e) { throw new Error(e); } return result; }
static <T extends Comparable<? super T>> void intersection(List<T> a, List<T> b, List<T> out) { ListIterator<T> aIterator = a.listIterator(); ListIterator<T> bIterator = b.listIterator(); ListIterator<T> outIterator = out.listIterator(); // out=new LinkedList<T>(); try { T aTemp = next(aIterator); T bTemp = next(bIterator); while (aTemp != null && bTemp != null) { if (aTemp.compareTo(bTemp) == 0) { // out.add(aTemp); outIterator.add(aTemp); aTemp = next(aIterator); bTemp = next(bIterator); } else if (aTemp.compareTo(bTemp) < 0) { aTemp = next(aIterator); } else { bTemp = next(bIterator); } } } catch (NullPointerException ex) { System.out.println("The input array(s) is/are empty. Please check!!"); } }
/** * Assigns the mapped colors to the FSTDirectives from the changed document. * * @return the directive list */ private void updateDirectives() { ListIterator<FSTDirective> newDirIt = getNewDirectives().listIterator(0); while (newDirIt.hasNext()) { FSTDirective newDir = newDirIt.next(); FSTDirective oldDir = directiveMap.get(newDir.getId()); if (oldDir != null && newDir.getCommand() == oldDir.getCommand() && newDir.getFeatureName().equals(oldDir.getFeatureName())) { oldDir.setStartLine(newDir.getStartLine(), newDir.getStartOffset()); oldDir.setEndLine(newDir.getEndLine(), newDir.getEndLength()); } else { directiveMap.clear(); return; } if (newDir.hasChildren()) { for (FSTDirective newDirChild : newDir.getChildrenList()) { newDirIt.add(newDirChild); newDirIt.previous(); } } } }
public void reloadStyles() { ListIterator<SectionRecord> k = records.listIterator(); while (k.hasNext()) { SectionRecord record = k.next(); k.remove(); k.add(new SectionRecord(record.getStyleName(), record.getIndex(), record.getIsPhrase())); } }
/** * Inserts the given element after the reference. Throws {@link NoSuchElementException} if the * list does not contain the reference * * @param <A> the list type * @param list the list * @param element the element to be inserted just afeter the reference element * @param reference the reference. The list must contain it */ public static <A> void addAfter(@NonNull List<A> list, A element, A reference) { for (ListIterator<A> iter = list.listIterator(); iter.hasNext(); ) if (ObjectUtils.equals(iter.next(), reference)) { iter.add(element); return; } throw new NoSuchElementException(reference.toString()); }
/** An implementation of {@link List#addAll(int, Collection)}. */ static <E> boolean addAllImpl(List<E> list, int index, Iterable<? extends E> elements) { boolean changed = false; ListIterator<E> listIterator = list.listIterator(index); for (E e : elements) { listIterator.add(e); changed = true; } return changed; }
@Override Object action(ListIterator<?> iterator) { AtomicInteger counter = counters.get(iterator); if (counter == null) { counters.put(iterator, counter = new AtomicInteger(0)); } ((ListIterator) iterator).add(counter.addAndGet(-2)); return null; }
/** * Adds all target ports of the components of given {@link LoopSide} of this component-holder to * the current position of the {@link ListIterator}. * * @param loopSide The components of this {@link LoopSide} will be added. * @param itr The {@link ListIterator} to add the ports into. */ public void addTargetPorts(final LoopSide loopSide, final ListIterator<LPort> itr) { final PortSide portSide = loopSide.getTargetSide(); for (final ConnectedSelfLoopComponent component : LISTS_OF_COMPONENTS.get(loopSide)) { for (final LPort port : component.getTargetLoopPorts()) { itr.add(port); setSideOfPort(port, portSide); } } }
@Override public byte[] transform(String name, String transformedName, byte[] basicClass) { if (!"net.minecraft.item.ItemStack".equals(name)) return basicClass; ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); FieldNode itemField = null; for (FieldNode f : classNode.fields) { if (ITEM_TYPE.equals(f.desc) && itemField == null) { itemField = f; } else if (ITEM_TYPE.equals(f.desc)) { throw new RuntimeException("Error processing ItemStack - found a duplicate Item field"); } } if (itemField == null) { throw new RuntimeException( "Error processing ItemStack - no Item field declared (is the code somehow obfuscated?)"); } MethodNode getItemMethod = null; for (MethodNode m : classNode.methods) { if (GETITEM_DESC.equals(m.desc) && getItemMethod == null) { getItemMethod = m; } else if (GETITEM_DESC.equals(m.desc)) { throw new RuntimeException("Error processing ItemStack - duplicate getItem method found"); } } if (getItemMethod == null) { throw new RuntimeException( "Error processing ItemStack - no getItem method found (is the code somehow obfuscated?)"); } for (MethodNode m : classNode.methods) { for (ListIterator<AbstractInsnNode> it = m.instructions.iterator(); it.hasNext(); ) { AbstractInsnNode insnNode = it.next(); if (insnNode.getType() == AbstractInsnNode.FIELD_INSN) { FieldInsnNode fi = (FieldInsnNode) insnNode; if (itemField.name.equals(fi.name) && fi.getOpcode() == Opcodes.GETFIELD) { it.remove(); MethodInsnNode replace = new MethodInsnNode( Opcodes.INVOKEVIRTUAL, "net/minecraft/item/ItemStack", getItemMethod.name, getItemMethod.desc, false); it.add(replace); } } } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); }
@Override public void add(T e) { if (e != null) { current = null; switch (e.getNodeType()) { case AstNode.NT_NODE_LIST: for (T n : (AstNodeList<T>) e) i.add(n); break; case AstNode.NT_TEXT: addTextIntern((AstStringNode<T>) e); break; default: i.add(e); break; } } }
public void addMessToVectorInSortedOrder(Vector v, MhrEvent ev) { ListIterator iter = v.listIterator(); MhrEvent vEv; while (iter.hasNext()) { vEv = (MhrEvent) iter.next(); if (ev.eventTime.compareTo(vEv.eventTime) >= 0) { iter.previous(); iter.add(ev); return; } } try { iter.add(ev); } catch (UnsupportedOperationException e) { System.out.println(e.toString()); } catch (Exception e) { System.out.println(e.toString()); } }
void collectVals(BucketMap map, boolean sum) throws JRException { ListIterator totalIt = entries.listIterator(); MapEntry totalItEntry = totalIt.hasNext() ? (MapEntry) totalIt.next() : null; Iterator it = map.entryIterator(); Map.Entry entry = it.hasNext() ? (Map.Entry) it.next() : null; while (entry != null) { Bucket key = (Bucket) entry.getKey(); int compare = totalItEntry == null ? -1 : key.compareTo(totalItEntry.key); if (compare <= 0) { Object addVal = null; if (last) { if (sum) { MeasureValue[] totalVals = compare == 0 ? (MeasureValue[]) totalItEntry.value : null; if (totalVals == null) { totalVals = initMeasureValues(); addVal = totalVals; } sumVals(totalVals, (MeasureValue[]) entry.getValue()); } } else { BucketListMap nextTotals = compare == 0 ? (BucketListMap) totalItEntry.value : null; if (nextTotals == null) { nextTotals = createCollectBucketMap(level + 1); addVal = nextTotals; } nextTotals.collectVals((BucketMap) entry.getValue(), sum); } if (compare < 0) { if (totalItEntry != null) { totalIt.previous(); } totalIt.add(new MapEntry(key, addVal)); if (totalItEntry != null) { totalIt.next(); } } entry = it.hasNext() ? (Map.Entry) it.next() : null; } if (compare >= 0) { totalItEntry = totalIt.hasNext() ? (MapEntry) totalIt.next() : null; } } }