Here you can find the source of vectorSubset(Vector aV1, Vector aV2)
Vector
is a subset of another Vector
.
Parameter | Description |
---|---|
aV1 | Subset <code>Vector</code> to compare against <code>aV2</code> |
aV2 | Superset <code>Vector</code> to compare against <code>aV1</code> |
true
if aV1
is a subset of aV2
; false
otherwise.
public static boolean vectorSubset(Vector aV1, Vector aV2)
//package com.java2s; /*********************************************************** Copyright (C) 2004 VeriSign, Inc.//from w w w . ja v a 2 s.c o m This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://www.verisign.com/nds/naming/namestore/techdocs.html ***********************************************************/ import java.util.*; public class Main { /** * Determines if one <code>Vector</code> is a subset of another * <code>Vector</code>. If every element in <code>aV1</code> is in * <code>aV2</code> return <code>true</code>; otherwise return * <code>false</code>. * * @param aV1 * Subset <code>Vector</code> to compare against <code>aV2</code> * @param aV2 * Superset <code>Vector</code> to compare against * <code>aV1</code> * @return <code>true</code> if <code>aV1</code> is a subset of * <code>aV2</code>; <code>false</code> otherwise. */ public static boolean vectorSubset(Vector aV1, Vector aV2) { Enumeration v1Enum = aV1.elements(); while (v1Enum.hasMoreElements()) { if (!aV2.contains(v1Enum.nextElement())) { return false; } } return true; } }