Update javadocs for CachedIteratorCollection

This commit is contained in:
slumlord
2018-08-06 15:14:15 +00:00
parent fc22d0fcbc
commit 177ef573ee

View File

@@ -1,8 +1,4 @@
// Extend `java.util.AbstractCollection` to create a collection that can be iterated over without creation of a new // The Node class below is derived from Java's LinkedList.java
// object
// https://docs.oracle.com/javase/7/docs/api/java/util/AbstractCollection.html
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
// The Node class below is from Java's LinkedList.java
package net.i2p.router.util; package net.i2p.router.util;
@@ -38,6 +33,14 @@ import java.util.NoSuchElementException;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.util.Log; 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<E> extends AbstractCollection<E> { public class CachedIteratorCollection<E> extends AbstractCollection<E> {
// FOR DEBUGGING & LOGGING PURPOSES // FOR DEBUGGING & LOGGING PURPOSES
@@ -60,18 +63,18 @@ public class CachedIteratorCollection<E> extends AbstractCollection<E> {
Node<E> next; Node<E> next;
Node<E> prev; Node<E> prev;
Node(Node<E> prev, E element, Node<E> next) { Node(Node<E> prev, E element) {
this.item = element; this.item = element;
this.prev = prev; this.prev = prev;
this.next = next; this.next = null;
} }
} }
// First Node in the AbstractCollectionTest object // First Node in the AbstractCollectionTest object
private transient Node<E> first; private transient Node<E> first = null;
// Last Node in the AbstractCollectionTest object // Last Node in the AbstractCollectionTest object
private transient Node<E> last; private transient Node<E> last = null;
/** /**
* Default constructor * Default constructor
@@ -85,14 +88,13 @@ public class CachedIteratorCollection<E> extends AbstractCollection<E> {
*/ */
@Override @Override
public boolean add(E element) { public boolean add(E element) {
final Node<E> newNode = new Node<>(null, element);
if (this.size == 0) { if (this.size == 0) {
final Node<E> newNode = new Node<>(null, element, null);
this.first = newNode; this.first = newNode;
this.last = newNode; this.last = newNode;
} else { } else {
final Node<E> newLast = new Node<>(this.last, element, null); this.last.next = newNode;
this.last.next = newLast; this.last = newNode;
this.last = newLast;
} }
this.size++; this.size++;
log.debug("CachedIteratorAbstractCollection: Element added"); log.debug("CachedIteratorAbstractCollection: Element added");
@@ -205,5 +207,7 @@ public class CachedIteratorCollection<E> extends AbstractCollection<E> {
/** /**
* Return size of current LinkedListTest object * Return size of current LinkedListTest object
*/ */
public int size() { return this.size; } public int size() {
return this.size;
}
} }