// Decompiled version of Breed, showing how
// it works under the hood with enum constant
// objects.

package com.mindprod.example;

import java.io.PrintStream;
// Note The final. Enums cannot be extended.
// The following line won't actually compile since
// the compiler won't let you extend the Enum
// class manually.

public final class Breed extends Enum
   {

   // automatically generated values method uses
   // generated $VALUES array

   public static final Breed[] values()
      {
      return(Breed[])$VALUES.clone();
      }

   // automatically generated valueOf method
   // If there is no match for the String, valueOf will throw an
   // IllegalArgumentException.
   public static Breed valueOf(String s)
      {
      return(Breed)Enum.valueOf(com.mindprod.example.Breed, s);
      }

   // Constructor with two hidden fields:
   // the enum constant name, and the ordinal
   private Breed(String s, int i)
      {
      // Super will save name and ordinal away in instance
      // field of the enum constant.

      super(s, i);
      }

   // How switch works, with a statically-generated table.
   public static boolean lap(Breed breed)
      {
      // switch implemented as a static class, and the equivalent ints.
      // There is almost no extra cpu overhead above using ints.
      static class _cls1
         {

         // array of ints (case#), indexed by ordinal
         static final int $SwitchMap$com$mindprod$example$Breed[];

         static
         {
            // one time static init of array mapping enum ordinals
            // to dense sequential case numbers.
            $SwitchMap$com$mindprod$example$Breed = new int[Breed.values().length];
            try
               {
               // map[1=DALMATIAN] = 1=case1=DALMATIAN

               $SwitchMap$com$mindprod$example$Breed[Breed.DALMATIAN.ordinal()] = 1;
               }
            catch ( NoSuchFieldError nosuchfielderror )
               {
               }
            try
               {
               // map[2=LABRADOR] = 2=case2=LABRADOR
               $SwitchMap$com$mindprod$example$Breed[Breed.LABRADOR.ordinal()] = 2;
               }
            catch ( NoSuchFieldError nosuchfielderror1 )
               {
               }
            try
               {
               // map[0=DACHSHUND] = 2=case2=DACHSHUND

               $SwitchMap$com$mindprod$example$Breed[Breed.DACHSHUND.ordinal()] = 3;
               }
            catch ( NoSuchFieldError nosuchfielderror2 )
               {
               }
         }
         }
      // use an ordinary int switch, using pre-mapped ordinals to sort the switch.

      switch ( _cls1..SwitchMap.com.mindprod.example.Breed[breed.ordinal()] )
         {
         // Note how case numbers are NOT the ordinals!
         // Ordinals are mapped to a smaller set of case numbers
         // before the switch.
         case 1: // '\001'  DALMATIAN
         case 2: // '\002'  LABRADOR
         default:
            return false;

         case 3: // '\003' DACHSHHUND
            return true;
         }
      }

   // using various methods, pretty much as you expect.
   public static void main(String args[])
      {
      Breed breed = LABRADOR;
      out.println(breed);
      out.println(breed.ordinal());
      out.println(DACHSHUND);
      if ( breed.compareTo(DALMATIAN) > 0 )
         out.println("LABRADOR comes after DALMATIAN");
      else
         out.println("DALMATIAN comes after LABRADOR");
      breed = null;
      Breed breed1 = valueOf("Dachshund".toUpperCase());
      out.println(breed1);
      int i = 1;
      Breed breed2 = values()[i];
      out.println(breed2);
      out.println("All possible breeds");
      Breed abreed[] = values();
      int j = abreed.length;
      for ( int k = 0; k < j; k++ )
         {
         Breed breed3 = abreed[k];
         out.println(breed3);
         }

      }

   // Named references to each of the enum constant objects.
   // Note how they are all public even though we did not
   // explicitly declare them so.
   public static final Breed DACHSHUND;
   public static final Breed DALMATIAN;
   public static final Breed LABRADOR;
   private static final Breed $VALUES[];

   static
   {
      // construct the enum constant objects statically
      DACHSHUND = new Breed("DACHSHUND", 0);
      DALMATIAN = new Breed("DALMATIAN", 1);
      LABRADOR = new Breed("LABRADOR", 2);

      // construct the $VALUES array
      $VALUES = (new Breed[] {
                    DACHSHUND, DALMATIAN, LABRADOR
                 });
   }

   // build map of ordinals to case numbers for the switch.
   static class Breed$1
      {

      static final int $SwitchMap$com$mindprod$example$Breed[];

      static
      {
         $SwitchMap$com$mindprod$example$Breed = new int[Breed.values().length];
         try
            {
            $SwitchMap$com$mindprod$example$Breed[Breed.DALMATIAN.ordinal()] = 1;
            }
         catch ( NoSuchFieldError nosuchfielderror )
            {
            }
         try
            {
            $SwitchMap$com$mindprod$example$Breed[Breed.LABRADOR.ordinal()] = 2;
            }
         catch ( NoSuchFieldError nosuchfielderror1 )
            {
            }
         try
            {
            $SwitchMap$com$mindprod$example$Breed[Breed.DACHSHUND.ordinal()] = 3;
            }
         catch ( NoSuchFieldError nosuchfielderror2 )
            {
            }
      }
      }

   }