OSDN Git Service

checkstyle警告に対処
authorOlyutorskii <olyutorskii@users.osdn.me>
Tue, 14 Jun 2016 01:56:50 +0000 (10:56 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Tue, 14 Jun 2016 01:56:50 +0000 (10:56 +0900)
src/main/java/jp/sourceforge/jindolf/corelib/DateUtils.java
src/main/java/jp/sourceforge/jindolf/corelib/GameRole.java
src/main/java/jp/sourceforge/jindolf/corelib/LandDef.java
src/main/java/jp/sourceforge/jindolf/corelib/PreDefAvatar.java

index 7b19a5f..d98b1a2 100644 (file)
@@ -24,25 +24,30 @@ final class DateUtils{
     private static final String REG_HYPHEN = "\\-";
 
     static{
+        StringBuilder txt = new StringBuilder();
+
         String gYear   = "([0-9][0-9][0-9][0-9])";
         String gMonth  = "([0-1][0-9])";
         String gDay    = "([0-3][0-9])";
-        String gHour   = "([0-2][0-9])";
-        String gMinute = "([0-5][0-9])";
-        String gSecond = "([0-6][0-9])";
 
-        String diffHour = "[" + REG_PLUS + REG_HYPHEN + "][0-2][0-9]";
-        String diffMin  = "(?:" + ":?[0-5][0-9]" + ")?";
-        String gTimezone = "(" + diffHour + diffMin + "|Z)";
-
-        StringBuilder txt = new StringBuilder();
         txt.append(gYear).append(REG_HYPHEN);
         txt.append(gMonth).append(REG_HYPHEN);
         txt.append(gDay);
+
         txt.append('T');
+
+        String gHour   = "([0-2][0-9])";
+        String gMinute = "([0-5][0-9])";
+        String gSecond = "([0-6][0-9])";
+
         txt.append(gHour).append(':');
         txt.append(gMinute).append(':');
         txt.append(gSecond);
+
+        String diffHour = "[" + REG_PLUS + REG_HYPHEN + "][0-2][0-9]";
+        String diffMin  = "(?:" + ":?[0-5][0-9]" + ")?";
+        String gTimezone = "(" + diffHour + diffMin + "|Z)";
+
         txt.append(gTimezone);
 
         String iso8601Regex = txt.toString();
index f30f19c..f6e3ef1 100644 (file)
@@ -17,21 +17,21 @@ import java.util.regex.Pattern;
 public enum GameRole{
 
     /** 村人。 */
-    INNOCENT("村人", '村', "innocent", Team.VILLAGE),
+    INNOCENT("村人", '村', "innocent",         Team.VILLAGE, -50),
     /** 人狼。 */
-    WOLF("人狼", '狼', "wolf", Team.WOLF),
+    WOLF("人狼", '狼', "wolf",                 Team.WOLF,    +20),
     /** 占い師。 */
-    SEER("占い師", '占', "seer", Team.VILLAGE),
+    SEER("占い師", '占', "seer",               Team.VILLAGE, -30),
     /** 霊能者。 */
-    SHAMAN("霊能者", '霊', "shaman", Team.VILLAGE),
+    SHAMAN("霊能者", '霊', "shaman",           Team.VILLAGE, -20),
     /** 狂人。 */
-    MADMAN("狂人", '狂', "madman", Team.WOLF),
+    MADMAN("狂人", '狂', "madman",             Team.WOLF,    +10),
     /** 狩人。 */
-    HUNTER("狩人", '狩', "hunter", Team.VILLAGE),
+    HUNTER("狩人", '狩', "hunter",             Team.VILLAGE, -10),
     /** 共有者。 */
-    FRATER("共有者", '共', "frater", Team.VILLAGE),
+    FRATER("共有者", '共', "frater",           Team.VILLAGE, -40),
     /** ハムスター人間。 */
-    HAMSTER("ハムスター人間", '公', "hamster", Team.HAMSTER),
+    HAMSTER("ハムスター人間", '公', "hamster", Team.HAMSTER,   0),
     ;
 
     private static final Comparator<GameRole> BALANCE_COMPARATOR =
@@ -57,6 +57,7 @@ public enum GameRole{
     private final char shortName;
     private final String xmlName;
     private final Team team;
+    private final int order;
 
 
     /**
@@ -65,15 +66,18 @@ public enum GameRole{
      * @param shortName 短縮名
      * @param xmlName XML用シンボル
      * @param team 陣営
+     * @param order 順位
      */
     private GameRole(String roleName,
                       char shortName,
                       String xmlName,
-                      Team team ){
+                      Team team,
+                      int order ){
         this.roleName = roleName.intern();
         this.shortName = shortName;
         this.xmlName = xmlName.intern();
         this.team = team;
+        this.order = order;
         return;
     }
 
@@ -141,9 +145,19 @@ public enum GameRole{
     }
 
     /**
+     * 順位を返す。
+     * @return 順位
+     */
+    private int getOrder(){
+        return this.order;
+    }
+
+
+    /**
      * 勢力バランス表記用Comparator。
      * 「村共占霊狩公狂狼」の順で役職を一意に順序づける。
      */
+    @SuppressWarnings("serial")
     private static final class PowerBalanceComparator
             implements Comparator<GameRole> {
 
@@ -159,28 +173,12 @@ public enum GameRole{
          * 役職に順序を割り当てる。
          * 村人陣営のほうが狼陣営より小さい値を返す。
          * @param role 役職
-         * @return 強さ
+         * @return 順位
          */
         private static int getPowerValue(GameRole role){
-            int power;
-
             if(role == null) return Integer.MIN_VALUE;
-
-            switch(role){
-            case INNOCENT: power = -50; break;
-            case FRATER:   power = -40; break;
-            case SEER:     power = -30; break;
-            case SHAMAN:   power = -20; break;
-            case HUNTER:   power = -10; break;
-            case HAMSTER:  power =   0; break;
-            case MADMAN:   power = +10; break;
-            case WOLF:     power = +20; break;
-            default:
-                assert false;
-                throw new AssertionError();
-            }
-
-            return power;
+            int result = role.getOrder();
+            return result;
         }
 
         /**
@@ -191,9 +189,9 @@ public enum GameRole{
          */
         @Override
         public int compare(GameRole role1, GameRole role2){
-            int power1 = getPowerValue(role1);
-            int power2 = getPowerValue(role2);
-            return power1 - power2;
+            int order1 = getPowerValue(role1);
+            int order2 = getPowerValue(role2);
+            return order1 - order2;
         }
 
     }
index 8675f88..4e08c83 100644 (file)
@@ -49,6 +49,9 @@ public final class LandDef{
 
     private static final Map<String, LandState> STATE_MAP;
 
+    /** space or tab. */
+    private static final String REG_POSIXBLANK = "\\p{Blank}";
+
     private static final char HYPHEN_CH = '-';
     private static final String HYPHEN = "-";
     private static final String COMMA = ",";
@@ -148,14 +151,13 @@ public final class LandDef{
 
         if(seq.length() <= 0 ) return result;
         String str = seq.toString();
-        str = str.replaceAll("\\p{Blank}", "");
+        str = str.replaceAll(REG_POSIXBLANK, "");
 
         String[] tokens = str.split(COMMA);
         assert tokens.length >= 1;
         for(String token : tokens){
             if(token.length() <= 0) continue;
-            if(   token.charAt(0) == HYPHEN_CH
-               || token.endsWith(HYPHEN) ){
+            if(token.charAt(0) == HYPHEN_CH || token.endsWith(HYPHEN)){
                 throw new IllegalArgumentException(token);
             }
             parseIntPair(result, token);
@@ -222,9 +224,9 @@ public final class LandDef{
         String formalName = DomUtils.attrRequired(elem, "formalName");
         String landPrefix = DomUtils.attrRequired(elem, "landPrefix");
 
-        if(   landName  .length() <= 0
-           || landId    .length() <= 0
-           || formalName.length() <= 0 ){
+        if(    landName  .length() <= 0
+            || landId    .length() <= 0
+            || formalName.length() <= 0 ){
             throw new SAXException("no identification info");
         }
 
@@ -250,8 +252,8 @@ public final class LandDef{
         int minMembers = Integer.parseInt(minStr);
         int maxMembers = Integer.parseInt(maxStr);
 
-        if(   minMembers <= 0
-           || minMembers > maxMembers ){
+        if(    minMembers <= 0
+            || minMembers > maxMembers ){
             throw new SAXException("invalid member limitation");
         }
 
@@ -274,8 +276,8 @@ public final class LandDef{
         if(webURI == null || cgiURI == null){
             throw new SAXException("no URI");
         }
-        if(   ! webURI.isAbsolute()
-           || ! cgiURI.isAbsolute() ){
+        if(    ! webURI.isAbsolute()
+            || ! cgiURI.isAbsolute() ){
             throw new SAXException("relative URI");
         }
 
index 8b5f620..4182fa7 100644 (file)
@@ -43,16 +43,16 @@ public final class PreDefAvatar{
                          int serialNo ){
         super();
 
-        if(   avatarId  == null
-           || fullName  == null
-           || jobTitle  == null
-           || shortName == null ){
+        if(    avatarId  == null
+            || fullName  == null
+            || jobTitle  == null
+            || shortName == null ){
             throw new NullPointerException();
         }
 
-        if(   avatarId.length() <= 0
-           || fullName.length() <= 0
-           || serialNo < 0 ){
+        if(    avatarId.length() <= 0
+            || fullName.length() <= 0
+            || serialNo < 0 ){
             throw new IllegalArgumentException();
         }