Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.*;

public class Main {
    public static <K extends Object, T extends Object> T getFirst(Map<K, T> map, K... keys) {
        if (map == null)
            return null;
        for (K key : keys) {
            if (map.containsKey(key))
                return map.get(key);
        }
        return null;
    }

    public static <T extends Object> T getFirst(Collection<T> items, T otherwise) {
        if (items == null || items.size() == 0)
            return otherwise;
        return items.iterator().next();
    }

    public static <T extends Object> T getFirst(T... items) {
        for (T item : items) {
            if (item != null)
                return item;
        }
        return null;
    }

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