Revision: 14498
          http://gate.svn.sourceforge.net/gate/?rev=14498&view=rev
Author:   markagreenwood
Date:     2011-11-05 11:53:30 +0000 (Sat, 05 Nov 2011)
Log Message:
-----------
squashed some more FindBugs issues, mostly via code simplification and some 
added generics information

Modified Paths:
--------------
    gate/trunk/src/com/ontotext/gate/vr/ClassNode.java
    gate/trunk/src/com/ontotext/gate/vr/MappingTreeView.java
    gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java
    gate/trunk/src/gate/creole/gazetteer/MappingNode.java

Modified: gate/trunk/src/com/ontotext/gate/vr/ClassNode.java
===================================================================
--- gate/trunk/src/com/ontotext/gate/vr/ClassNode.java  2011-11-05 02:17:27 UTC 
(rev 14497)
+++ gate/trunk/src/com/ontotext/gate/vr/ClassNode.java  2011-11-05 11:53:30 UTC 
(rev 14498)
@@ -219,7 +219,7 @@
     return children.indexOf(child);
   }
 
-  public Iterator getChildren() {
+  public Iterator<ClassNode> getChildren() {
     return children.iterator();
   }
 
@@ -227,7 +227,7 @@
     children = chldrn;
   }
 
-  public Vector children() {
+  public Vector<ClassNode> children() {
     return children;
   }
 
@@ -243,15 +243,26 @@
     return children.get(index);
   }
 
-  public boolean equals(Object o) {
-    boolean result = false;
-    if (o instanceof ClassNode) {
-      ClassNode node = (ClassNode) o;
-      result = node.source.equals(this.source);
-    }
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((source == null) ? 0 : source.hashCode());
     return result;
   }
 
+  @Override
+  public boolean equals(Object obj) {
+    if(this == obj) return true;
+    if(obj == null) return false;
+    if(getClass() != obj.getClass()) return false;
+    ClassNode other = (ClassNode)obj;
+    if(source == null) {
+      if(other.source != null) return false;
+    } else if(!source.equals(other.source)) return false;
+    return true;
+  }
+
   /**Gets the Source object
    * @return the source object e.g. an gate.creole.TClass
    * or a gate.creole.Ontology   */

Modified: gate/trunk/src/com/ontotext/gate/vr/MappingTreeView.java
===================================================================
--- gate/trunk/src/com/ontotext/gate/vr/MappingTreeView.java    2011-11-05 
02:17:27 UTC (rev 14497)
+++ gate/trunk/src/com/ontotext/gate/vr/MappingTreeView.java    2011-11-05 
11:53:30 UTC (rev 14498)
@@ -1,17 +1,31 @@
 package com.ontotext.gate.vr;
 
-import javax.swing.*;
-import javax.swing.tree.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import gate.gui.*;
-import gate.util.*;
-import gate.creole.gazetteer.*;
-import gate.creole.ontology.*;
+import gate.creole.gazetteer.MappingDefinition;
+import gate.creole.gazetteer.MappingNode;
+import gate.creole.ontology.OClass;
+import gate.gui.MainFrame;
+import gate.util.LazyProgrammerException;
 
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
 
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
 
