Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2013
 *
 * 52North Initiative for Geospatial Open Source Software GmbH
 * Contact: Andreas Wytzisk
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

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

import java.util.LinkedList;
import java.util.List;

public class Main {
    public static <T> Collection<T> collection() {
        return list();
    }

    public static <T> Collection<T> collection(final T... elements) {
        return list(elements);
    }

    public static <T> List<T> list() {
        return new LinkedList<T>();
    }

    /**
     * @return an <b>UNMODIFIABLE</b> List&lt;T&gt;
     */
    public static <T> List<T> list(final T... elements) {
        return Collections.unmodifiableList(Arrays.asList(elements));
    }

    /**
     * @return an <b>UNMODIFIABLE</b> List&lt;T&gt;
     */
    public static <T> List<T> unmodifiableList(final List<? extends T> l) {
        return (l == null) ? Collections.<T>emptyList() : Collections.unmodifiableList(l);
    }

    public static <T> List<T> asList(final Iterable<? extends T> iterable) {
        return (iterable instanceof Collection) ? new LinkedList<T>((Collection<? extends T>) iterable)
                : new LinkedList<T>() {
                    private static final long serialVersionUID = 3109256773218160485L;
                    {
                        if (iterable != null) {
                            for (final T t : iterable) {
                                add(t);
                            }
                        }
                    }
                };
    }

    public static <T> List<T> asList(final T t, final T... ts) {
        final ArrayList<T> list = new ArrayList<T>(ts.length + 1);
        list.add(t);
        Collections.addAll(list, ts);
        return list;
    }
}