1 /*
2  * Copyright (C) 2008 Google Inc.
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 
17 package com.android.hit;
18 
19 public class Types {
20     private static int mIdSize = 4;
21 
22     public static final int OBJECT     =   2;
23     public static final int BOOLEAN    =   4;
24     public static final int CHAR       =   5;
25     public static final int FLOAT      =   6;
26     public static final int DOUBLE     =   7;
27     public static final int BYTE       =   8;
28     public static final int SHORT      =   9;
29     public static final int INT        =   10;
30     public static final int LONG       =   11;
31 
setIdSize(int size)32     public static final void setIdSize(int size) {
33         mIdSize = size;
34     }
35 
getTypeSize(int type)36     public static final int getTypeSize(int type) {
37         switch (type) {
38             case '[':      return mIdSize; //  array object
39             case 'L':      return mIdSize; //  object
40             case 'Z':      return 1;       //  boolean
41             case 'C':      return 2;       //  char
42             case 'F':      return 4;       //  float
43             case 'D':      return 8;       //  double
44             case 'B':      return 1;       //  byte
45             case 'S':      return 2;       //  short
46             case 'I':      return 4;       //  int
47             case 'J':      return 8;       //  long
48 
49             case OBJECT:   return mIdSize;
50             case BOOLEAN:  return 1;
51             case CHAR:     return 2;
52             case FLOAT:    return 4;
53             case DOUBLE:   return 8;
54             case BYTE:     return 1;
55             case SHORT:    return 2;
56             case INT:      return 4;
57             case LONG:     return 8;
58         }
59 
60         throw new IllegalArgumentException("Illegal type signature: " + type);
61     }
62 
getTypeName(int type)63     public static final String getTypeName(int type) {
64         switch (type) {
65             case '[':      return "array";
66             case 'L':      return "object";
67             case 'Z':      return "boolean";
68             case 'C':      return "char";
69             case 'F':      return "float";
70             case 'D':      return "double";
71             case 'B':      return "byte";
72             case 'S':      return "short";
73             case 'I':      return "int";
74             case 'J':      return "long";
75 
76             case OBJECT:   return "object";
77             case BOOLEAN:  return "boolean";
78             case CHAR:     return "char";
79             case FLOAT:    return "float";
80             case DOUBLE:   return "double";
81             case BYTE:     return "byte";
82             case SHORT:    return "short";
83             case INT:      return "int";
84             case LONG:     return "long";
85         }
86 
87         throw new IllegalArgumentException("Illegal type signature: " + type);
88     }
89 }
90