src/share/classes/javax/swing/tree/DefaultMutableTreeNode.java
Print this page
@@ -100,11 +100,11 @@
/** this node's parent, or null if this node has no parent */
protected MutableTreeNode parent;
/** array of children, may be null if this node has no children */
- protected Vector children;
+ protected Vector<TreeNode> children;
/** optional user object */
transient protected Object userObject;
/** true if the node is able to have children */
@@ -185,11 +185,11 @@
if (oldParent != null) {
oldParent.remove(newChild);
}
newChild.setParent(this);
if (children == null) {
- children = new Vector();
+ children = new Vector<>();
}
children.insertElementAt(newChild, childIndex);
}
/**
@@ -241,11 +241,11 @@
*/
public TreeNode getChildAt(int index) {
if (children == null) {
throw new ArrayIndexOutOfBoundsException("node has no children");
}
- return (TreeNode)children.elementAt(index);
+ return children.elementAt(index);
}
/**
* Returns the number of children of this node.
*
@@ -288,11 +288,11 @@
* children. Modifying this node's child array invalidates any child
* enumerations created before the modification.
*
* @return an Enumeration of this node's children
*/
- public Enumeration children() {
+ public Enumeration<TreeNode> children() {
if (children == null) {
return EMPTY_ENUMERATION;
} else {
return children.elements();
}
@@ -555,11 +555,11 @@
* @see #getLevel
* @return the depth of the tree whose root is this node
*/
public int getDepth() {
Object last = null;
- Enumeration enum_ = breadthFirstEnumeration();
+ Enumeration<TreeNode> enum_ = breadthFirstEnumeration();
while (enum_.hasMoreElements()) {
last = enum_.nextElement();
}
@@ -763,11 +763,11 @@
* any enumerations created before the modification.
*
* @see #postorderEnumeration
* @return an enumeration for traversing the tree in preorder
*/
- public Enumeration preorderEnumeration() {
+ public Enumeration<TreeNode> preorderEnumeration() {
return new PreorderEnumeration(this);
}
/**
* Creates and returns an enumeration that traverses the subtree rooted at
@@ -780,11 +780,11 @@
*
* @see #depthFirstEnumeration
* @see #preorderEnumeration
* @return an enumeration for traversing the tree in postorder
*/
- public Enumeration postorderEnumeration() {
+ public Enumeration<TreeNode> postorderEnumeration() {
return new PostorderEnumeration(this);
}
/**
* Creates and returns an enumeration that traverses the subtree rooted at
@@ -795,11 +795,11 @@
* any enumerations created before the modification.
*
* @see #depthFirstEnumeration
* @return an enumeration for traversing the tree in breadth-first order
*/
- public Enumeration breadthFirstEnumeration() {
+ public Enumeration<TreeNode> breadthFirstEnumeration() {
return new BreadthFirstEnumeration(this);
}
/**
* Creates and returns an enumeration that traverses the subtree rooted at
@@ -812,11 +812,11 @@
*
* @see #breadthFirstEnumeration
* @see #postorderEnumeration
* @return an enumeration for traversing the tree in depth-first order
*/
- public Enumeration depthFirstEnumeration() {
+ public Enumeration<TreeNode> depthFirstEnumeration() {
return postorderEnumeration();
}
/**
* Creates and returns an enumeration that follows the path from
@@ -837,11 +837,11 @@
* @exception IllegalArgumentException if <code>ancestor</code> is
* not an ancestor of this node
* @return an enumeration for following the path from an ancestor of
* this node to this one
*/
- public Enumeration pathFromAncestorEnumeration(TreeNode ancestor) {
+ public Enumeration<TreeNode> pathFromAncestorEnumeration(TreeNode ancestor) {
return new PathBetweenNodesEnumeration(ancestor, this);
}
//
@@ -1216,14 +1216,14 @@
*/
public int getLeafCount() {
int count = 0;
TreeNode node;
- Enumeration enum_ = breadthFirstEnumeration(); // order matters not
+ Enumeration<TreeNode> enum_ = breadthFirstEnumeration(); // order matters not
while (enum_.hasMoreElements()) {
- node = (TreeNode)enum_.nextElement();
+ node = enum_.nextElement();
if (node.isLeaf()) {
count++;
}
}
@@ -1306,11 +1306,11 @@
if(tValues.length > 0 && tValues[0].equals("userObject"))
userObject = tValues[1];
}
private final class PreorderEnumeration implements Enumeration<TreeNode> {
- private final Stack<Enumeration> stack = new Stack<Enumeration>();
+ private final Stack<Enumeration<TreeNode>> stack = new Stack<>();
public PreorderEnumeration(TreeNode rootNode) {
super();
Vector<TreeNode> v = new Vector<TreeNode>(1);
v.addElement(rootNode); // PENDING: don't really need a vector
@@ -1320,13 +1320,14 @@
public boolean hasMoreElements() {
return (!stack.empty() && stack.peek().hasMoreElements());
}
public TreeNode nextElement() {
- Enumeration enumer = stack.peek();
- TreeNode node = (TreeNode)enumer.nextElement();
- Enumeration children = node.children();
+ Enumeration<TreeNode> enumer = stack.peek();
+ TreeNode node = enumer.nextElement();
+ @SuppressWarnings("unchecked")
+ Enumeration<TreeNode> children = node.children();
if (!enumer.hasMoreElements()) {
stack.pop();
}
if (children.hasMoreElements()) {
@@ -1390,13 +1391,13 @@
return (!queue.isEmpty() &&
((Enumeration)queue.firstObject()).hasMoreElements());
}
public TreeNode nextElement() {
- Enumeration enumer = (Enumeration)queue.firstObject();
+ Enumeration<?> enumer = (Enumeration)queue.firstObject();
TreeNode node = (TreeNode)enumer.nextElement();
- Enumeration children = node.children();
+ Enumeration<?> children = node.children();
if (!enumer.hasMoreElements()) {
queue.dequeue();
}
if (children.hasMoreElements()) {