PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/pkg/ParamValueType.java

http://mobicents.googlecode.com/
Java | 81 lines | 63 code | 18 blank | 0 comment | 2 complexity | 077d7cfa8a9d9d648fb0ef9f9fc5941e MD5 | raw file
 1package javax.megaco.pkg;
 2
 3import java.io.Serializable;
 4
 5public final class ParamValueType implements Serializable {
 6	public static final int M_STRING = 1;
 7	public static final int M_INTEGER = 2;
 8	public static final int M_BOOLEAN = 3;
 9	public static final int M_DOUBLE = 4;
10
11	public static final ParamValueType STRING = new ParamValueType(M_STRING);
12	public static final ParamValueType INTEGER = new ParamValueType(M_INTEGER);
13	public static final ParamValueType BOOLEAN = new ParamValueType(M_BOOLEAN);
14	public static final ParamValueType DOUBLE = new ParamValueType(M_DOUBLE);
15
16	private int value_type;
17
18	private ParamValueType(int value_type) {
19		this.value_type = value_type;
20	}
21
22	public int getParamValueType() {
23		return this.value_type;
24	}
25
26	public static final ParamValueType getObject(int value) throws IllegalArgumentException {
27		ParamValueType p = null;
28		switch (value) {
29		case M_STRING:
30			p = STRING;
31			break;
32
33		case M_INTEGER:
34			p = INTEGER;
35			break;
36
37		case M_BOOLEAN:
38			p = BOOLEAN;
39			break;
40
41		case M_DOUBLE:
42			p = DOUBLE;
43			break;
44
45		default:
46			throw new IllegalArgumentException("No ParamValueType for passed value " + value);
47		}
48		return p;
49	}
50
51	private Object readResolve() {
52		return this.getObject(this.value_type);
53	}
54
55	@Override
56	public String toString() {
57		String p = null;
58		switch (this.value_type) {
59		case M_STRING:
60			p = "ParamValueType[STRING]";
61			break;
62
63		case M_INTEGER:
64			p = "ParamValueType[INTEGER]";
65			break;
66
67		case M_BOOLEAN:
68			p = "ParamValueType[BOOLEAN]";
69			break;
70
71		case M_DOUBLE:
72			p = "ParamValueType[DOUBLE]";
73			break;
74
75		default:
76			p = "ParamValueType[" + this.value_type + "]";
77		}
78		return p;
79	}
80
81}