Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import java.util.Vector;

public class Main {
    /**
     * Method getTokenSeparatedStrings.
     * @param vector Vector
     * @param getter String
     * @param tokenizer String
     * @param tokenDelimiter String
     * @return String
     * @throws NoSuchMethodException
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     */
    public static String getTokenSeparatedStrings(Vector vector, String getter, String tokenizer,
            String tokenDelimiter) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        StringBuffer tokenSeparatedStrings = new StringBuffer("");
        String stringValue = null;
        Class[] clsParms = new Class[0];
        Object[] objParms = new Object[0];
        Object property;
        Method getterMethod = null;

        Object vectorElement = null;

        for (int i = 0; i < vector.size(); i++) {
            vectorElement = vector.elementAt(i);
            getterMethod = vectorElement.getClass().getMethod(getter, clsParms);
            property = getterMethod.invoke(vectorElement, objParms);

            if (property != null) {
                stringValue = property.toString();
            } else {
                stringValue = "";
            }

            tokenSeparatedStrings.append(tokenDelimiter + stringValue + tokenDelimiter);

            if (i < vector.size() - 1) {
                tokenSeparatedStrings.append(tokenizer);
            }
        }

        return tokenSeparatedStrings.toString();
    }
}