001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/entity/tags/sakai_2-4-1/entity-impl/impl/src/java/org/sakaiproject/entity/impl/ReferenceVectorComponent.java $
003: * $Id: ReferenceVectorComponent.java 7110 2006-03-28 14:04:26Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.entity.impl;
021:
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.Vector;
025:
026: import org.sakaiproject.entity.api.Entity;
027: import org.sakaiproject.entity.api.Reference;
028:
029: /**
030: * <p>
031: * ReferenceVectorComponent implements the ReferenceVector API.
032: * </p>
033: */
034: public class ReferenceVectorComponent extends Vector {
035: /**
036: * Constructor.
037: */
038: public ReferenceVectorComponent(int initialCapacity,
039: int capacityIncrement) {
040: super (initialCapacity, capacityIncrement);
041: }
042:
043: /**
044: * Constructor.
045: */
046: public ReferenceVectorComponent(int initialCapacity) {
047: super (initialCapacity);
048: }
049:
050: /**
051: * Constructor.
052: */
053: public ReferenceVectorComponent(Collection c) {
054: super (c);
055: }
056:
057: /**
058: * Constructor.
059: */
060: public ReferenceVectorComponent() {
061: super ();
062: }
063:
064: /**
065: * Is this resource referred to in any of the references in the vector? Accept any Resource, or a String assumed to be a resource reference.
066: *
067: * @param o
068: * The Resource (or resource reference string) to check for presence in the references in the vector.
069: * @return true if the resource referred to in any of the references in the Vector, false if not.
070: */
071: public boolean contains(Object o) {
072: if ((o instanceof Entity) || (o instanceof String)
073: || (o instanceof Reference)) {
074: String ref = null;
075: if (o instanceof Entity) {
076: ref = ((Entity) o).getReference();
077: } else if (o instanceof String) {
078: ref = (String) o;
079: } else {
080: ref = ((Reference) o).getReference();
081: }
082:
083: Iterator it = iterator();
084: while (it.hasNext()) {
085: Reference de = (Reference) it.next();
086: if (de.getReference().equals(ref))
087: return true;
088: }
089:
090: return false;
091: }
092:
093: else
094: return super .contains(o);
095: }
096:
097: /**
098: * Removes the first occurrence of the specified element in this Vector. If the element is a String, treat it as a resource reference, else it's a Reference object.
099: *
100: * @return true if the element was found, false if not.
101: */
102: public boolean remove(Object o) {
103: // if a string, treat as a resource reference
104: if (o instanceof String) {
105: String ref = (String) o;
106: Iterator it = iterator();
107: while (it.hasNext()) {
108: Reference de = (Reference) it.next();
109: if (de.getReference().equals(ref)) {
110: return super .remove(de);
111: }
112: }
113:
114: return false;
115: }
116:
117: return super.remove(o);
118: }
119: }
|