Java Array to String toString(Class[] modelPath)

Here you can find the source of toString(Class[] modelPath)

Description

Converts a model path to a string representation.

License

Apache License

Parameter

Parameter Description
modelPath the subject model path

Return

model path string

Declaration

public static String toString(Class<?>[] modelPath) 

Method Source Code


//package com.java2s;
/*/*from   w  w w.  j av  a2  s.  c  o m*/
 * File created on Mar 12, 2016
 *
 * Copyright (c) 2016 Carl Harris, Jr
 * and others as noted
 *
 * 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.
 */

import java.util.Arrays;
import java.util.List;

public class Main {
    /**
     * Converts a model path to a string representation.
     * @param modelPath the subject model path
     * @return model path string
     */
    public static String toString(Class<?>[] modelPath) {
        return toString(Arrays.asList(modelPath));
    }

    /**
     * Converts a model path to a string representation.
     * @param modelPath the subject model path
     * @return model path string
     */
    public static String toString(List<Class<?>> modelPath) {
        if (modelPath.size() == 1) {
            return modelPath.get(0).getSimpleName();
        }

        final StringBuilder sb = new StringBuilder();
        int i = 0;
        sb.append("[");
        for (Class<?> modelClass : modelPath) {
            sb.append(modelClass.getSimpleName());
            if (++i < modelPath.size()) {
                sb.append(", ");
            }
        }
        sb.append("]");
        return sb.toString();
    }
}

Related

  1. toDelimitedString(Object[] array, String delimiter)
  2. toDelimitedString(Object[] array, String delimiter)
  3. toPrettyString(String[] array)
  4. toString(byte[] array)
  5. toString(Class aClass, Object[] objects)
  6. toString(final byte[] buffer, final int offset, final int length)
  7. toString(final Object[] array)
  8. toString(int X[][])
  9. toString(int[] a, int maxValues)