View Javadoc

1   /*
2   @See License.txt@
3    */
4   
5   package spellcast.beings;
6   
7   import java.io.*;
8   
9   /***
10   *
11   * @author Barrie Treloar
12   */
13  public abstract class Gender
14      implements Serializable
15  {
16      public static final Gender MALE = new Male();
17      public static final Gender FEMALE = new Female();
18      public static final Gender NEUTER = new Neuter();
19      public static final Gender NONE = new GenderNone();
20  
21      /***
22       * A list of genders that are available in their string form.
23       * These are "Male", "Female", "Neuter", "None".
24       */
25      public static final String[] GENDERS_AS_STRINGS = { Male.GENDER, 
26                                                          Female.GENDER, 
27                                                          Neuter.GENDER,
28                                                          GenderNone.GENDER };
29  
30      private static final Gender[] GENDERS = { MALE, FEMALE, NEUTER, NONE };
31  
32      private String genderString;
33  
34      public Gender( String genderString )
35      {
36          this.genderString = genderString;
37      } 
38      
39      /***
40       * Get the value of genderString.
41       *
42       * @return value of genderString.
43       */
44      public String getGenderString() 
45      {
46          return genderString;
47      }
48      
49      /***
50       * Set the value of genderString.
51       *
52       * @param v Value to assign to genderString.
53       */
54      public void setGenderString( String v ) 
55      {
56          genderString = v;
57      }
58  
59      /***
60       * Return the "himself" like pronoun.
61       */
62      public abstract String pro_himself();   
63  
64      /***
65       * Return the "him" like pronoun.
66       */
67      public abstract String pro_him();
68  
69      /***
70       * Return the "he" like pronoun.
71       */
72      public abstract String pro_he();
73  
74      /***
75       * Return the "his" like pronoun.
76       */ 
77      public abstract String pro_his();
78  
79      public boolean equals( Object o )
80      {
81          boolean result = false;
82          
83          if ( o instanceof Gender )
84          {
85              Gender other = (Gender)o;
86              if ( getGenderString().equals( other.getGenderString() ) )
87              {
88                  result = true;
89              }
90          }
91          
92          return result;
93      }
94  
95      /***
96       * Given a string return the matching gender object (case is insensitive). 
97       * If unknown gender return null.
98       *
99       * @param genderString must be on of the strings listed in <code>GENDERS_AS_STRINGS</code>
100      * @return the matching Gender object for the string or null if unkown.
101      */
102     public static Gender getGender( String genderString )
103     {
104         Gender result = null;
105 
106         for ( int i = 0; i < GENDERS_AS_STRINGS.length; i++ )
107         {
108             if ( GENDERS_AS_STRINGS[ i ].equalsIgnoreCase( genderString ) )
109             {
110                 result = GENDERS[ i ];
111                 break;
112             }
113         }
114         return result;
115     }
116 
117 }
118