+
+
 /**
  * Mapping Tree View extends {@link javax.swing.JTree}
  * in order to represent the mapping information.
@@ -132,8 +146,7 @@
 
       public void mouseClicked(MouseEvent e){
           TreePath path=MappingTreeView.this.getSelectionPath();
-          javax.swing.JTree tree = new javax.swing.JTree();
-
+          
           ClassNode node =null;
           if (SwingUtilities.isLeftMouseButton(e)) {
             if (2 == e.getClickCount()) {
@@ -167,14 +180,13 @@
   /*Action Listener of the remove pop up menu item */
   class RemoveAL implements ActionListener{
     public void actionPerformed(ActionEvent e) {
-      JMenuItem item = (JMenuItem)e.getSource();
       ClassNode node = 
(ClassNode)MappingTreeView.this.getLastSelectedPathComponent();
       Object source = node.getSource();
       if (source instanceof MappingNode) {
         TreePath pp = 
MappingTreeView.this.getAnchorSelectionPath().getParentPath();
         if (null!=pp) {
           ClassNode pNode = (ClassNode)pp.getLastPathComponent();
-          Vector kids = pNode.children();
+          Vector<ClassNode> kids = pNode.children();
           kids.remove(node);
           pNode.setChildren(kids);
           mapping.remove(source);
@@ -189,11 +201,10 @@
   /*Action Listener of the insert pop up menu item */
   class InsertAL implements ActionListener {
     public void actionPerformed(ActionEvent e) {
-      JMenuItem item = (JMenuItem)e.getSource();
       ClassNode node = 
(ClassNode)MappingTreeView.this.getLastSelectedPathComponent();
       Object source = node.getSource();
       if (source instanceof OClass) {
-        java.util.List lists = gaze.getLists();
+        List lists = gaze.getLists();
         Collections.sort(lists);
 
         Object result = JOptionPane.showInputDialog(MappingTreeView.this,
@@ -208,7 +219,7 @@
               node.toString());
           mapping.add(mn);
           ClassNode cn = new ClassNode(mn);
-          Vector kids = node.children();
+          Vector<ClassNode> kids = node.children();
           kids.add(cn);
           MappingTreeView.this.updateUI();
           gaze.updateMappingUI();

Modified: gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java 2011-11-05 
02:17:27 UTC (rev 14497)
+++ gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java 2011-11-05 
11:53:30 UTC (rev 14498)
@@ -26,7 +26,7 @@
 
 /** Represents a mapping definition which maps gazetteer lists to ontology 
classes */
 public class MappingDefinition extends gate.creole.AbstractLanguageResource
-                              implements List {
+                              implements List<MappingNode> {
 
   private static final long serialVersionUID = 3617291212063848503L;
 
@@ -173,7 +173,7 @@
    * @param o a node
    * @return true if the list of node is not already mapped with another node.
    */
-  public boolean add(Object o) {
+  public boolean add(MappingNode o) {
     boolean result = false;
     if (o instanceof MappingNode) {
       String list = ((MappingNode)o).getList();
@@ -191,7 +191,7 @@
    * @param o a node
    * @param index position in the list
    */
-  public void add(int index,Object o) {
+  public void add(int index,MappingNode o) {
     if (o instanceof MappingNode) {
       String list = ((MappingNode)o).getList();
       if (!nodesByList.containsKey(list)) {
@@ -202,11 +202,11 @@
     } // if a linear node
   } // add()
 
-  public Object set(int index, Object o) {
+  public MappingNode set(int index, MappingNode o) {
     throw new UnsupportedOperationException("this method has not been 
implemented");
   }
 
-  public Object get(int index){
+  public MappingNode get(int index){
     return nodes.get(index);
   }
 
@@ -221,8 +221,8 @@
     return result;
   }// remove
 
-  public Object remove(int index) {
-    Object result = null;
+  public MappingNode remove(int index) {
+    MappingNode result = null;
     result = nodes.remove(index);
     if (null!=result) {
       String list = ((MappingNode)result).getList();
@@ -243,7 +243,7 @@
     while (iter.hasNext()) {
       o = iter.next();
       if (o instanceof MappingNode)  {
-        result |= add(o);
+        result |= add((MappingNode)o);
       } // instance of MappingNode
     } // while
     return result;
@@ -256,7 +256,7 @@
     while (iter.hasNext()) {
       o = iter.next();
       if (o instanceof MappingNode)  {
-        add(index++, o);
+        add(index++, (MappingNode)o);
       } // instance of MappingNode
     } // while
     return (size!=nodes.size());

Modified: gate/trunk/src/gate/creole/gazetteer/MappingNode.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/MappingNode.java       2011-11-05 
02:17:27 UTC (rev 14497)
+++ gate/trunk/src/gate/creole/gazetteer/MappingNode.java       2011-11-05 
11:53:30 UTC (rev 14498)
@@ -15,11 +15,15 @@
  */
 package gate.creole.gazetteer;
 
+import java.io.Serializable;
 
 
+
 /**Represents a single node from the mapping definition*/
-public class MappingNode{
+public class MappingNode implements Serializable {
 
+  private static final long serialVersionUID = -4410243081697344856L;
+
   /** the gazetteer list filename */
   private String list;
   /** the class associated with the list */

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to