Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of McIDAS-V
 *
 * Copyright 2007-2015
 * Space Science and Engineering Center (SSEC)
 * University of Wisconsin - Madison
 * 1225 W. Dayton Street, Madison, WI 53706, USA
 * http://www.ssec.wisc.edu/mcidas
 * 
 * All Rights Reserved
 * 
 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
 * some McIDAS-V source code is based on IDV and VisAD source code.  
 * 
 * McIDAS-V is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * McIDAS-V 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 Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.List;

public class Main {
    /**
     * Creates a {@link List} from incoming {@literal "varargs"}. Currently 
     * uses {@link ArrayList} as the {@code List} implementation.
     * 
     * <p>Used like so:
     * {@code List<String> listy = list("y", "helo", "thar");}
     * 
     * @param elements Items that will make up the elements of the returned
     * {@code List}.
     * 
     * @return A {@code List} whose elements are each item within {@code elements}.
     */
    public static <E> List<E> list(E... elements) {
        List<E> newList = arrList(elements.length);
        Collections.addAll(newList, elements);
        return newList;
    }

    /**
     * Creates an empty {@link ArrayList} that uses a little cleverness with
     * Java's generics. Useful for eliminating redundant type information and
     * declaring fields as {@code final}.
     * 
     * <p>Used like so:
     * {@code List<String> listy = arrList();}
     *
     * <p>Please consider using {@link #arrList(int)} or
     * {@link #arrList(java.util.Collection)} instead of this method.
     * 
     * @return A new, empty {@code ArrayList}.
     *
     * @see #arrList(int)
     * @see #arrList(java.util.Collection)
     */
    @SuppressWarnings({ "CollectionWithoutInitialCapacity" })
    public static <E> List<E> arrList() {
        return new ArrayList<>();
    }

    /**
     * Creates an empty {@link ArrayList} with a given capacity.
     * 
     * @param capacity The initial size of the returned {@code ArrayList}.
     * 
     * @return A new, empty {@code ArrayList} that has an initial capacity of
     * {@code capacity} elements.
     * 
     * @see ArrayList#ArrayList(int)
     */
    public static <E> List<E> arrList(final int capacity) {
        return new ArrayList<>(capacity);
    }

    /**
     * Copies an existing {@link Collection} into a new {@link ArrayList}.
     * 
     * @param c {@code Collection} whose elements are to be placed into the 
     * returned {@code ArrayList}.
     * 
     * @return An {@code ArrayList} containing the elements of {@code c}.
     * 
     * @see ArrayList#ArrayList(Collection)
     */
    public static <E> List<E> arrList(final Collection<? extends E> c) {
        return new ArrayList<>(c);
    }
}