package editor.database.characteristics;

/**
 * This enum represents a rarity a Magic: The Gathering card can have.  Rarities
 * are basically Strings, so they implement {@link CharSequence}.  All of the
 * implemented methods operate on a Rarity's String representation from
 * {@link #toString()}.
 *
 * @author Alec Roelke
 */
public enum Rarity implements CharSequence
{
    /**
     * Rarity for basic lands.
     */
    BASIC_LAND("Basic Land"),
    /**
     * Common rarity.
     */
    COMMON("Common"),
    /**
     * Uncommon rarity.
     */
    UNCOMMON("Uncommon"),
    /**
     * Rare rarity.
     */
    RARE("Rare"),
    /**
     * Mythic rare rarity.
     */
    MYTHIC_RARE("Mythic Rare"),
    /**
     * "Special" rarity, such as timeshifted.
     */
    SPECIAL("Special");

    /**
     * Create a rarity from a shorthand character.
     *
     * @param rarity Character to create a Rarity from
     * @return a Rarity representing the specified shorthand character
     * @throws IllegalArgumentException if a Rarity cannot be created from the specified character
     */
    public static Rarity parseRarity(char rarity)
    {
        switch (Character.toLowerCase(rarity))
        {
        case 'c':
            return COMMON;
        case 'u':
            return UNCOMMON;
        case 'r':
            return RARE;
        case 'm':
            return MYTHIC_RARE;
        case 's':
            return SPECIAL;
        case 'b':
            return BASIC_LAND;
        default:
            throw new IllegalArgumentException("Illegal rarity shorthand");
        }
    }

    /**
     * Create a Rarity from the specified String.
     *
     * @param rarity String to create a Rarity from
     * @return a Rarity representing the specified String
     * @throws IllegalArgumentException if a Rarity cannot be created from the String
     */
    public static Rarity parseRarity(String rarity)
    {
        if (rarity.contains("mythic"))
            return MYTHIC_RARE;
        else if (rarity.contains("rare"))
            return RARE;
        else if (rarity.contains("uncommon"))
            return UNCOMMON;
        else if (rarity.contains("common"))
            return COMMON;
        else if (rarity.contains("basic"))
            return BASIC_LAND;
        else
        {
            System.err.println("warning: Could not determine rarity of \"" + rarity + '"');
            return SPECIAL;
        }
    }

    /**
     * String representation of this Rarity.
     */
    private final String rarity;

    /**
     * Create a new Rarity.
     *
     * @param rarity String representation of the new Rarity.
     */
    Rarity(final String rarity)
    {
        this.rarity = rarity;
    }

    @Override
    public char charAt(int index)
    {
        return rarity.charAt(index);
    }

    @Override
    public int length()
    {
        return rarity.length();
    }

    /**
     * Get the shorthand character for this Rarity.
     *
     * @return A shorthand character representing this Rarity.
     */
    public char shorthand()
    {
        switch (this)
        {
        case COMMON:
            return 'C';
        case UNCOMMON:
            return 'U';
        case RARE:
            return 'R';
        case MYTHIC_RARE:
            return 'M';
        case SPECIAL:
            return 'S';
        case BASIC_LAND:
            return 'B';
        default:
            return '\0';
        }
    }

    @Override
    public CharSequence subSequence(int start, int end)
    {
        return rarity.subSequence(start, end);
    }

    @Override
    public String toString()
    {
        return rarity;
    }
}

@@ -35,16 +35,64 @@
 stics;%0A%0A
+import org.apache.commons.codec.binary.Base32;%0A%0A
 /**%0A * T
@@ -1191,32 +1191,39 @@
 )%0A    %7B%0A        
+return 
 switch (Characte
@@ -1244,27 +1244,23 @@
 rarity))
-%0A    
+ %7B%0A
     
-%7B%0A
         
@@ -1267,36 +1267,19 @@
 case 'c'
-:%0A            return
+ -%3E
  COMMON;
@@ -1271,32 +1271,36 @@
  'c' -%3E COMMON;%0A
+    
         case 'u'
@@ -1299,36 +1299,19 @@
 case 'u'
-:%0A            return
+ -%3E
  UNCOMMO
@@ -1325,16 +1325,20 @@
     
+    
 case 'r'
 :%0A  
@@ -1337,35 +1337,22 @@
  'r'
-:%0A            return
+ -%3E
  RARE;%0A
+    
     
@@ -1363,36 +1363,19 @@
 case 'm'
-:%0A            return
+ -%3E
  MYTHIC_
@@ -1392,16 +1392,20 @@
     
+  
+  
 case 's'
 :%0A  
@@ -1400,36 +1400,19 @@
 case 's'
-:%0A            return
+ -%3E
  SPECIAL
@@ -1425,16 +1425,20 @@
     
+    
 case 'b'
 :%0A  
@@ -1433,36 +1433,19 @@
 case 'b'
-:%0A            return
+ -%3E
  BASIC_L
@@ -1457,36 +1457,30 @@
         
+    
 default
-:%0A           
+ -%3E
  throw n
@@ -1537,32 +1537,33 @@
 and%22);%0A        %7D
+;
 %0A    %7D%0A%0A    /**%0A
@@ -3043,16 +3043,23 @@
         
+return 
 switch (
@@ -3063,24 +3063,26 @@
 h (this)
+ %7B
 %0A       
  %7B%0A     
@@ -3073,27 +3073,21 @@
 %0A       
- %7B%0A
      
-   
 case COM
@@ -3093,34 +3093,26 @@
 MMON
-:%0A            return
+      -%3E
  'C';%0A
+    
     
@@ -3132,34 +3132,24 @@
 MMON
-:%0A
     
-        return
+-%3E
  'U';%0A
+    
     
@@ -3157,34 +3157,32 @@
    case RARE
-:%0A
         
     return '
@@ -3173,24 +3173,20 @@
     
-    return
+-%3E
  'R';%0A
+    
     
@@ -3209,34 +3209,21 @@
 RARE
-:%0A            return
+ -%3E
  'M';%0A
+    
     
@@ -3242,34 +3242,25 @@
 CIAL
-:%0A  
      
-     return
+-%3E
  'S';%0A
+    
     
@@ -3282,85 +3282,28 @@
 LAND
-:%0A            return 'B';%0A        default:%0A            return '%5C0';%0A        %7D
+  -%3E 'B';%0A        %7D;
 %0A   

Use switch expression for return value