();
- numbers.add(new Short("0"));
+ numbers.add(Short.valueOf("0"));
numbers.add((short)trackNo);
numbers.add((short)total);
- numbers.add(new Short("0"));
+ numbers.add(Short.valueOf("0"));
}
/**
diff --git a/ealvatag/src/main/java/ealvatag/tag/reference/Tagger.java b/ealvatag/src/main/java/ealvatag/tag/reference/Tagger.java
index be7bc71f..251c48c0 100644
--- a/ealvatag/src/main/java/ealvatag/tag/reference/Tagger.java
+++ b/ealvatag/src/main/java/ealvatag/tag/reference/Tagger.java
@@ -26,12 +26,10 @@ public enum Tagger
MUSICHI(15, "Musichi"),
;
- private int compatability;
private String desc;
Tagger(int compatability,String desc)
{
- this.compatability=compatability;
this.desc=desc;
}
diff --git a/ealvatag/src/main/java/ealvatag/utils/Buffers.java b/ealvatag/src/main/java/ealvatag/utils/Buffers.java
index c16974c7..76691e9e 100644
--- a/ealvatag/src/main/java/ealvatag/utils/Buffers.java
+++ b/ealvatag/src/main/java/ealvatag/utils/Buffers.java
@@ -44,7 +44,7 @@ public static String peekString(final BufferedSource bufferedSource,
final Charset charset) throws IOException {
bufferedSource.require(offset + count);
byte[] bytes = new byte[count];
- final Buffer buffer = bufferedSource.buffer();
+ final Buffer buffer = bufferedSource.getBuffer();
for (int i = 0; i < count; i++) {
bytes[i] = buffer.getByte(offset + i);
}
@@ -67,7 +67,7 @@ public static int read3ByteInt(final BufferedSource source) throws IOException {
public static int peek3ByteInt(final BufferedSource bufferedSource, final int offset) throws IOException {
bufferedSource.require(offset + 3);
- final Buffer buffer = bufferedSource.buffer();
+ final Buffer buffer = bufferedSource.getBuffer();
return (buffer.getByte(offset) & 0xff) << 16
| (buffer.getByte(offset + 1) & 0xff) << 8
| (buffer.getByte(offset + 2) & 0xff);
diff --git a/ealvatag/src/main/java/ealvatag/utils/tree/DefaultMutableTreeNode.java b/ealvatag/src/main/java/ealvatag/utils/tree/DefaultMutableTreeNode.java
index 01139885..c321a22e 100644
--- a/ealvatag/src/main/java/ealvatag/utils/tree/DefaultMutableTreeNode.java
+++ b/ealvatag/src/main/java/ealvatag/utils/tree/DefaultMutableTreeNode.java
@@ -17,7 +17,7 @@
/**
* A DefaultMutableTreeNode is a general-purpose node in a tree data
- * structure.
+ * structure.
* For examples of using default mutable tree nodes, see
* How to Use Trees
@@ -42,17 +42,17 @@
* representation of its user object.
*
* This is not a thread safe class.If you intend to use
- * a DefaultMutableTreeNode (or a tree of TreeNodes) in more than one thread, you
+ * a DefaultMutableTreeNode (or a tree of TreeNodes) in more than one thread, you
* need to do your own synchronizing. A good convention to adopt is
* synchronizing on the root node of a tree.
*
- * While DefaultMutableTreeNode implements the MutableTreeNode interface and
- * will allow you to add in any implementation of MutableTreeNode not all
- * of the methods in DefaultMutableTreeNode will be applicable to all
+ * While DefaultMutableTreeNode implements the MutableTreeNode interface and
+ * will allow you to add in any implementation of MutableTreeNode not all
+ * of the methods in DefaultMutableTreeNode will be applicable to all
* MutableTreeNodes implementations. Especially with some of the enumerations
* that are provided, using some of these methods assumes the
- * DefaultMutableTreeNode contains only DefaultMutableNode instances. All
- * of the TreeNode/MutableTreeNode methods will behave as defined no
+ * DefaultMutableTreeNode contains only DefaultMutableNode instances. All
+ * of the TreeNode/MutableTreeNode methods will behave as defined no
* matter what implementations are added.
*
*
@@ -70,30 +70,37 @@
* @version 1.25 03/23/10
* @author Rob Davis
*/
-public class DefaultMutableTreeNode extends Object implements Cloneable,
- MutableTreeNode, Serializable
+public class DefaultMutableTreeNode implements Cloneable,
+ MutableTreeNode, Serializable
{
/**
+ *
+ */
+ private static final long serialVersionUID = 7195119412898901913L;
+
+ /**
* An enumeration that is always empty. This is used when an enumeration
* of a leaf node's children is requested.
*/
- static public final Enumeration EMPTY_ENUMERATION
- = new Enumeration() {
- public boolean hasMoreElements() { return false; }
- public TreeNode nextElement() {
- throw new NoSuchElementException("No more elements");
- }
- };
+
+ public static final Enumeration emptyEnumeration() {
+ return new Enumeration() {
+ public boolean hasMoreElements() { return false; }
+ public X nextElement() {
+ throw new NoSuchElementException("No more elements");
+ }
+ };
+ }
/** this node's parent, or null if this node has no parent */
- protected MutableTreeNode parent;
+ protected MutableTreeNode parent;
/** array of children, may be null if this node has no children */
- protected Vector children;
+ protected Vector> children;
/** optional user object */
- transient protected Object userObject;
+ transient protected T userObject;
/** true if the node is able to have children */
protected boolean allowsChildren;
@@ -108,13 +115,13 @@ public DefaultMutableTreeNode() {
}
/**
- * Creates a tree node with no parent, no children, but which allows
+ * Creates a tree node with no parent, no children, but which allows
* children, and initializes it with the specified user object.
- *
+ *
* @param userObject an Object provided by the user that constitutes
* the node's data
*/
- public DefaultMutableTreeNode(Object userObject) {
+ public DefaultMutableTreeNode(T userObject) {
this(userObject, true);
}
@@ -122,13 +129,13 @@ public DefaultMutableTreeNode(Object userObject) {
* Creates a tree node with no parent, no children, initialized with
* the specified user object, and that allows children only if
* specified.
- *
+ *
* @param userObject an Object provided by the user that constitutes
* the node's data
* @param allowsChildren if true, the node is allowed to have child
* nodes -- otherwise, it is always a leaf node
*/
- public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) {
+ public DefaultMutableTreeNode(T userObject, boolean allowsChildren) {
super();
parent = null;
this.allowsChildren = allowsChildren;
@@ -147,7 +154,7 @@ public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) {
* newChild must not be null and must not be an ancestor of
* this node.
*
- * @param newChild the MutableTreeNode to insert under this node
+ * @param newChild the MutableTreeNode to insert under this node
* @param childIndex the index in this node's child array
* where this node is to be inserted
* @exception ArrayIndexOutOfBoundsException if
@@ -159,7 +166,7 @@ public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) {
* children
* @see #isNodeDescendant
*/
- public void insert(MutableTreeNode newChild, int childIndex) {
+ public void insert(MutableTreeNode newChild, int childIndex) {
if (!allowsChildren) {
throw new IllegalStateException("node does not allow children");
} else if (newChild == null) {
@@ -168,14 +175,14 @@ public void insert(MutableTreeNode newChild, int childIndex) {
throw new IllegalArgumentException("new child is an ancestor");
}
- MutableTreeNode oldParent = (MutableTreeNode)newChild.getParent();
+ MutableTreeNode oldParent = (MutableTreeNode)newChild.getParent();
if (oldParent != null) {
oldParent.remove(newChild);
}
newChild.setParent(this);
if (children == null) {
- children = new Vector();
+ children = new Vector>();
}
children.insertElementAt(newChild, childIndex);
}
@@ -191,13 +198,13 @@ public void insert(MutableTreeNode newChild, int childIndex) {
* childIndex is out of bounds
*/
public void remove(int childIndex) {
- MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex);
+ MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex);
children.removeElementAt(childIndex);
child.setParent(null);
}
/**
- * Sets this node's parent to newParent but does not
+ * Sets this node's parent to newParent but does not
* change the parent's child array. This method is called from
* insert() and remove() to
* reassign a child's parent, it should not be messaged from anywhere
@@ -205,7 +212,7 @@ public void remove(int childIndex) {
*
* @param newParent this node's new parent
*/
- public void setParent(MutableTreeNode newParent) {
+ public void setParent(MutableTreeNode newParent) {
parent = newParent;
}
@@ -214,7 +221,7 @@ public void setParent(MutableTreeNode newParent) {
*
* @return this node's parent TreeNode, or null if this node has no parent
*/
- public TreeNode getParent() {
+ public TreeNode getParent() {
return parent;
}
@@ -224,13 +231,13 @@ public TreeNode getParent() {
* @param index an index into this node's child array
* @exception ArrayIndexOutOfBoundsException if index
* is out of bounds
- * @return the TreeNode in this node's child array at the specified index
+ * @return the TreeNode in this node's child array at the specified index
*/
- public TreeNode getChildAt(int index) {
+ public TreeNode getChildAt(int index) {
if (children == null) {
throw new ArrayIndexOutOfBoundsException("node has no children");
}
- return (TreeNode)children.elementAt(index);
+ return children.elementAt(index);
}
/**
@@ -252,14 +259,15 @@ public int getChildCount() {
* -1. This method performs a linear search and is O(n)
* where n is the number of children.
*
- * @param aChild the TreeNode to search for among this node's children
+ * @param aChild the TreeNode to search for among this node's children
* @exception IllegalArgumentException if aChild
* is null
- * @return an int giving the index of the node in this node's child
+ * @return an int giving the index of the node in this node's child
* array, or -1 if the specified node is a not
* a child of this node
*/
- public int getIndex(TreeNode aChild) {
+ @Override
+ public int getIndex(TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
@@ -277,16 +285,16 @@ public int getIndex(TreeNode aChild) {
*
* @return an Enumeration of this node's children
*/
- public Enumeration children() {
+ public Enumeration> children() {
if (children == null) {
- return EMPTY_ENUMERATION;
+ return emptyEnumeration();
} else {
return children.elements();
}
}
/**
- * Determines whether or not this node is allowed to have children.
+ * Determines whether or not this node is allowed to have children.
* If allows is false, all of this node's children are
* removed.
*
@@ -315,12 +323,12 @@ public boolean getAllowsChildren() {
/**
* Sets the user object for this node to userObject.
*
- * @param userObject the Object that constitutes this node's
+ * @param userObject the Object that constitutes this node's
* user-specified data
* @see #getUserObject
* @see #toString
*/
- public void setUserObject(Object userObject) {
+ public void setUserObject(T userObject) {
this.userObject = userObject;
}
@@ -331,7 +339,7 @@ public void setUserObject(Object userObject) {
* @see #setUserObject
* @see #toString
*/
- public Object getUserObject() {
+ public T getUserObject() {
return userObject;
}
@@ -346,7 +354,7 @@ public Object getUserObject() {
* tree.
*/
public void removeFromParent() {
- MutableTreeNode parent = (MutableTreeNode)getParent();
+ MutableTreeNode parent = (MutableTreeNode)getParent();
if (parent != null) {
parent.remove(this);
}
@@ -360,7 +368,7 @@ public void removeFromParent() {
* @exception IllegalArgumentException if aChild
* is null or is not a child of this node
*/
- public void remove(MutableTreeNode aChild) {
+ public void remove(MutableTreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
@@ -392,7 +400,7 @@ public void removeAllChildren() {
* @exception IllegalStateException if this node does not allow
* children
*/
- public void add(MutableTreeNode newChild) {
+ public void add(MutableTreeNode newChild) {
if(newChild != null && newChild.getParent() == this)
insert(newChild, getChildCount() - 1);
else
@@ -418,12 +426,12 @@ public void add(MutableTreeNode newChild) {
* @param anotherNode node to test as an ancestor of this node
* @return true if this node is a descendant of anotherNode
*/
- public boolean isNodeAncestor(TreeNode anotherNode) {
+ public boolean isNodeAncestor(TreeNode anotherNode) {
if (anotherNode == null) {
return false;
}
- TreeNode ancestor = this;
+ TreeNode ancestor = this;
do {
if (ancestor == anotherNode) {
@@ -447,7 +455,7 @@ public boolean isNodeAncestor(TreeNode anotherNode) {
* @param anotherNode node to test as descendant of this node
* @return true if this node is an ancestor of anotherNode
*/
- public boolean isNodeDescendant(DefaultMutableTreeNode anotherNode) {
+ public boolean isNodeDescendant(DefaultMutableTreeNode anotherNode) {
if (anotherNode == null)
return false;
@@ -466,7 +474,7 @@ public boolean isNodeDescendant(DefaultMutableTreeNode anotherNode) {
* @return nearest ancestor common to this node and aNode,
* or null if none
*/
- public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
+ public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
if (aNode == this) {
return this;
} else if (aNode == null) {
@@ -474,11 +482,11 @@ public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
}
int level1, level2, diff;
- TreeNode node1, node2;
-
+ TreeNode node1, node2;
+
level1 = getLevel();
level2 = aNode.getLevel();
-
+
if (level2 > level1) {
diff = level2 - level1;
node1 = aNode;
@@ -494,12 +502,12 @@ public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
node1 = node1.getParent();
diff--;
}
-
+
// Move up the tree until we find a common ancestor. Since we know
// that both nodes are at the same level, we won't cross paths
// unknowingly (if there is a common ancestor, both nodes hit it in
// the same iteration).
-
+
do {
if (node1 == node2) {
return node1;
@@ -508,11 +516,11 @@ public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
node2 = node2.getParent();
} while (node1 != null);// only need to check one -- they're at the
// same level so if one is null, the other is
-
+
if (node1 != null || node2 != null) {
throw new Error ("nodes should be null");
}
-
+
return null;
}
@@ -526,7 +534,7 @@ public TreeNode getSharedAncestor(DefaultMutableTreeNode aNode) {
* @return true if aNode is in the same tree as this node;
* false if aNode is null
*/
- public boolean isNodeRelated(DefaultMutableTreeNode aNode) {
+ public boolean isNodeRelated(DefaultMutableTreeNode aNode) {
return (aNode != null) && (getRoot() == aNode.getRoot());
}
@@ -542,18 +550,18 @@ public boolean isNodeRelated(DefaultMutableTreeNode aNode) {
* @return the depth of the tree whose root is this node
*/
public int getDepth() {
- Object last = null;
- Enumeration enum_ = breadthFirstEnumeration();
-
+ TreeNode last = null;
+ Enumeration> enum_ = breadthFirstEnumeration();
+
while (enum_.hasMoreElements()) {
last = enum_.nextElement();
}
-
+
if (last == null) {
throw new Error ("nodes should be null");
}
-
- return ((DefaultMutableTreeNode)last).getLevel() - getLevel();
+
+ return ((DefaultMutableTreeNode)last).getLevel() - getLevel();
}
@@ -566,7 +574,7 @@ public int getDepth() {
* @return the number of levels above this node
*/
public int getLevel() {
- TreeNode ancestor;
+ TreeNode ancestor;
int levels = 0;
ancestor = this;
@@ -582,11 +590,11 @@ public int getLevel() {
* Returns the path from the root, to get to this node. The last
* element in the path is this node.
*
- * @return an array of TreeNode objects giving the path, where the
+ * @return an array of TreeNode objects giving the path, where the
* first element in the path is the root and the last
* element is this node.
*/
- public TreeNode[] getPath() {
+ public TreeNode[] getPath() {
return getPathToRoot(this, 0);
}
@@ -595,15 +603,16 @@ public TreeNode[] getPath() {
* where the original node is the last element in the returned array.
* The length of the returned array gives the node's depth in the
* tree.
- *
- * @param aNode the TreeNode to get the path for
+ *
+ * @param aNode the TreeNode to get the path for
* @param depth an int giving the number of steps already taken towards
* the root (on recursive calls), used to size the returned array
* @return an array of TreeNodes giving the path from the root to the
- * specified node
+ * specified node
*/
- protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
- TreeNode[] retNodes;
+ @SuppressWarnings("unchecked")
+ protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
+ TreeNode[] retNodes;
/* Check for null, in case someone passed in a null node, or
they passed in an element that isn't rooted at root. */
@@ -627,11 +636,11 @@ protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
* returned path will contain nulls.
*/
public Object[] getUserObjectPath() {
- TreeNode[] realPath = getPath();
+ TreeNode[] realPath = getPath();
Object[] retPath = new Object[realPath.length];
for(int counter = 0; counter < realPath.length; counter++)
- retPath[counter] = ((DefaultMutableTreeNode)realPath[counter])
+ retPath[counter] = ((DefaultMutableTreeNode)realPath[counter])
.getUserObject();
return retPath;
}
@@ -643,9 +652,9 @@ public Object[] getUserObjectPath() {
* @see #isNodeAncestor
* @return the root of the tree that contains this node
*/
- public TreeNode getRoot() {
- TreeNode ancestor = this;
- TreeNode previous;
+ public TreeNode getRoot() {
+ TreeNode ancestor = this;
+ TreeNode previous;
do {
previous = ancestor;
@@ -678,13 +687,13 @@ public boolean isRoot() {
* @return the node that follows this node in a preorder traversal, or
* null if this node is last
*/
- public DefaultMutableTreeNode getNextNode() {
+ public DefaultMutableTreeNode getNextNode() {
if (getChildCount() == 0) {
// No children, so look for nextSibling
- DefaultMutableTreeNode nextSibling = getNextSibling();
+ DefaultMutableTreeNode nextSibling = getNextSibling();
if (nextSibling == null) {
- DefaultMutableTreeNode aNode = (DefaultMutableTreeNode)getParent();
+ DefaultMutableTreeNode aNode = (DefaultMutableTreeNode)getParent();
do {
if (aNode == null) {
@@ -696,13 +705,13 @@ public DefaultMutableTreeNode getNextNode() {
return nextSibling;
}
- aNode = (DefaultMutableTreeNode)aNode.getParent();
+ aNode = (DefaultMutableTreeNode)aNode.getParent();
} while(true);
} else {
return nextSibling;
}
} else {
- return (DefaultMutableTreeNode)getChildAt(0);
+ return (DefaultMutableTreeNode)getChildAt(0);
}
}
@@ -710,7 +719,7 @@ public DefaultMutableTreeNode getNextNode() {
/**
* Returns the node that precedes this node in a preorder traversal of
* this node's tree. Returns null if this node is the
- * first node of the traversal -- the root of the tree.
+ * first node of the traversal -- the root of the tree.
* This is an inefficient way to
* traverse the entire tree; use an enumeration, instead.
*
@@ -718,9 +727,9 @@ public DefaultMutableTreeNode getNextNode() {
* @return the node that precedes this node in a preorder traversal, or
* null if this node is the first
*/
- public DefaultMutableTreeNode getPreviousNode() {
- DefaultMutableTreeNode previousSibling;
- DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
+ public DefaultMutableTreeNode getPreviousNode() {
+ DefaultMutableTreeNode previousSibling;
+ DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
if (myParent == null) {
return null;
@@ -749,7 +758,7 @@ public DefaultMutableTreeNode getPreviousNode() {
* @see #postorderEnumeration
* @return an enumeration for traversing the tree in preorder
*/
- public Enumeration preorderEnumeration() {
+ public Enumeration> preorderEnumeration() {
return new PreorderEnumeration(this);
}
@@ -766,8 +775,8 @@ public Enumeration preorderEnumeration() {
* @see #preorderEnumeration
* @return an enumeration for traversing the tree in postorder
*/
- public Enumeration postorderEnumeration() {
- return new PostorderEnumeration(this);
+ public Enumeration> postorderEnumeration() {
+ return new PostorderEnumeration<>(this);
}
/**
@@ -781,8 +790,8 @@ public Enumeration postorderEnumeration() {
* @see #depthFirstEnumeration
* @return an enumeration for traversing the tree in breadth-first order
*/
- public Enumeration breadthFirstEnumeration() {
- return new BreadthFirstEnumeration(this);
+ public Enumeration> breadthFirstEnumeration() {
+ return new BreadthFirstEnumeration<>(this);
}
/**
@@ -798,7 +807,7 @@ public Enumeration breadthFirstEnumeration() {
* @see #postorderEnumeration
* @return an enumeration for traversing the tree in depth-first order
*/
- public Enumeration depthFirstEnumeration() {
+ public Enumeration> depthFirstEnumeration() {
return postorderEnumeration();
}
@@ -822,8 +831,8 @@ public Enumeration depthFirstEnumeration() {
* @return an enumeration for following the path from an ancestor of
* this node to this one
*/
- public Enumeration pathFromAncestorEnumeration(TreeNode ancestor) {
- return new PathBetweenNodesEnumeration(ancestor, this);
+ public Enumeration> pathFromAncestorEnumeration(TreeNode ancestor) {
+ return new PathBetweenNodesEnumeration<>(ancestor, this);
}
@@ -835,10 +844,10 @@ public Enumeration pathFromAncestorEnumeration(TreeNode ancestor) {
* Returns true if aNode is a child of this node. If
* aNode is null, this method returns false.
*
- * @return true if aNode is a child of this node; false if
+ * @return true if aNode is a child of this node; false if
* aNode is null
*/
- public boolean isNodeChild(TreeNode aNode) {
+ public boolean isNodeChild(TreeNode aNode) {
boolean retval;
if (aNode == null) {
@@ -862,7 +871,7 @@ public boolean isNodeChild(TreeNode aNode) {
* @return the first child of this node
* @exception NoSuchElementException if this node has no children
*/
- public TreeNode getFirstChild() {
+ public TreeNode getFirstChild() {
if (getChildCount() == 0) {
throw new NoSuchElementException("node has no children");
}
@@ -877,7 +886,7 @@ public TreeNode getFirstChild() {
* @return the last child of this node
* @exception NoSuchElementException if this node has no children
*/
- public TreeNode getLastChild() {
+ public TreeNode getLastChild() {
if (getChildCount() == 0) {
throw new NoSuchElementException("node has no children");
}
@@ -899,7 +908,7 @@ public TreeNode getLastChild() {
* @return the child of this node that immediately follows
* aChild
*/
- public TreeNode getChildAfter(TreeNode aChild) {
+ public TreeNode getChildAfter(TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
@@ -930,7 +939,7 @@ public TreeNode getChildAfter(TreeNode aChild) {
* @return the child of this node that immediately precedes
* aChild
*/
- public TreeNode getChildBefore(TreeNode aChild) {
+ public TreeNode getChildBefore(TreeNode aChild) {
if (aChild == null) {
throw new IllegalArgumentException("argument is null");
}
@@ -962,7 +971,7 @@ public TreeNode getChildBefore(TreeNode aChild) {
* @param anotherNode node to test as sibling of this node
* @return true if anotherNode is a sibling of this node
*/
- public boolean isNodeSibling(TreeNode anotherNode) {
+ public boolean isNodeSibling(TreeNode anotherNode) {
boolean retval;
if (anotherNode == null) {
@@ -970,10 +979,10 @@ public boolean isNodeSibling(TreeNode anotherNode) {
} else if (anotherNode == this) {
retval = true;
} else {
- TreeNode myParent = getParent();
+ TreeNode myParent = getParent();
retval = (myParent != null && myParent == anotherNode.getParent());
- if (retval && !((DefaultMutableTreeNode)getParent())
+ if (retval && !((DefaultMutableTreeNode)getParent())
.isNodeChild(anotherNode)) {
throw new Error("sibling has different parent");
}
@@ -991,7 +1000,7 @@ public boolean isNodeSibling(TreeNode anotherNode) {
* @return the number of siblings of this node
*/
public int getSiblingCount() {
- TreeNode myParent = getParent();
+ TreeNode myParent = getParent();
if (myParent == null) {
return 1;
@@ -1011,15 +1020,15 @@ public int getSiblingCount() {
* @see #children
* @return the sibling of this node that immediately follows this node
*/
- public DefaultMutableTreeNode getNextSibling() {
- DefaultMutableTreeNode retval;
+ public DefaultMutableTreeNode getNextSibling() {
+ DefaultMutableTreeNode retval;
- DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
+ DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
if (myParent == null) {
retval = null;
} else {
- retval = (DefaultMutableTreeNode)myParent.getChildAfter(this); // linear search
+ retval = (DefaultMutableTreeNode)myParent.getChildAfter(this); // linear search
}
if (retval != null && !isNodeSibling(retval)) {
@@ -1038,15 +1047,15 @@ public DefaultMutableTreeNode getNextSibling() {
*
* @return the sibling of this node that immediately precedes this node
*/
- public DefaultMutableTreeNode getPreviousSibling() {
- DefaultMutableTreeNode retval;
+ public DefaultMutableTreeNode getPreviousSibling() {
+ DefaultMutableTreeNode retval;
- DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
+ DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
if (myParent == null) {
retval = null;
} else {
- retval = (DefaultMutableTreeNode)myParent.getChildBefore(this); // linear search
+ retval = (DefaultMutableTreeNode)myParent.getChildBefore(this); // linear search
}
if (retval != null && !isNodeSibling(retval)) {
@@ -1085,11 +1094,11 @@ public boolean isLeaf() {
* @see #isNodeDescendant
* @return the first leaf in the subtree rooted at this node
*/
- public DefaultMutableTreeNode getFirstLeaf() {
- DefaultMutableTreeNode node = this;
+ public DefaultMutableTreeNode getFirstLeaf() {
+ DefaultMutableTreeNode node = this;
while (!node.isLeaf()) {
- node = (DefaultMutableTreeNode)node.getFirstChild();
+ node = (DefaultMutableTreeNode)node.getFirstChild();
}
return node;
@@ -1098,18 +1107,18 @@ public DefaultMutableTreeNode getFirstLeaf() {
/**
* Finds and returns the last leaf that is a descendant of this node --
- * either this node or its last child's last leaf.
+ * either this node or its last child's last leaf.
* Returns this node if it is a leaf.
*
* @see #isLeaf
* @see #isNodeDescendant
* @return the last leaf in the subtree rooted at this node
*/
- public DefaultMutableTreeNode getLastLeaf() {
- DefaultMutableTreeNode node = this;
+ public DefaultMutableTreeNode getLastLeaf() {
+ DefaultMutableTreeNode node = this;
while (!node.isLeaf()) {
- node = (DefaultMutableTreeNode)node.getLastChild();
+ node = (DefaultMutableTreeNode)node.getLastChild();
}
return node;
@@ -1122,11 +1131,11 @@ public DefaultMutableTreeNode getLastLeaf() {
*
* In this implementation of the MutableNode interface,
* this operation is very inefficient. In order to determine the
- * next node, this method first performs a linear search in the
- * parent's child-list in order to find the current node.
+ * next node, this method first performs a linear search in the
+ * parent's child-list in order to find the current node.
*
* That implementation makes the operation suitable for short
- * traversals from a known position. But to traverse all of the
+ * traversals from a known position. But to traverse all of the
* leaves in the tree, you should use depthFirstEnumeration
* to enumerate the nodes in the tree and use isLeaf
* on each node to determine which are leaves.
@@ -1135,9 +1144,9 @@ public DefaultMutableTreeNode getLastLeaf() {
* @see #isLeaf
* @return returns the next leaf past this node
*/
- public DefaultMutableTreeNode getNextLeaf() {
- DefaultMutableTreeNode nextSibling;
- DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
+ public DefaultMutableTreeNode getNextLeaf() {
+ DefaultMutableTreeNode nextSibling;
+ DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
if (myParent == null)
return null;
@@ -1157,11 +1166,11 @@ public DefaultMutableTreeNode getNextLeaf() {
*
* In this implementation of the MutableNode interface,
* this operation is very inefficient. In order to determine the
- * previous node, this method first performs a linear search in the
- * parent's child-list in order to find the current node.
+ * previous node, this method first performs a linear search in the
+ * parent's child-list in order to find the current node.
*
* That implementation makes the operation suitable for short
- * traversals from a known position. But to traverse all of the
+ * traversals from a known position. But to traverse all of the
* leaves in the tree, you should use depthFirstEnumeration
* to enumerate the nodes in the tree and use isLeaf
* on each node to determine which are leaves.
@@ -1170,9 +1179,9 @@ public DefaultMutableTreeNode getNextLeaf() {
* @see #isLeaf
* @return returns the leaf before this node
*/
- public DefaultMutableTreeNode getPreviousLeaf() {
- DefaultMutableTreeNode previousSibling;
- DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
+ public DefaultMutableTreeNode getPreviousLeaf() {
+ DefaultMutableTreeNode previousSibling;
+ DefaultMutableTreeNode myParent = (DefaultMutableTreeNode)getParent();
if (myParent == null)
return null;
@@ -1197,11 +1206,11 @@ public DefaultMutableTreeNode getPreviousLeaf() {
public int getLeafCount() {
int count = 0;
- TreeNode node;
- Enumeration enum_ = breadthFirstEnumeration(); // order matters not
+ TreeNode node;
+ Enumeration> enum_ = breadthFirstEnumeration(); // order matters not
while (enum_.hasMoreElements()) {
- node = (TreeNode)enum_.nextElement();
+ node = enum_.nextElement();
if (node.isLeaf()) {
count++;
}
@@ -1240,11 +1249,12 @@ public String toString() {
*
* @return a copy of this node
*/
- public Object clone() {
- DefaultMutableTreeNode newNode = null;
+ @SuppressWarnings("unchecked")
+ public DefaultMutableTreeNode clone() {
+ DefaultMutableTreeNode newNode = null;
try {
- newNode = (DefaultMutableTreeNode)super.clone();
+ newNode = (DefaultMutableTreeNode)super.clone();
// shallow copy -- the new node has no parent or children
newNode.children = null;
@@ -1259,7 +1269,7 @@ public Object clone() {
}
- // Serialization support.
+ // Serialization support.
private void writeObject(ObjectOutputStream s) throws IOException {
Object[] tValues;
@@ -1275,38 +1285,39 @@ private void writeObject(ObjectOutputStream s) throws IOException {
s.writeObject(tValues);
}
- private void readObject(ObjectInputStream s)
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
- Object[] tValues;
+ T[] tValues;
s.defaultReadObject();
- tValues = (Object[])s.readObject();
+ tValues = (T[])s.readObject();
if(tValues.length > 0 && tValues[0].equals("userObject"))
userObject = tValues[1];
}
- final class PreorderEnumeration implements Enumeration {
- protected Stack stack;
+ final class PreorderEnumeration implements Enumeration> {
+ protected Stack>> stack;
- public PreorderEnumeration(TreeNode rootNode) {
+ public PreorderEnumeration(TreeNode rootNode) {
super();
- Vector v = new Vector(1);
+ Vector> v = new Vector<>(1);
v.addElement(rootNode); // PENDING: don't really need a vector
- stack = new Stack();
+ stack = new Stack<>();
stack.push(v.elements());
}
public boolean hasMoreElements() {
- return (!stack.empty() &&
- ((Enumeration)stack.peek()).hasMoreElements());
+ return !stack.empty() &&
+ stack.peek().hasMoreElements();
}
- public TreeNode nextElement() {
- Enumeration enumer = (Enumeration)stack.peek();
- TreeNode node = (TreeNode)enumer.nextElement();
- Enumeration children = node.children();
+ public TreeNode nextElement() {
+ Enumeration> enumer = stack.peek();
+ TreeNode node = enumer.nextElement();
+ Enumeration> children = node.children();
if (!enumer.hasMoreElements()) {
stack.pop();
@@ -1321,30 +1332,29 @@ public TreeNode nextElement() {
- final class PostorderEnumeration implements Enumeration {
- protected TreeNode root;
- protected Enumeration children;
- protected Enumeration subtree;
+ final class PostorderEnumeration implements Enumeration> {
+ protected TreeNode root;
+ protected Enumeration> children;
+ protected Enumeration> subtree;
- public PostorderEnumeration(TreeNode rootNode) {
+ public PostorderEnumeration(TreeNode rootNode) {
super();
root = rootNode;
children = root.children();
- subtree = EMPTY_ENUMERATION;
+ subtree = emptyEnumeration();
}
public boolean hasMoreElements() {
return root != null;
}
- public TreeNode nextElement() {
- TreeNode retval;
+ public TreeNode nextElement() {
+ TreeNode retval;
if (subtree.hasMoreElements()) {
retval = subtree.nextElement();
} else if (children.hasMoreElements()) {
- subtree = new PostorderEnumeration(
- (TreeNode)children.nextElement());
+ subtree = new PostorderEnumeration<>(children.nextElement());
retval = subtree.nextElement();
} else {
retval = root;
@@ -1358,26 +1368,26 @@ public TreeNode nextElement() {
- final class BreadthFirstEnumeration implements Enumeration {
- protected Queue queue;
+ final class BreadthFirstEnumeration implements Enumeration> {
+ protected Queue>> queue;
- public BreadthFirstEnumeration(TreeNode rootNode) {
+ public BreadthFirstEnumeration(TreeNode rootNode) {
super();
- Vector v = new Vector(1);
+ Vector> v = new Vector<>(1);
v.addElement(rootNode); // PENDING: don't really need a vector
- queue = new Queue();
+ queue = new Queue<>();
queue.enqueue(v.elements());
}
public boolean hasMoreElements() {
return (!queue.isEmpty() &&
- ((Enumeration)queue.firstObject()).hasMoreElements());
+ queue.firstObject().hasMoreElements());
}
- public TreeNode nextElement() {
- Enumeration enumer = (Enumeration)queue.firstObject();
- TreeNode node = (TreeNode)enumer.nextElement();
- Enumeration children = node.children();
+ public TreeNode nextElement() {
+ Enumeration> enumer = queue.firstObject();
+ TreeNode node = enumer.nextElement();
+ Enumeration> children = node.children();
if (!enumer.hasMoreElements()) {
queue.dequeue();
@@ -1390,24 +1400,24 @@ public TreeNode nextElement() {
// A simple queue with a linked list data structure.
- final class Queue {
- QNode head; // null if empty
- QNode tail;
-
- final class QNode {
- public Object object;
- public QNode next; // null if end
- public QNode(Object object, QNode next) {
+ final class Queue {
+ QNode head; // null if empty
+ QNode tail;
+
+ final class QNode {
+ public Z object;
+ public QNode next; // null if end
+ public QNode(Z object, QNode next) {
this.object = object;
this.next = next;
}
}
- public void enqueue(Object anObject) {
+ public void enqueue(Y anObject) {
if (head == null) {
- head = tail = new QNode(anObject, null);
+ head = tail = new QNode<>(anObject, null);
} else {
- tail.next = new QNode(anObject, null);
+ tail.next = new QNode<>(anObject, null);
tail = tail.next;
}
}
@@ -1417,8 +1427,8 @@ public Object dequeue() {
throw new NoSuchElementException("No more elements");
}
- Object retval = head.object;
- QNode oldHead = head;
+ Y retval = head.object;
+ QNode oldHead = head;
head = head.next;
if (head == null) {
tail = null;
@@ -1428,7 +1438,7 @@ public Object dequeue() {
return retval;
}
- public Object firstObject() {
+ public Y firstObject() {
if (head == null) {
throw new NoSuchElementException("No more elements");
}
@@ -1446,11 +1456,11 @@ public boolean isEmpty() {
- final class PathBetweenNodesEnumeration implements Enumeration {
- protected Stack stack;
+ final class PathBetweenNodesEnumeration implements Enumeration> {
+ protected Stack> stack;
- public PathBetweenNodesEnumeration(TreeNode ancestor,
- TreeNode descendant)
+ public PathBetweenNodesEnumeration(TreeNode ancestor,
+ TreeNode descendant)
{
super();
@@ -1458,9 +1468,9 @@ public PathBetweenNodesEnumeration(TreeNode ancestor,
throw new IllegalArgumentException("argument is null");
}
- TreeNode current;
+ TreeNode current;
- stack = new Stack();
+ stack = new Stack>();
stack.push(descendant);
current = descendant;
@@ -1478,7 +1488,7 @@ public boolean hasMoreElements() {
return stack.size() > 0;
}
- public TreeNode nextElement() {
+ public TreeNode nextElement() {
try {
return stack.pop();
} catch (EmptyStackException e) {
diff --git a/ealvatag/src/main/java/ealvatag/utils/tree/DefaultTreeModel.java b/ealvatag/src/main/java/ealvatag/utils/tree/DefaultTreeModel.java
index 9d7fd0b1..cdb5b285 100644
--- a/ealvatag/src/main/java/ealvatag/utils/tree/DefaultTreeModel.java
+++ b/ealvatag/src/main/java/ealvatag/utils/tree/DefaultTreeModel.java
@@ -35,9 +35,13 @@
* @author Ray Ryan
* @author Scott Violet
*/
-public class DefaultTreeModel implements Serializable, TreeModel {
- /** Root of the tree. */
- protected TreeNode root;
+public class DefaultTreeModel implements Serializable, TreeModel {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4868723904649433259L;
+ /** Root of the tree. */
+ protected TreeNode root;
/** Listeners. */
protected EventListenerList listenerList = new EventListenerList();
/**
@@ -65,7 +69,7 @@ public class DefaultTreeModel implements Serializable, TreeModel {
* @param root a TreeNode object that is the root of the tree
* @see #DefaultTreeModel(TreeNode, boolean)
*/
- public DefaultTreeModel(TreeNode root) {
+ public DefaultTreeModel(TreeNode root) {
this(root, false);
}
@@ -79,7 +83,7 @@ public DefaultTreeModel(TreeNode root) {
* it can have children
* @see #asksAllowsChildren
*/
- public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) {
+ public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) {
super();
this.root = root;
this.asksAllowsChildren = asksAllowsChildren;
@@ -110,7 +114,7 @@ public boolean asksAllowsChildren() {
* Sets the root to root. A null root implies
* the tree is to display nothing, and is legal.
*/
- public void setRoot(TreeNode root) {
+ public void setRoot(TreeNode root) {
Object oldRoot = this.root;
this.root = root;
if (root == null && oldRoot != null) {
@@ -127,7 +131,7 @@ public void setRoot(TreeNode root) {
*
* @return the root of the tree
*/
- public Object getRoot() {
+ public TreeNode getRoot() {
return root;
}
@@ -139,10 +143,10 @@ public Object getRoot() {
* @return the index of the child in the parent, or -1
* if either the parent or the child is null
*/
- public int getIndexOfChild(Object parent, Object child) {
+ public int getIndexOfChild(TreeNode parent, TreeNode child) {
if(parent == null || child == null)
return -1;
- return ((TreeNode)parent).getIndex((TreeNode)child);
+ return parent.getIndex(child);
}
/**
@@ -155,8 +159,8 @@ public int getIndexOfChild(Object parent, Object child) {
* @param parent a node in the tree, obtained from this data source
* @return the child of parent at index index
*/
- public Object getChild(Object parent, int index) {
- return ((TreeNode)parent).getChildAt(index);
+ public TreeNode getChild(TreeNode parent, int index) {
+ return parent.getChildAt(index);
}
/**
@@ -167,8 +171,8 @@ public Object getChild(Object parent, int index) {
* @param parent a node in the tree, obtained from this data source
* @return the number of children of the node parent
*/
- public int getChildCount(Object parent) {
- return ((TreeNode)parent).getChildCount();
+ public int getChildCount(TreeNode parent) {
+ return parent.getChildCount();
}
/**
@@ -182,10 +186,10 @@ public int getChildCount(Object parent) {
* @see #asksAllowsChildren
* @see TreeModel#isLeaf
*/
- public boolean isLeaf(Object node) {
+ public boolean isLeaf(TreeNode node) {
if(asksAllowsChildren)
- return !((TreeNode)node).getAllowsChildren();
- return ((TreeNode)node).isLeaf();
+ return !node.getAllowsChildren();
+ return node.isLeaf();
}
/**
@@ -203,8 +207,8 @@ public void reload() {
* the TreeModel you're going to need to subclass this and
* set the user object of the changed node to something meaningful.
*/
- public void valueForPathChanged(TreePath path, Object newValue) {
- MutableTreeNode aNode = (MutableTreeNode)path.getLastPathComponent();
+ public void valueForPathChanged(TreePath path, T newValue) {
+ MutableTreeNode