Java Array Convert to convertArrayTypeName(final String typeName)

Here you can find the source of convertArrayTypeName(final String typeName)

Description

Converts an internal Java array type name ([Lblabla) to the a the format used by the expression matcher (blabla[])

License

Open Source License

Parameter

Parameter Description
typeName is type name

Declaration

public static String convertArrayTypeName(final String typeName) 

Method Source Code

//package com.java2s;
/**************************************************************************************
 * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
 * http://aspectwerkz.codehaus.org                                                    *
 * ---------------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the LGPL license      *
 * a copy of which has been included with this distribution in the license.txt file.  *
 **************************************************************************************/

public class Main {
    /**/*from   w ww  .j a  va  2s . com*/
     * Converts an internal Java array type name ([Lblabla) to the a the format used by the expression matcher
     * (blabla[])
     *
     * @param typeName is type name
     * @return
     */
    public static String convertArrayTypeName(final String typeName) {
        int index = typeName.lastIndexOf('[');
        if (index != -1) {
            StringBuffer arrayType = new StringBuffer();
            if (typeName.endsWith("I")) {
                arrayType.append("int");
            } else if (typeName.endsWith("J")) {
                arrayType.append("long");
            } else if (typeName.endsWith("S")) {
                arrayType.append("short");
            } else if (typeName.endsWith("F")) {
                arrayType.append("float");
            } else if (typeName.endsWith("D")) {
                arrayType.append("double");
            } else if (typeName.endsWith("Z")) {
                arrayType.append("boolean");
            } else if (typeName.endsWith("C")) {
                arrayType.append("char");
            } else if (typeName.endsWith("B")) {
                arrayType.append("byte");
            } else {
                arrayType.append(typeName.substring(index + 2, typeName.length() - 1));
            }
            for (int i = 0; i < (index + 1); i++) {
                arrayType.append("[]");
            }
            return arrayType.toString();
        } else {
            return typeName;
        }
    }
}

Related

  1. convertArrayIndexToShipLetter(int i)
  2. convertArrayToCSVString(String[] s)
  3. convertArrayToInteger(String[] input)
  4. convertArrayToLine(String[] cols)
  5. convertArrayType(String type)
  6. convertArrayValue(Object value, Class type)
  7. toDoubleArray(byte[] data)
  8. toDoubleArray(Double[] list)
  9. toDoubleArray(final int[] intArray)