Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Collection;

import java.util.Iterator;
import java.util.Map;

public class Main {
    /**
     * Determine whether the given collection only contains a
     * single unique object.
     * @param coll the collection to check
     * @return <code>true</code> if the collection contains a
     * single reference or multiple references to the same
     * instance, <code>false</code> else
     */
    public static boolean hasUniqueObject(Collection<?> coll) {
        if (coll.isEmpty()) {
            return false;
        }
        Object candidate = null;
        for (Iterator<?> it = coll.iterator(); it.hasNext();) {
            Object elem = it.next();
            if (candidate == null) {
                candidate = elem;
            } else if (candidate != elem) {
                return false;
            }
        }
        return true;
    }

    /**
     * Return <code>true</code> if the supplied <code>Collection</code> is null or empty.
     * Otherwise, return <code>false</code>.
     * @param collection the <code>Collection</code> to check
     */
    public static boolean isEmpty(Collection<?> collection) {
        return (collection == null || collection.isEmpty());
    }

    /**
     * Return <code>true</code> if the supplied <code>Map</code> is null or empty.
     * Otherwise, return <code>false</code>.
     * @param map the <code>Map</code> to check
     */
    public static boolean isEmpty(Map<?, ?> map) {
        return (map == null || map.isEmpty());
    }
}