001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.metadata.value;
020:
021: import java.util.*;
022:
023: import org.openharmonise.vfs.metadata.*;
024:
025: /**
026: * This is the value for compund type properties.
027: *
028: * @author Matthew Large
029: * @version $Revision: 1.1 $
030: *
031: */
032: public class PropertyValue implements ValueInstance {
033:
034: /**
035: * List of {@link PropertyInstance} objects that are part of this value.
036: */
037: ArrayList m_aPropertyInstances = new ArrayList();
038:
039: public PropertyValue() {
040: super ();
041: }
042:
043: /**
044: * Construcs a new compound value.
045: *
046: * @param aPropertyInstances List of {@link PropertyInstance} objects
047: */
048: public PropertyValue(ArrayList aPropertyInstances) {
049: super ();
050: this .m_aPropertyInstances = aPropertyInstances;
051: }
052:
053: /**
054: * Sets the property instances that are part of this value.
055: *
056: * @param aPropertyInstances List of {@link PropertyInstance} objects
057: */
058: public void setValue(ArrayList aPropertyInstances) {
059: this .m_aPropertyInstances = aPropertyInstances;
060: }
061:
062: /**
063: * Returns a list of {@link PropertyInstance} objects that are part of
064: * this value.
065: *
066: * @return List of {@link PropertyInstance} objects
067: */
068: public ArrayList getValue() {
069: return this .m_aPropertyInstances;
070: }
071:
072: /* (non-Javadoc)
073: * @see java.lang.Object#equals(java.lang.Object)
074: */
075: public boolean equals(Object arg0) {
076: if (super .equals(arg0)) {
077: return true;
078: } else if (arg0 instanceof PropertyValue) {
079: if (this
080: .compareAllValues(((PropertyValue) arg0).getValue())) {
081: return true;
082: } else {
083: return false;
084: }
085: } else {
086: return false;
087: }
088: }
089:
090: /**
091: * Compares a given list of {@link PropertyInstance} objects against
092: * the list that is part of this value.
093: *
094: * @param aPropertyInstances List of {@link PropertyInstance} objects
095: * @return true if there is a complete match
096: */
097: private boolean compareAllValues(ArrayList aPropertyInstances) {
098: boolean bSame = true;
099:
100: Iterator itor = aPropertyInstances.iterator();
101: while (itor.hasNext()) {
102: boolean bFound = false;
103: PropertyInstance propInst = (PropertyInstance) itor.next();
104: Iterator itor2 = this .m_aPropertyInstances.iterator();
105: while (itor2.hasNext()) {
106: PropertyInstance myPropInst = (PropertyInstance) itor2
107: .next();
108: if (myPropInst.equals(propInst)) {
109: bFound = true;
110: break;
111: }
112: }
113: if (!bFound) {
114: bSame = false;
115: break;
116: }
117: }
118:
119: return bSame;
120: }
121:
122: }
|