You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2016/12/19 22:43:14 UTC

[08/14] opennlp git commit: Replace == with equals for string compare

Replace == with equals for string compare

Comparing string referencs to check strings are equal
should not be done, in case the strigns somehow change
all those comparisons break. Using equals will result in the
same and only if references are not equal the string will
be compared.

See issue OPENNLP-871


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/6871d116
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/6871d116
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/6871d116

Branch: refs/heads/trunk
Commit: 6871d1164ef22692141f59bb3176bef4c7777771
Parents: e20dc21
Author: J�rn Kottmann <jo...@apache.org>
Authored: Wed Nov 2 20:12:55 2016 +0100
Committer: J�rn Kottmann <jo...@apache.org>
Committed: Mon Dec 19 23:37:33 2016 +0100

----------------------------------------------------------------------
 .../tools/formats/frenchtreebank/ConstitDocumentHandler.java     | 2 +-
 opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java      | 2 +-
 .../src/main/java/opennlp/tools/parser/lang/en/HeadRules.java    | 2 +-
 .../opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java     | 2 +-
 .../src/main/java/opennlp/tools/parser/treeinsert/Parser.java    | 4 ++--
 .../java/opennlp/tools/parser/treeinsert/ParserEventStream.java  | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
index a58b448..2f3cf6a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
@@ -171,7 +171,7 @@ class ConstitDocumentHandler extends DefaultHandler {
           Constituent con = cons.get(ci);
           String type = con.getLabel();
           if (!type.equals(AbstractBottomUpParser.TOP_NODE)) {
-            if (type == AbstractBottomUpParser.TOK_NODE) {
+            if (AbstractBottomUpParser.TOK_NODE.equals(type)) {
               tokenIndex++;
             }
             Parse c = new Parse(txt, con.getSpan(), type, 1,tokenIndex);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
index 4a57ed1..9bf12f3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
@@ -883,7 +883,7 @@ public class Parse implements Cloneable, Comparable<Parse> {
       Constituent con = cons.get(ci);
       String type = con.getLabel();
       if (!type.equals(AbstractBottomUpParser.TOP_NODE)) {
-        if (type == AbstractBottomUpParser.TOK_NODE) {
+        if (AbstractBottomUpParser.TOK_NODE.equals(type)) {
           tokenIndex++;
         }
         Parse c = new Parse(txt, con.getSpan(), type, 1,tokenIndex);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
index a8059db..8a5a947 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
@@ -131,7 +131,7 @@ public class HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler, Se
   }
 
   public Parse getHead(Parse[] constituents, String type) {
-    if (constituents[0].getType() == Parser.TOK_NODE) {
+    if (Parser.TOK_NODE.equals(constituents[0].getType())) {
       return null;
     }
     HeadRule hr;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
index 5118a08..946fa5c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
@@ -132,7 +132,7 @@ public class AncoraSpanishHeadRules implements opennlp.tools.parser.HeadRules, G
   }
 
   public Parse getHead(Parse[] constituents, String type) {
-    if (constituents[0].getType() == Parser.TOK_NODE) {
+    if (Parser.TOK_NODE.equals(constituents[0].getType())) {
       return null;
     }
     HeadRule hr;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/Parser.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/Parser.java b/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/Parser.java
index a06576e..e2c62d7 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/Parser.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/Parser.java
@@ -142,8 +142,8 @@ public class Parser extends AbstractBottomUpParser {
   public static List<Parse> getRightFrontier(Parse root,Set<String> punctSet) {
     List<Parse> rf = new LinkedList<Parse>();
     Parse top;
-    if (root.getType() == AbstractBottomUpParser.TOP_NODE ||
-        root.getType() == AbstractBottomUpParser.INC_NODE) {
+    if (AbstractBottomUpParser.TOP_NODE.equals(root.getType()) ||
+        AbstractBottomUpParser.INC_NODE.equals(root.getType())) {
       top = collapsePunctuation(root.getChildren(),punctSet)[0];
     }
     else {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/6871d116/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/ParserEventStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/ParserEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/ParserEventStream.java
index 6f6c85d..c693ef6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/ParserEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/treeinsert/ParserEventStream.java
@@ -273,7 +273,7 @@ public class ParserEventStream extends AbstractParserEventStream {
         }
         //attach Node
         if (attachNode != null) {
-          if (attachType == Parser.ATTACH_DAUGHTER) {
+          if (Parser.ATTACH_DAUGHTER.equals(attachType)) {
             Parse daughter = currentChunks[ci];
             if (debug) System.err.println("daughter attach a="+attachNode.getType()+":"+attachNode+" d="+daughter+" com="+lastChild(chunks[ci], rightFrontier.get(attachNodeIndex)));
             attachNode.add(daughter,rules);
@@ -290,7 +290,7 @@ public class ParserEventStream extends AbstractParserEventStream {
               }
             }
           }
-          else if (attachType == Parser.ATTACH_SISTER) {
+          else if (Parser.ATTACH_SISTER.equals(attachType)) {
             Parse frontierNode = rightFrontier.get(attachNodeIndex);
             rightFrontier.set(attachNodeIndex,frontierNode.getParent());
             Parse sister = currentChunks[ci];