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 findFirstMatch(Collection source, Collection candidates) {
        if (!isEmpty(source) && !isEmpty(candidates)) {
            Iterator it = candidates.iterator();

            Object candidate;
            do {
                if (!it.hasNext()) {
                    return null;
                }

                candidate = it.next();
            } while (!source.contains(candidate));

            return candidate;
        } else {
            return null;
        }
    }

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

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