View Javadoc

1   /*
2    * Copyright (C) 2007 Alf Mikula
3    * 
4    * This file is part of PromoteGo.
5    *
6    * PromoteGo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * PromoteGo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with PromoteGo.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.promotego.beans;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  import javax.persistence.Entity;
25  
26  @Entity
27  public class LocationType extends BeanSupport<LocationType> implements Comparable<LocationType>
28  {
29      private String m_name;
30      private int m_ordinal;
31      
32      /***
33       * Locations to initialize in the database, if none are already present.
34       * Ordinals will be assigned based on the order given here.
35       */
36      private static final String [] s_initialLocations = {
37              "Coffee House", "Library", "Park", "Bookstore", "Go Club", "Other"
38      };
39   
40      public static Set<LocationType> getInitialLocations()
41      {
42          Set<LocationType> retval = new HashSet<LocationType>();
43          
44          int ordinal = 0;
45          for (String name : s_initialLocations)
46          {
47              LocationType thisType = new LocationType();
48              thisType.setName(name);
49              thisType.setOrdinal(ordinal);
50              
51              ordinal++;
52              
53              retval.add(thisType);
54          }
55          
56          return retval;
57      }
58      
59      public String getName()
60      {
61          return m_name;
62      }
63      
64      public void setName(String name)
65      {
66          m_name = name;
67      }
68  
69      public int getOrdinal()
70      {
71          return m_ordinal;
72      }
73  
74      public void setOrdinal(int ordinal)
75      {
76          m_ordinal = ordinal;
77      }
78  
79      public int compareTo(LocationType o)
80      {
81          return getOrdinal() - o.getOrdinal();
82      }
83  }