Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

public class Main {
    /**
     * @param at
     * @return a List containing the elements of the given array.
     * @precondition at != null
     * @postcondition result != null
     * @postcondition result.size() == at.length
     */
    public static <T> List<T> asListFromObjectArray(Object[] at) {
        final List<T> result = new ArrayList<T>(at.length);
        for (Object t : at) {
            result.add((T) t);
        }
        assert result.size() == at.length;
        return result;
    }

    /**
     * @param coll
     * @postcondition (coll == null) --> (result == 0)
     * @postcondition (coll != null) --> (result == coll.size())
     */
    public static int size(Collection<?> coll) {
        return (coll == null) ? 0 : coll.size();
    }
}