src/share/classes/javax/imageio/spi/DigraphNode.java

Print this page
rev 9345 : 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
Reviewed-by:

@@ -37,45 +37,45 @@
  * to by the current node (available from <code>getOutNodes</code>).
  * The in-degree of the node (that is, number of nodes that point to
  * the current node) may be queried.
  *
  */
-class DigraphNode implements Cloneable, Serializable {
+class DigraphNode<E> implements Cloneable, Serializable {
     private static final long serialVersionUID = 5308261378582246841L;
 
     /** The data associated with this node. */
-    protected Object data;
+    protected E data;
 
     /**
      * A <code>Set</code> of neighboring nodes pointed to by this
      * node.
      */
-    protected Set outNodes = new HashSet();
+    protected Set<DigraphNode<E>> outNodes = new HashSet<>();
 
     /** The in-degree of the node. */
     protected int inDegree = 0;
 
     /**
      * A <code>Set</code> of neighboring nodes that point to this
      * node.
      */
-    private Set inNodes = new HashSet();
+    private Set<DigraphNode<E>> inNodes = new HashSet<>();
 
-    public DigraphNode(Object data) {
+    public DigraphNode(E data) {
         this.data = data;
     }
 
     /** Returns the <code>Object</code> referenced by this node. */
-    public Object getData() {
+    public E getData() {
         return data;
     }
 
     /**
      * Returns an <code>Iterator</code> containing the nodes pointed
      * to by this node.
      */
-    public Iterator getOutNodes() {
+    public Iterator<DigraphNode<E>> getOutNodes() {
         return outNodes.iterator();
     }
 
     /**
      * Adds a directed edge to the graph.  The outNodes list of this

@@ -84,11 +84,11 @@
      * @param node a <code>DigraphNode</code>.
      *
      * @return <code>true</code> if the node was not previously the
      * target of an edge.
      */
-    public boolean addEdge(DigraphNode node) {
+    public boolean addEdge(DigraphNode<E> node) {
         if (outNodes.contains(node)) {
             return false;
         }
 
         outNodes.add(node);

@@ -103,22 +103,22 @@
      *
      * @param node a <code>DigraphNode</code>.
      *
      * @return <code>true</code> if the node is the target of an edge.
      */
-    public boolean hasEdge(DigraphNode node) {
+    public boolean hasEdge(DigraphNode<E> node) {
         return outNodes.contains(node);
     }
 
     /**
      * Removes a directed edge from the graph.  The outNodes list of this
      * node is updated and the in-degree of the other node is decremented.
      *
      * @return <code>true</code> if the node was previously the target
      * of an edge.
      */
-    public boolean removeEdge(DigraphNode node) {
+    public boolean removeEdge(DigraphNode<E> node) {
         if (!outNodes.contains(node)) {
             return false;
         }
 
         outNodes.remove(node);

@@ -130,19 +130,21 @@
     /**
      * Removes this node from the graph, updating neighboring nodes
      * appropriately.
      */
     public void dispose() {
-        Object[] inNodesArray = inNodes.toArray();
+        @SuppressWarnings("unchecked")
+        DigraphNode<E>[] inNodesArray = (DigraphNode<E>[])inNodes.toArray();
         for(int i=0; i<inNodesArray.length; i++) {
-            DigraphNode node = (DigraphNode) inNodesArray[i];
+            DigraphNode<E> node = inNodesArray[i];
             node.removeEdge(this);
         }
 
-        Object[] outNodesArray = outNodes.toArray();
+        @SuppressWarnings("unchecked")
+        DigraphNode<E>[] outNodesArray = (DigraphNode<E>[])outNodes.toArray();
         for(int i=0; i<outNodesArray.length; i++) {
-            DigraphNode node = (DigraphNode) outNodesArray[i];
+            DigraphNode<E> node = outNodesArray[i];
             removeEdge(node);
         }
     }
 
     /** Returns the in-degree of this node. */