View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.map;
24  
25  import java.io.ObjectStreamException;
26  import java.util.Calendar;
27  import java.util.Collection;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /***
32   * Constants of Notes data types.
33   *
34   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
35   */
36  public final class NotesType {
37  
38      /*** Integer constant for data type TEXT. */
39      private static final Integer TEXT_TYPE = new Integer(1);
40  
41      /*** Integer constant for data type NUMBER. */
42      private static final Integer NUMBER_TYPE = new Integer(2);
43  
44      /*** Integer constant for data type DATE. */
45      private static final Integer DATE_TYPE = new Integer(3);
46  
47      /*** Data type TEXT. */
48      public static final NotesType TEXT = new NotesType(TEXT_TYPE, "TEXT".intern(), String.class);
49  
50      /*** Data type NUMBER. */
51      public static final NotesType NUMBER = new NotesType(NUMBER_TYPE, "NUMBER".intern(), Number.class);
52  
53      /*** Data type DATE. */
54      public static final NotesType DATE = new NotesType(DATE_TYPE, "DATE".intern(), Calendar.class);
55  
56      /*** Integer constant identifying a type. */
57      private final Integer type;
58  
59      /*** Textual representation of a type. */
60      private final String name;
61  
62      /*** Corresponding Java type. */
63      private final Class clazz;
64  
65      /*** Map of all values. */
66      private static Map values = new HashMap();
67      static {
68          values.put(TEXT_TYPE, TEXT);
69          values.put(NUMBER_TYPE, NUMBER);
70          values.put(DATE_TYPE, DATE);
71      }
72  
73      /***
74       * Constructor.
75       *
76       * @param type type constant
77       */
78      private NotesType(final Integer type, final String name, final Class clazz) {
79          this.type = type;
80          this.name = name;
81          this.clazz = clazz;
82      }
83  
84      /***
85       * Returns a collection of all possible values.
86       *
87       * @return collection of possible values
88       */
89      public static Collection getValues() {
90          return values.values();
91      }
92  
93      /***
94       * Returns the name of a Notes type.
95       *
96       * @return name
97       */
98      public String getName() {
99          return name;
100     }
101 
102     /***
103      * Returns the Java class used to represent values of a Notes type.
104      *
105      * @return Java class
106      */
107     public Class getJavaClass() {
108         return clazz;
109     }
110 
111     /***
112      * {@inheritDoc}
113      * @see java.lang.Object#equals(java.lang.Object)
114      */
115     public boolean equals(final Object obj) {
116         return (obj instanceof NotesType) && (type.intValue() == ((NotesType) obj).type.intValue());
117     }
118 
119     /***
120      * {@inheritDoc}
121      * @see java.lang.Object#hashCode()
122      */
123     public int hashCode() {
124         return type.intValue();
125     }
126 
127     /***
128      * {@inheritDoc}
129      * @see java.lang.Object#toString()
130      */
131     public String toString() {
132         return name;
133     }
134 
135     /***
136      * Serialization helper used to resolve the enumeration instances.
137      */
138     private Object readResolve() throws ObjectStreamException {
139         return values.get(this.type);
140     }
141 }