Changeset 177ef573
- Timestamp:
- Aug 6, 2018 3:14:15 PM (2 years ago)
- Branches:
- master
- Children:
- f97ec88
- Parents:
- fc22d0f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
router/java/src/net/i2p/router/util/CachedIteratorCollection.java
rfc22d0f r177ef573 1 // Extend `java.util.AbstractCollection` to create a collection that can be iterated over without creation of a new 2 // object 3 4 // https://docs.oracle.com/javase/7/docs/api/java/util/AbstractCollection.html 5 1 // The Node class below is derived from Java's LinkedList.java 6 2 /* 7 3 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. … … 28 24 * questions. 29 25 */ 30 // The Node class below is from Java's LinkedList.java31 26 32 27 package net.i2p.router.util; … … 38 33 import net.i2p.I2PAppContext; 39 34 import net.i2p.util.Log; 35 36 /** 37 * Extend java.util.AbstractCollection to create a collection that can be 38 * iterated over without creation of a new object 39 * 40 * @since 0.9.36 41 * 42 */ 40 43 41 44 public class CachedIteratorCollection<E> extends AbstractCollection<E> { … … 61 64 Node<E> prev; 62 65 63 Node(Node<E> prev, E element , Node<E> next) {66 Node(Node<E> prev, E element) { 64 67 this.item = element; 65 68 this.prev = prev; 66 this.next = n ext;69 this.next = null; 67 70 } 68 71 } 69 72 70 73 // First Node in the AbstractCollectionTest object 71 private transient Node<E> first ;74 private transient Node<E> first = null; 72 75 73 76 // Last Node in the AbstractCollectionTest object 74 private transient Node<E> last ;77 private transient Node<E> last = null; 75 78 76 79 /** … … 86 89 @Override 87 90 public boolean add(E element) { 91 final Node<E> newNode = new Node<>(null, element); 88 92 if (this.size == 0) { 89 final Node<E> newNode = new Node<>(null, element, null);90 93 this.first = newNode; 91 94 this.last = newNode; 92 95 } else { 93 final Node<E> newLast = new Node<>(this.last, element, null); 94 this.last.next = newLast; 95 this.last = newLast; 96 this.last.next = newNode; 97 this.last = newNode; 96 98 } 97 99 this.size++; … … 206 208 * Return size of current LinkedListTest object 207 209 */ 208 public int size() { return this.size; } 210 public int size() { 211 return this.size; 212 } 209 213 }
Note: See TracChangeset
for help on using the changeset viewer.