@Override public void add(final E obj) { checkModCount(); parent.add(nextIndex, obj); current = null; currentIndex = -1; nextIndex++; expectedModCount++; } }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ @Override public ListIterator<E> listIterator(final int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator<>(this, fromIndex); }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ @Override public E remove(final int index) { modCount++; checkInterval(index, 0, size() - 1); final E result = get(index); root = root.remove(index); size--; return result; }
/** * ArrayList 与 LinkedList的折衷版 * * ArrayList 随机访问快,当非末尾的插入删除慢. LinkedList的插入删除快,但非两端的操作都需要遍历链表到达指定下标. * * TreeList是内部结构为TreeNode的Linked List, 与Linked相仿,但能更快的到达指定下标. */ public static <E> TreeList<E> treeList() { return new TreeList<E>(); } }
@Override public boolean hasNext() { return nextIndex < parent.size(); }
/** * Gets an iterator over the list. * * @return an iterator over the list */ @Override public Iterator<E> iterator() { // override to go 75% faster return listIterator(0); }
/** * Searches for the presence of an object in the list. * * @param object the object to check * @return true if the object is found */ @Override public boolean contains(final Object object) { return indexOf(object) >= 0; }
@Override public void remove() { checkModCount(); if (currentIndex == -1) { throw new IllegalStateException(); } parent.remove(currentIndex); if (nextIndex != currentIndex) { // remove() following next() nextIndex--; } // the AVL node referenced by next may have become stale after a remove // reset it now: will be retrieved by next call to next()/previous() via nextIndex next = null; current = null; currentIndex = -1; expectedModCount++; }
/** * ArrayList 与 LinkedList的折衷版 * * ArrayList 随机访问快,当非末尾的插入删除慢. LinkedList的插入删除快,但非两端的操作都需要遍历链表到达指定下标. * * TreeList是内部结构为TreeNode的Linked List, 与Linked相仿,但能更快的到达指定下标. */ public static <E> TreeList<E> treeList() { return new TreeList<E>(); } }
/** * Checks whether the index is valid. * * @param index the index to check * @param startIndex the first allowed index * @param endIndex the last allowed index * @throws IndexOutOfBoundsException if the index is invalid */ private void checkInterval(final int index, final int startIndex, final int endIndex) { if (index < startIndex || index > endIndex) { throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size()); } }
/** * Gets a ListIterator over the list. * * @return the new iterator */ @Override public ListIterator<E> listIterator() { // override to go 75% faster return listIterator(0); }
/** Generate outgoing IpAccessList for the specified zone */ private IpAccessList generateOutgoingFilter(String name, Zone toZone, Vsys vsys) { List<IpAccessListLine> lines = new TreeList<>(); SortedMap<String, Rule> rules = toZone.getVsys().getRules(); for (Rule rule : rules.values()) { if (!rule.getDisabled() && (rule.getTo().contains(toZone.getName()) || rule.getTo().contains(CATCHALL_ZONE_NAME))) { lines.add(toIpAccessListLine(rule, vsys)); } } // Intrazone traffic is allowed by default lines.add( IpAccessListLine.builder() .accepting() .setMatchCondition(new MatchSrcInterface(toZone.getInterfaceNames())) .build()); return IpAccessList.builder().setName(name).setLines(lines).build(); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ @Override public E get(final int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }
/** * Converts the list into an array. * * @return the list as an array */ @Override public Object[] toArray() { // override to go 20% faster final Object[] array = new Object[size()]; if (root != null) { root.toArray(array, root.relativePosition); } return array; }
List<AclLineMatchExpr> conjuncts = new TreeList<>(); IpAccessListLine.Builder ipAccessListLineBuilder = IpAccessListLine.builder().setName(rule.getName()); List<String> srcInterfaces = new TreeList<>(); for (String zoneName : ruleFroms) { if (zoneName.equals(CATCHALL_ZONE_NAME)) { List<AclLineMatchExpr> serviceDisjuncts = new TreeList<>(); for (ServiceOrServiceGroupReference service : ruleServices) { if (service.getName().equals(CATCHALL_SERVICE_NAME)) {
/** * Sets the element at the specified index. * * @param index the index to set * @param obj the object to store at the specified index * @return the previous object at that index * @throws IndexOutOfBoundsException if the index is invalid */ @Override public E set(final int index, final E obj) { checkInterval(index, 0, size() - 1); final AVLNode<E> node = root.get(index); final E result = node.value; node.setValue(obj); return result; }
List<IpAccessListLine> zoneAclLines = new TreeList<>();
/** * Adds a new element to the list. * * @param index the index to add before * @param obj the element to add */ @Override public void add(final int index, final E obj) { modCount++; checkInterval(index, 0, size()); if (root == null) { root = new AVLNode<>(index, obj, null, null); } else { root = root.insert(index, obj); } size++; }
@Override public IpAccessList toIpAccessList(LineAction action, PaloAltoConfiguration pc, Vsys vsys) { List<IpAccessListLine> lines = new TreeList<>(); for (ServiceOrServiceGroupReference memberReference : _references) { String vsysName = memberReference.getVsysName(pc, vsys); if (vsysName != null) { lines.add( new IpAccessListLine( action, new PermittedByAcl( computeServiceGroupMemberAclName(vsysName, memberReference.getName())), _name)); } } return IpAccessList.builder() .setName(_name) .setLines(lines) .setSourceName(_name) .setSourceType(PaloAltoStructureType.SERVICE_GROUP.getDescription()) .build(); } }