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.*;

public class Main {
    public static Object findValueOfType(Collection collection, Class type) {
        if (isEmpty(collection)) {
            return null;
        } else {
            Object value = null;
            Iterator it = collection.iterator();

            while (true) {
                Object obj;
                do {
                    if (!it.hasNext()) {
                        return value;
                    }

                    obj = it.next();
                } while (type != null && !type.isInstance(obj));

                if (value != null) {
                    return null;
                }

                value = obj;
            }
        }
    }

    public static boolean isEmpty(Collection collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }
}