You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/08/05 15:41:04 UTC
svn commit: r801229 - in
/incubator/pivot/trunk/core/src/org/apache/pivot/collections:
ArrayList.java LinkedList.java List.java
Author: gbrown
Date: Wed Aug 5 13:41:04 2009
New Revision: 801229
URL: http://svn.apache.org/viewvc?rev=801229&view=rev
Log:
Make LinkedList.Node a static inner class.
Modified:
incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java
Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java?rev=801229&r1=801228&r2=801229&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java Wed Aug 5 13:41:04 2009
@@ -427,7 +427,11 @@
public static <T extends Comparable<? super T>> int binarySearch(ArrayList<T> arrayList,
T item) {
- return binarySearch(arrayList, item, new SimpleComparator<T>());
+ return binarySearch(arrayList, item, new Comparator<T>() {
+ public int compare(T t1, T t2) {
+ return t1.compareTo(t2);
+ }
+ });
}
@SuppressWarnings("unchecked")
Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java?rev=801229&r1=801228&r2=801229&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java Wed Aug 5 13:41:04 2009
@@ -34,13 +34,13 @@
*/
public class LinkedList<T> implements List<T>, Serializable {
// Node containing an item in the list
- private class Node implements Serializable {
+ private static class Node<T> implements Serializable {
private static final long serialVersionUID = 0;
- private Node previous;
- private Node next;
+ private Node<T> previous;
+ private Node<T> next;
private T item;
- public Node(Node previous, Node next, T item) {
+ public Node(Node<T> previous, Node<T> next, T item) {
this.previous = previous;
this.next = next;
this.item = item;
@@ -49,7 +49,7 @@
// Node iterator
private class NodeIterator implements Iterator<T> {
- private Node node;
+ private Node<T> node;
public NodeIterator() {
this.node = first;
@@ -84,8 +84,8 @@
private static final long serialVersionUID = 0;
- private Node first = null;
- private Node last = null;
+ private Node<T> first = null;
+ private Node<T> last = null;
private int length = 0;
private Comparator<T> comparator = null;
@@ -132,7 +132,7 @@
if (nodeIterator.hasNext()
&& index > 0) {
// Insert the new node here
- Node node = new Node(nodeIterator.node, nodeIterator.node.next, item);
+ Node<T> node = new Node<T>(nodeIterator.node, nodeIterator.node.next, item);
nodeIterator.node.next = node;
node.next.previous = node;
length++;
@@ -156,12 +156,12 @@
}
if (length == 0) {
- Node node = new Node(null, null, item);
+ Node<T> node = new Node<T>(null, null, item);
first = node;
last = node;
} else {
- Node next = (index == length) ? null : getNode(index);
- Node previous = (next == null) ? last : next.previous;
+ Node<T> next = (index == length) ? null : getNode(index);
+ Node<T> previous = (next == null) ? last : next.previous;
if (comparator != null) {
// Ensure that the new item is greater or equal to its
@@ -174,7 +174,7 @@
}
}
- Node node = new Node(previous, next, item);
+ Node<T> node = new Node<T>(previous, next, item);
if (previous == null) {
first = node;
} else {
@@ -200,7 +200,7 @@
}
// Get the previous item at index
- Node node = getNode(index);
+ Node<T> node = getNode(index);
T previousItem = node.item;
if (previousItem != item) {
@@ -254,8 +254,8 @@
if (count > 0) {
// Identify the bounding nodes and build the removed item list
- Node start = getNode(index);
- Node end = start;
+ Node<T> start = getNode(index);
+ Node<T> end = start;
for (int i = 0; i < count; i++) {
removed.add(end.item);
end = end.next;
@@ -311,12 +311,12 @@
throw new IndexOutOfBoundsException();
}
- Node node = getNode(index);
+ Node<T> node = getNode(index);
return node.item;
}
- private Node getNode(int index) {
- Node node;
+ private Node<T> getNode(int index) {
+ Node<T> node;
if (index == 0) {
node = first;
} else if (index == length - 1) {
@@ -384,10 +384,10 @@
// Rebuild the node list
first = null;
- Node node = null;
+ Node<T> node = null;
for (i = 0; i < length; i++) {
- Node previousNode = node;
- node = new Node(previousNode, null, array[i]);
+ Node<T> previousNode = node;
+ node = new Node<T>(previousNode, null, array[i]);
if (previousNode == null) {
first = node;
Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java?rev=801229&r1=801228&r2=801229&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java Wed Aug 5 13:41:04 2009
@@ -27,22 +27,6 @@
*/
public interface List<T> extends Sequence<T>, Collection<T> {
/**
- * Comparator capable of comparing two comparable objects by delegating the
- * comparison to the objects.
- *
- * @author gbrown
- */
- public static final class SimpleComparator<T extends Comparable<? super T>>
- implements Comparator<T> {
- /**
- * {@inheritDoc}
- */
- public int compare(T t1, T t2) {
- return t1.compareTo(t2);
- }
- }
-
- /**
* List listener list.
*
* @author gbrown