summaryrefslogtreecommitdiff
path: root/hit/src/com/android/hit/Types.java
blob: 62228cea69f4e80625a4e4a214ed9d7f002ce0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.hit;

public class Types {
    private static int mIdSize = 4;

    public static final int OBJECT     =   2;
    public static final int BOOLEAN    =   4;
    public static final int CHAR       =   5;
    public static final int FLOAT      =   6;
    public static final int DOUBLE     =   7;
    public static final int BYTE       =   8;
    public static final int SHORT      =   9;
    public static final int INT        =   10;
    public static final int LONG       =   11;

    public static final void setIdSize(int size) {
        mIdSize = size;
    }

    public static final int getTypeSize(int type) {
        switch (type) {
            case '[':      return mIdSize; //  array object
            case 'L':      return mIdSize; //  object
            case 'Z':      return 1;       //  boolean
            case 'C':      return 2;       //  char
            case 'F':      return 4;       //  float
            case 'D':      return 8;       //  double
            case 'B':      return 1;       //  byte
            case 'S':      return 2;       //  short
            case 'I':      return 4;       //  int
            case 'J':      return 8;       //  long

            case OBJECT:   return mIdSize;
            case BOOLEAN:  return 1;
            case CHAR:     return 2;
            case FLOAT:    return 4;
            case DOUBLE:   return 8;
            case BYTE:     return 1;
            case SHORT:    return 2;
            case INT:      return 4;
            case LONG:     return 8;
        }

        throw new IllegalArgumentException("Illegal type signature: " + type);
    }

    public static final String getTypeName(int type) {
        switch (type) {
            case '[':      return "array";
            case 'L':      return "object";
            case 'Z':      return "boolean";
            case 'C':      return "char";
            case 'F':      return "float";
            case 'D':      return "double";
            case 'B':      return "byte";
            case 'S':      return "short";
            case 'I':      return "int";
            case 'J':      return "long";

            case OBJECT:   return "object";
            case BOOLEAN:  return "boolean";
            case CHAR:     return "char";
            case FLOAT:    return "float";
            case DOUBLE:   return "double";
            case BYTE:     return "byte";
            case SHORT:    return "short";
            case INT:      return "int";
            case LONG:     return "long";
        }

        throw new IllegalArgumentException("Illegal type signature: " + type);
    }
}