Java Type Size sizeOf(String typeDescriptor)

Here you can find the source of sizeOf(String typeDescriptor)

Description

Return the size of a type.

License

Apache License

Parameter

Parameter Description
typeDescriptor the descriptor for a single type, may be primitive. For example: I, J, Z, Ljava/lang/String;

Return

the size of the descriptor (number of slots it will consume), either 1 or 2

Declaration

public static int sizeOf(String typeDescriptor) 

Method Source Code

//package com.java2s;
/*//www  . java2  s.co m
 * Copyright 2010-2012 VMware and contributors
 *
 * 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.
 */

public class Main {
    /**
     * Return the size of a type. The size is usually 1 except for double and long which are of size 2. The descriptor
     * passed in is the full descriptor, including any leading 'L' and trailing ';'.
     * 
     * @param typeDescriptor the descriptor for a single type, may be primitive. For example: I, J, Z,
     *            Ljava/lang/String;
     * @return the size of the descriptor (number of slots it will consume), either 1 or 2
     */
    public static int sizeOf(String typeDescriptor) {
        if (typeDescriptor.length() != 1) {
            return 1;
        }
        char ch = typeDescriptor.charAt(0);
        if (ch == 'J' || ch == 'D') {
            return 2;
        } else {
            return 1;
        }
    }
}

Related

  1. sizeOf(int tagNumber, int contentLength)
  2. sizeOf(int value)
  3. sizeOf(int[] arr)
  4. sizeOf(String str)
  5. sizeOf(String type)
  6. sizeOfBinary(int maximumNumber)
  7. sizeOfCompactInt(int i)
  8. sizeOfEnumValue(T enumValue)
  9. sizeOfFloat(float f)