Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * DataCleaner (community edition)
 * Copyright (C) 2014 Neopost - Customer Information Management
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */

import java.lang.reflect.Array;

public class Main {
    @SuppressWarnings("unchecked")
    public static <E> E[] array(Class<E> elementClass, Object existingArray, E... elements) {
        if (existingArray == null) {
            return elements;
        }
        E[] result;
        if (existingArray.getClass().isArray()) {
            int length = Array.getLength(existingArray);
            result = (E[]) Array.newInstance(elementClass, length + elements.length);
            System.arraycopy(existingArray, 0, result, 0, length);
            System.arraycopy(elements, 0, result, length, elements.length);
        } else {
            result = (E[]) Array.newInstance(elementClass, 1 + elements.length);
            result[0] = (E) existingArray;
            System.arraycopy(elements, 0, result, 1, elements.length);
        }

        return result;
    }
}