From 177ef573eeb3efb505079f5b572f9e17a2b63090 Mon Sep 17 00:00:00 2001 From: slumlord Date: Mon, 6 Aug 2018 15:14:15 +0000 Subject: [PATCH] Update javadocs for CachedIteratorCollection --- .../router/util/CachedIteratorCollection.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/router/java/src/net/i2p/router/util/CachedIteratorCollection.java b/router/java/src/net/i2p/router/util/CachedIteratorCollection.java index 84570882d..6038dd67d 100644 --- a/router/java/src/net/i2p/router/util/CachedIteratorCollection.java +++ b/router/java/src/net/i2p/router/util/CachedIteratorCollection.java @@ -1,8 +1,4 @@ -// Extend `java.util.AbstractCollection` to create a collection that can be iterated over without creation of a new -// object - -// https://docs.oracle.com/javase/7/docs/api/java/util/AbstractCollection.html - +// The Node class below is derived from Java's LinkedList.java /* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -27,7 +23,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -// The Node class below is from Java's LinkedList.java package net.i2p.router.util; @@ -38,6 +33,14 @@ import java.util.NoSuchElementException; import net.i2p.I2PAppContext; import net.i2p.util.Log; +/** + * Extend java.util.AbstractCollection to create a collection that can be + * iterated over without creation of a new object + * + * @since 0.9.36 + * + */ + public class CachedIteratorCollection extends AbstractCollection { // FOR DEBUGGING & LOGGING PURPOSES @@ -60,18 +63,18 @@ public class CachedIteratorCollection extends AbstractCollection { Node next; Node prev; - Node(Node prev, E element, Node next) { + Node(Node prev, E element) { this.item = element; this.prev = prev; - this.next = next; + this.next = null; } } // First Node in the AbstractCollectionTest object - private transient Node first; + private transient Node first = null; // Last Node in the AbstractCollectionTest object - private transient Node last; + private transient Node last = null; /** * Default constructor @@ -85,14 +88,13 @@ public class CachedIteratorCollection extends AbstractCollection { */ @Override public boolean add(E element) { + final Node newNode = new Node<>(null, element); if (this.size == 0) { - final Node newNode = new Node<>(null, element, null); this.first = newNode; this.last = newNode; } else { - final Node newLast = new Node<>(this.last, element, null); - this.last.next = newLast; - this.last = newLast; + this.last.next = newNode; + this.last = newNode; } this.size++; log.debug("CachedIteratorAbstractCollection: Element added"); @@ -205,5 +207,7 @@ public class CachedIteratorCollection extends AbstractCollection { /** * Return size of current LinkedListTest object */ - public int size() { return this.size; } + public int size() { + return this.size; + } }