Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Manchester Centre for Integrative Systems Biology
 * University of Manchester
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2007 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * 
     * @param collections
     * @return Collection
     */
    public static Collection<?> getIntersection(
            final Collection<? extends Collection<? extends Object>> collections) {
        final List<Collection<?>> collectionsList = new ArrayList<Collection<?>>(collections);
        final Collection<Object> intersection = new HashSet<>();

        if (collectionsList.size() != 0) {
            intersection.addAll(collectionsList.get(0));
        }

        for (int i = 1; i < collections.size() && intersection.size() > 0; i++) {
            intersection.retainAll(new HashSet<>(collectionsList.get(i)));
        }

        return intersection;
    }
}