Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * TMQL4J - Javabased TMQL Engine
 * 
 * Copyright: Copyright 2010 Topic Maps Lab, University of Leipzig. http://www.topicmapslab.de/    
 * License:   Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * @author Sven Krosse
 * @email krosse@informatik.uni-leipzig.de
 *
 */

import java.util.Collection;

public class Main {
    /**
     * Method checks if the given collections contain the same content. Please
     * note that the method only check if each item of one collection is
     * contained at least one times in the other collection. Method does not
     * check if the number of containments of each element are equal. For
     * example this means that { A , B , B } and { A , A , B } are contained
     * equal content.
     * 
     * @param collectionA
     *            the first collection
     * @param collectionB
     *            the other collection
     * @return <code>true</code> if the content are equal, <code>false</code>
     *         otherwise.
     */
    public static boolean isContentEqual(final Collection<?> collectionA, final Collection<?> collectionB) {
        /*
         * check if at least one parameter are null
         */
        if (collectionA == null || collectionB == null) {
            throw new IllegalArgumentException("parameters can not be null.");
        }

        /*
         * check if both collection have the same size
         */
        if (collectionA.size() != collectionB.size()) {
            return false;
        }

        /*
         * check if each item of collection A contained in collection B
         */
        for (Object obj : collectionA) {
            if (!collectionB.contains(obj)) {
                return false;
            }
        }

        /*
         * check if each item of collection B contained in collection A
         */
        for (Object obj : collectionB) {
            if (!collectionA.contains(obj)) {
                return false;
            }
        }

        return true;
    }
}