devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693377 - /devicemap/trunk/clients/2.0/reference/src/Pattern.java
Date Thu, 30 Jul 2015 01:02:01 GMT
Author: rezan
Date: Thu Jul 30 01:02:01 2015
New Revision: 1693377

URL: http://svn.apache.org/r1693377
Log:
enums

Modified:
    devicemap/trunk/clients/2.0/reference/src/Pattern.java

Modified: devicemap/trunk/clients/2.0/reference/src/Pattern.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Pattern.java?rev=1693377&r1=1693376&r2=1693377&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Pattern.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Pattern.java Thu Jul 30 01:02:01 2015
@@ -24,12 +24,20 @@ import org.codehaus.jackson.JsonNode;
 
 public class Pattern {
   private final String patternId;
-  private final String patternType;
+  private final PatternType patternType;
   private final List<String> patternTokens;
 
-  private final String rankType;
+  private final RankType rankType;
   private final int rankValue;
 
+  private enum PatternType {
+    Simple, SimpleAnd, SimpleOrderedAnd
+  };
+
+  private enum RankType {
+    Strong, Weak, None
+  };
+
   public Pattern(JsonNode json) throws Exception {
     if(json.get("patternId") == null || json.get("patternId").asText().isEmpty()) {
       throw new Exception("patternId not found");
@@ -49,18 +57,8 @@ public class Pattern {
       throw new Exception("rankType not found in " + patternId);
     }
 
-    patternType = json.get("patternType").asText();
-    rankType = json.get("rankType").asText();
-
-    if(!patternType.equals("SimpleOrderedAnd") && !patternType.equals("SimpleAnd")
&&
-        !patternType.equals("Simple")) {
-      throw new Exception("Invalid patternType: " + patternType);
-    }
-
-    if(!rankType.equals("Strong") && !rankType.equals("Weak") &&
-        !rankType.equals("None")) {
-      throw new Exception("Invalid rankType: " + rankType);
-    }
+    patternType = PatternType.valueOf(json.get("patternType").asText());
+    rankType = RankType.valueOf(json.get("rankType").asText());
 
     String rankValueStr = (json.get("rankValue") != null ? json.get("rankValue").asText()
: "0");
     rankValue = Integer.parseInt(rankValueStr);
@@ -147,26 +145,26 @@ public class Pattern {
   }
 
   public boolean isStrong() {
-    return rankType.equals("Strong");
+    return rankType.equals(RankType.Strong);
   }
 
   public boolean isWeak() {
-    return rankType.equals("Weak");
+    return rankType.equals(RankType.Weak);
   }
 
   public boolean isNone() {
-    return rankType.equals("None");
+    return rankType.equals(RankType.None);
   }
 
   public boolean isSimple() {
-    return patternType.equals("Simple");
+    return patternType.equals(PatternType.Simple);
   }
 
   public boolean isSimpleAnd() {
-    return patternType.equals("SimpleAnd");
+    return patternType.equals(PatternType.SimpleAnd);
   }
 
   public boolean isSimpleOrderedAnd() {
-    return patternType.equals("SimpleOrderedAnd");
+    return patternType.equals(PatternType.SimpleOrderedAnd);
   }
 }



Mime
View raw message