Java Vector Compare isIdentical(Object[] array, Vector vector)

Here you can find the source of isIdentical(Object[] array, Vector vector)

Description

is Identical

License

Open Source License

Parameter

Parameter Description
array an Object[]
vector a Vector

Return

true if the two arguments have the same elements (don't need to be in same order)

Declaration

public static boolean isIdentical(Object[] array, Vector vector) 

Method Source Code

//package com.java2s;
import java.util.*;

public class Main {
    /**/* www . j  a v a  2s .co  m*/
     * @return true if the 2 List have the same Objects in same order
     * @param l1 the first List
     * @param 12 the second List
     */
    public static boolean isIdentical(List l1, List l2) {
        return isIdentical(new Vector(l1).elements(),
                new Vector(l2).elements());
    }

    /**
     * @return true if the 2 Iterator have the same Objects in same order
     * @param i1 the first Iterator
     * @param i2 the second Iterator
     */
    public static boolean isIdentical(Iterator i1, Iterator i2) {
        return isIdentical(createVector(i1).elements(), createVector(i2)
                .elements());
    }

    /**
     * @return true if the 2 Enumeration have the same Objects in same order
     * @param v1 the first Vector
     * @param v2 the second Vector
     */
    public static boolean isIdentical(Vector v1, Vector v2) {
        return isIdentical(v1.elements(), v2.elements());
    }

    /**
     * @return true if the 2 Enumeration have the same Objects in same order 
     * @param enum1 the first Enumeration
     * @param enum2 the second Enumeration
     */
    public static boolean isIdentical(Enumeration enum1, Enumeration enum2) {
        if (enum1 == null || enum2 == null)
            return false;

        if (enum1.hasMoreElements() && (enum2.hasMoreElements() == false))
            return false;

        if (enum2.hasMoreElements() && (enum1.hasMoreElements() == false))
            return false;

        while (enum1.hasMoreElements()) {
            Object enum1Obj = enum1.nextElement();

            if (enum2.hasMoreElements() == false)
                return false;

            Object enum2Obj = enum2.nextElement();

            if (!enum1Obj.equals(enum2Obj))
                return false;
        }

        if (enum2.hasMoreElements())
            return false;

        return true;
    }

    /**
     * @return true if the two arguments have the same elements (don't need to be in same order)
     * @param array an Object[]
     * @param vector a Vector 
     */
    public static boolean isIdentical(Object[] array, Vector vector) {
        return isIdentical(createVector(array), vector);
    }

    /**
     * @return true if the two arguments have the same elements (don't need to be in same order)
     * @param array an Object[]
     * @param e an Enumeration of Objects 
     */
    public static boolean isIdentical(Object[] array, Enumeration e) {
        return isIdentical(createVector(array).elements(), e);
    }

    /**
     * @return a Vector with contents of the Iterator
     * @param iterator the Iterator object
     */
    public static Vector createVector(Iterator iterator) {
        Vector v = new Vector();

        while (iterator.hasNext())
            v.addElement(iterator.next());

        return v;
    }

    /**
     * @return a Vector with contents of the List
     * @param iterator the Iterator object
     */
    public static Vector createVector(List list) {
        return createVector(list.iterator());
    }

    /**
     * @return a Vector with contents of the Enumeration 
     * @param e the Enumeration object
     */
    public static Vector createVector(Enumeration e) {
        Vector v = new Vector();

        while (e.hasMoreElements())
            v.addElement(e.nextElement());

        return v;
    }

    /**
     * @return a Vector with contents of the Object[] 
     * @param array an Object[]
     */
    public static Vector createVector(Object[] array) {
        Vector v = new Vector();

        for (int i = 0; i < array.length; ++i)
            v.addElement(array[i]);

        return v;
    }
}

Related

  1. equals(Vector vFirst_, Vector vSecond_)
  2. equalVectors(Vector aV1, Vector aV2)
  3. isEquals(Object[] array, Vector vector)