Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    public static Object oneOrMany(final Collection<?> collection) {
        switch (size(collection)) {
        case 0:
            return null;
        case 1:
            return collection.iterator().next();
        default:
            return collection;
        }
    }

    public static int size(final Collection<?> collection) {
        return collection == null ? 0 : collection.size();
    }

    public static <T> int size(final T[] array) {
        return array == null ? 0 : array.length;
    }
}