package com.etretatlogiciels.dvdcatalog.util;

import java.util.*;

/** ----------------------------------------------------------------------------
 ** This is a little class to handle storage of DVD film genres supported. It is
 ** consumed by the loader and dumper applications as well as by the web
 ** application.
 **
 ** @author russ
 */
public class GenreBits extends BitSet
{
   static final long serialVersionUID = 20051202;
   
   public GenreBits()
   {
      super(32);                       // only a BitSet of this width...
   }

   public void addGenre( String genre )
   {
      if (genre.compareToIgnoreCase("Action")          == 0)   set(0);
      if (genre.compareToIgnoreCase("Adventure")       == 0)   set(1);
      if (genre.compareToIgnoreCase("Cartoon")         == 0)   set(2);
      if (genre.compareToIgnoreCase("Chick Flick")     == 0)   set(3);
      if (genre.compareToIgnoreCase("Comedy")          == 0)   set(4);
      if (genre.compareToIgnoreCase("Drama")           == 0)   set(5);
      if (genre.compareToIgnoreCase("Fantasy")         == 0)   set(6);
      if (genre.compareToIgnoreCase("History,")        == 0)   set(7);
      if (genre.compareToIgnoreCase("Military")        == 0)   set(8);
      if (genre.compareToIgnoreCase("Music")           == 0)   set(9);
      if (genre.compareToIgnoreCase("Musical")         == 0)   set(10);
      if (genre.compareToIgnoreCase("Mystery")         == 0)   set(11);
      if (genre.compareToIgnoreCase("Politics")        == 0)   set(12);
      if (genre.compareToIgnoreCase("Religious")       == 0)   set(13);
      if (genre.compareToIgnoreCase("Science Fiction") == 0)   set(14);
      if (genre.compareToIgnoreCase("Suspense")        == 0)   set(15);
      if (genre.compareToIgnoreCase("Thriller")        == 0)   set(16);
   }

   public void addListOfGenres( String genres )
   {
      StringTokenizer   genreTokens = new StringTokenizer(genres, ",");

      /*
      ** March down the in-coming string parsing out the genres and adding
      ** them the usual way. Return the integer value of the bit set.
      */
      while (genreTokens.hasMoreTokens())
         addGenre(genreTokens.nextToken());
   }

   public int  integerValue()
   {
      int   value, which;

      for (value = which = 0; which < 32; which++)
      {
         if (get(which) == true)
            value += 1 << which;
      }

      return value;
   }

   public String getGenreString( int which )
   {
      switch (which)
      {
         default :   return (String) null;
         case 0 :    return "Action";
         case 1 :    return "Adventure";
         case 2 :    return "Cartoon";
         case 3 :    return "Chick Flick";
         case 4 :    return "Comedy";
         case 5 :    return "Drama";
         case 6 :    return "Fantasy";
         case 7 :    return "History,";
         case 8 :    return "Military";
         case 9 :    return "Music";
         case 10 :   return "Musical";
         case 11 :   return "Mystery";
         case 12 :   return "Politics";
         case 13 :   return "Religious";
         case 14 :   return "Science Fiction";
         case 15 :   return "Suspense";
         case 16 :   return "Thriller";
      }
   }
}
