View Javadoc

1   /*
2    * Copyright 2008-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.entropysoft.transmorph.signature;
17  
18  
19  /**
20   * Signature for a primitive type
21   * 
22   * This class is thread-safe
23   * 
24   * @author Cedric Chabanois (cchabanois at gmail.com)
25   * 
26   */
27  public class PrimitiveTypeSignature extends FullTypeSignature {
28  
29  	public static final char PRIMITIVE_BOOLEAN = 'Z';
30  	public static final char PRIMITIVE_BYTE = 'B';
31  	public static final char PRIMITIVE_CHAR = 'C';
32  	public static final char PRIMITIVE_DOUBLE = 'D';
33  	public static final char PRIMITIVE_FLOAT = 'F';
34  	public static final char PRIMITIVE_INT = 'I';
35  	public static final char PRIMITIVE_LONG = 'J';
36  	public static final char PRIMITIVE_SHORT = 'S';
37  
38  	private final char primitiveChar;
39  
40  	public PrimitiveTypeSignature(char primitiveChar) {
41  		this.primitiveChar = primitiveChar;
42  	}
43  
44  	/**
45  	 * get the character corresponding to this primitive type
46  	 * 
47  	 * @return
48  	 */
49  	public char getPrimitiveTypeChar() {
50  		return primitiveChar;
51  	}
52  
53  	@Override
54  	public String toString() {
55  		return getSignature();
56  	}
57  
58  	public boolean isPrimitiveType() {
59  		return true;
60  	}
61  
62  	public boolean isBoolean() {
63  		return primitiveChar == PRIMITIVE_BOOLEAN;
64  	}
65  
66  	public boolean isByte() {
67  		return primitiveChar == PRIMITIVE_BYTE;
68  	}
69  
70  	public boolean isChar() {
71  		return primitiveChar == PRIMITIVE_CHAR;
72  	}
73  
74  	public boolean isDouble() {
75  		return primitiveChar == PRIMITIVE_DOUBLE;
76  	}
77  
78  	public boolean isFloat() {
79  		return primitiveChar == PRIMITIVE_FLOAT;
80  	}
81  
82  	public boolean isInt() {
83  		return primitiveChar == PRIMITIVE_INT;
84  	}
85  
86  	public boolean isLong() {
87  		return primitiveChar == PRIMITIVE_LONG;
88  	}
89  
90  	public boolean isShort() {
91  		return primitiveChar == PRIMITIVE_SHORT;
92  	}
93  
94  	public boolean isNumber() {
95  		return primitiveChar == PRIMITIVE_DOUBLE
96  				|| primitiveChar == PRIMITIVE_FLOAT
97  				|| primitiveChar == PRIMITIVE_INT
98  				|| primitiveChar == PRIMITIVE_LONG
99  				|| primitiveChar == PRIMITIVE_SHORT
100 				|| primitiveChar == PRIMITIVE_BYTE;
101 	}
102 
103 	@Override
104 	public FullTypeSignature getTypeErasureSignature() {
105 		return this;
106 	}
107 
108 }