1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  */
18 package org.apache.bcel.generic;
19 
20 import org.apache.bcel.Const;
21 
22 /**
23  * Denotes basic type such as int.
24  *
25  * @version $Id$
26  */
27 public final class BasicType extends Type {
28 
29     /**
30      * Constructor for basic types such as int, long, `void'
31      *
32      * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
33      * @see Const
34      */
BasicType(final byte type)35     BasicType(final byte type) {
36         super(type, Const.getShortTypeName(type));
37         if ((type < Const.T_BOOLEAN) || (type > Const.T_VOID)) {
38             throw new ClassGenException("Invalid type: " + type);
39         }
40     }
41 
42 
43     // @since 6.0 no longer final
getType( final byte type )44     public static BasicType getType( final byte type ) {
45         switch (type) {
46             case Const.T_VOID:
47                 return VOID;
48             case Const.T_BOOLEAN:
49                 return BOOLEAN;
50             case Const.T_BYTE:
51                 return BYTE;
52             case Const.T_SHORT:
53                 return SHORT;
54             case Const.T_CHAR:
55                 return CHAR;
56             case Const.T_INT:
57                 return INT;
58             case Const.T_LONG:
59                 return LONG;
60             case Const.T_DOUBLE:
61                 return DOUBLE;
62             case Const.T_FLOAT:
63                 return FLOAT;
64             default:
65                 throw new ClassGenException("Invalid type: " + type);
66         }
67     }
68 
69 
70     /** @return a hash code value for the object.
71      */
72     @Override
hashCode()73     public int hashCode() {
74         return super.getType();
75     }
76 
77 
78     /** @return true if both type objects refer to the same type
79      */
80     @Override
equals( final Object _type )81     public boolean equals( final Object _type ) {
82         return (_type instanceof BasicType) ? ((BasicType) _type).getType() == this.getType() : false;
83     }
84 }
85