KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > core > jrrd > DataSourceType


1 /*
2  * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
3  *
4  * Distributable under GPL license.
5  * See terms of license at gnu.org.
6  *
7  * $Id: DataSourceType.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $
8  */

9 package org.jrobin.core.jrrd;
10
11 /**
12  * Class DataSourceType
13  *
14  * @author <a HREF="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
15  * @version $Revision: 1.1 $
16  */

17 public class DataSourceType {
18
19     private static final int _COUNTER = 0;
20     private static final String JavaDoc STR_COUNTER = "COUNTER";
21
22     /**
23      * Field COUNTER
24      */

25     public static final DataSourceType COUNTER =
26             new DataSourceType(_COUNTER);
27     private static final int _ABSOLUTE = 1;
28     private static final String JavaDoc STR_ABSOLUTE = "ABSOLUTE";
29
30     /**
31      * Field ABSOLUTE
32      */

33     public static final DataSourceType ABSOLUTE =
34             new DataSourceType(_ABSOLUTE);
35     private static final int _GAUGE = 2;
36     private static final String JavaDoc STR_GAUGE = "GAUGE";
37
38     /**
39      * Field GAUGE
40      */

41     public static final DataSourceType GAUGE = new DataSourceType(_GAUGE);
42     private static final int _DERIVE = 3;
43     private static final String JavaDoc STR_DERIVE = "DERIVE";
44
45     /**
46      * Field DERIVE
47      */

48     public static final DataSourceType DERIVE = new DataSourceType(_DERIVE);
49     private int type;
50
51     private DataSourceType(int type) {
52         this.type = type;
53     }
54
55     /**
56      * Returns a <code>DataSourceType</code> with the given name.
57      *
58      * @param s name of the <code>DataSourceType</code> required.
59      * @return a <code>DataSourceType</code> with the given name.
60      */

61     public static DataSourceType get(String JavaDoc s) {
62
63         if (s.equalsIgnoreCase(STR_COUNTER)) {
64             return COUNTER;
65         } else if (s.equalsIgnoreCase(STR_ABSOLUTE)) {
66             return ABSOLUTE;
67         } else if (s.equalsIgnoreCase(STR_GAUGE)) {
68             return GAUGE;
69         } else if (s.equalsIgnoreCase(STR_DERIVE)) {
70             return DERIVE;
71         } else {
72             throw new IllegalArgumentException JavaDoc("Invalid DataSourceType");
73         }
74     }
75
76     /**
77      * Compares this object against the specified object.
78      *
79      * @return <code>true</code> if the objects are the same,
80      * <code>false</code> otherwise.
81      */

82     public boolean equals(Object JavaDoc obj) {
83
84         if (!(obj instanceof DataSourceType)) {
85             throw new IllegalArgumentException JavaDoc("Not a DataSourceType");
86         }
87
88         return (((DataSourceType) obj).type == type)
89                 ? true
90                 : false;
91     }
92
93     /**
94      * Returns a string representation of this object.
95      *
96      * @return a string representation of this object.
97      */

98     public String JavaDoc toString() {
99
100         String JavaDoc strType;
101
102         switch (type) {
103
104             case _COUNTER:
105                 strType = STR_COUNTER;
106                 break;
107
108             case _ABSOLUTE:
109                 strType = STR_ABSOLUTE;
110                 break;
111
112             case _GAUGE:
113                 strType = STR_GAUGE;
114                 break;
115
116             case _DERIVE:
117                 strType = STR_DERIVE;
118                 break;
119
120             default :
121                 // Don't you just hate it when you see a line like this?
122
throw new RuntimeException JavaDoc("This should never happen");
123         }
124
125         return strType;
126     }
127 }
128
Popular Tags