package com.etretatlogiciels.dvdcatalog.util;

import java.util.*;

/** ----------------------------------------------------------------------------
 ** This is a little class to handle storage of DVD languages supported. It is
 ** consumed by the loader and dumper applications as well as by the web
 ** application.
 **
 ** @author russ
 */
public class LangBits extends BitSet
{
   static final long serialVersionUID = 20051202;

   public LangBits()
   {
      super(32);                       // only a BitSet of this width...
   }

   public void addLang( String lang )
   {
      if (lang.contains("E")) set(0);  // English
      if (lang.contains("F")) set(1);  // French
      if (lang.contains("S")) set(2);  // Spanish
      if (lang.contains("P")) set(3);  // Portuguese
      if (lang.contains("J")) set(4);  // Japanese
      if (lang.contains("C")) set(5);  // Chinese
      if (lang.contains("K")) set(6);  // Korean
      if (lang.contains("G")) set(7);  // Greek
      if (lang.contains("T")) set(8);  // Thai
   }

   public void addListOfLangs( String langs )
   {
      int   length = langs.length();

      while (length > 0)
      {
         addLang(langs.substring(length-1, length));
         length--;
      }
   }

   public int  integerValue()
   {
      int   value, which;

      for (value = which = 0; which < 32; which++)
      {
         if (get(which) == true)
            value += 1 << which;
      }

      return value;
   }

   public String getLangString( int which )
   {
      switch (which)
      {
         default :   return (String) null;
         case 0 :    return "English";
         case 1 :    return "French";
         case 2 :    return "Spanish";
         case 3 :    return "Portuguese";
         case 4 :    return "Japanese";
         case 5 :    return "Chinese";
         case 6 :    return "Korean";
         case 7 :    return "Greek,";
         case 8 :    return "Thai";
      }
   }
}
