001: /*
002: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.mandarax.rdf;
020:
021: import java.util.*;
022: import com.hp.hpl.jena.rdf.model.RDFList;
023: import com.hp.hpl.jena.rdf.model.RDFNode;
024: import org.mandarax.kernel.ClauseSetException;
025:
026: /**
027: * RDFCollection is a wrapper for RDF Collections (RDF Linked List).
028: * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
029: * @version 1.1 <01 August 2004>
030: * @since 1.1
031: */
032: public class RDFCollection implements Collection, RDFLogger {
033:
034: private RDFList delegate = null;
035:
036: /**
037: * Default constructor.
038: * @param c the wrapped jena collection (RDFList)
039: */
040: public RDFCollection(RDFList c) throws ClauseSetException {
041: super ();
042: delegate = c;
043: }
044:
045: /**
046: * Returns an iterator over the elements in the internal collection.
047: * @return an Iterator over the elements in the internal collection.
048: */
049: public Iterator iterator() {
050: return delegate.iterator();
051: }
052:
053: /**
054: * Returns the number of elements in the internal collection.
055: * @return the number of elements in the internal collection.
056: */
057: public int size() {
058: return delegate.size();
059: }
060:
061: /**
062: * Adds the specified element to the collection.
063: * Not supported, this is a "read only" view on a container.
064: * @param o the element to be added to the collection.
065: * @return true if the collection changed as a result of the call.
066: */
067: public boolean add(Object o) {
068: throw new UnsupportedOperationException(
069: "This is an unmodifiable collection");
070: }
071:
072: /**
073: * Adds all of the elements in the specified collection to this collection.
074: * @param col the elements to be inserted into the collection.
075: * @return true if the collection changed as a result of the call.
076: */
077: public boolean addAll(Collection col) {
078: throw new UnsupportedOperationException(
079: "This is an unmodifiable collection");
080: }
081:
082: /**
083: * Retains only the elements in the collection that are contained in the specified collection.
084: * @param col the elements to be retained in the collection.
085: * @return true if the collection changed as a result of the call.
086: */
087: public boolean retainAll(Collection col) {
088: throw new UnsupportedOperationException(
089: "This is an unmodifiable collection");
090: }
091:
092: /**
093: * Removes all the collection's elements that are also contained in the specified collection.
094: * @param col the elements to be removed from this collection.
095: * @return true if the collection changed as a result of the call.
096: */
097: public boolean removeAll(Collection col) {
098: throw new UnsupportedOperationException(
099: "This is an unmodifiable collection");
100: }
101:
102: /**
103: * Returns true if this collection contains all of the elements in the specified collection.
104: * Not yet supported (but could be done), would enforce initializing the entire collections.
105: * @param col the collection to be checked for containment in the internal collection.
106: * @return true if this collection contains all of the elements in the specified collection.
107: */
108: public boolean containsAll(Collection col) {
109: throw new UnsupportedOperationException(
110: "This operation is not supported");
111: }
112:
113: /**
114: * Returns true if this collection contains the specified element.
115: * @param o the element whose presence in this collection is to be tested.
116: * @return true if this collection contains the specified element.
117: */
118: public boolean contains(Object o) {
119: return delegate.contains((RDFNode) o);
120: }
121:
122: /**
123: * Removes all of the elements from the internal collection.
124: * This collection will be empty after this method returns unless it throws an exception.
125: */
126: public void clear() {
127: throw new UnsupportedOperationException(
128: "This is an unmodifiable collection");
129: }
130:
131: /**
132: * Overwrite the equals method of the Collection Interface.
133: * @param o is the object the new method is invoked from.
134: * @return the result of dispatching the new method represented by RDFContainer's method field on object o with parameters equal_value.
135: * @throws Exception if the new method can not be invoked correctly.
136: */
137: public boolean equals(Object o) {
138:
139: if (!super .equals(o)) {
140:
141: if (o instanceof RDFCollection) {
142: return ((RDFCollection) o).sameListAs(delegate);
143: } else
144: return false;
145: } else
146: return true;
147: }
148:
149: /**
150: * Get the hash code for an object.
151: * @return the hash code
152: */
153: public int hashCode() {
154: return delegate == null ? 0 : delegate.hashCode();
155: }
156:
157: /**
158: * Returns an array containing all of the elements in the collection.
159: * Not yet supported, would enforge reading the entire collection.
160: * @return an array containing all of the elements in this collection.
161: */
162: public Object[] toArray() {
163: throw new UnsupportedOperationException(
164: "This operation is not supported");
165: }
166:
167: /**
168: * Returns true if this collection contains no elements.
169: * @return true if this collection contains no elements.
170: */
171: public boolean isEmpty() {
172: return delegate.size() == 0;
173: }
174:
175: /**
176: * Removes a single instance of the specified element from the collection.
177: * @param o the element to be removed from this collection, if present.
178: * @return true if this collection changed as a result of the call.
179: */
180: public boolean remove(Object o) {
181: throw new UnsupportedOperationException(
182: "This is an unmodifiable collection");
183: }
184:
185: /**
186: * Returns an array containing all of the elements in this collection;
187: * the runtime type of the returned array is that of the specified array.
188: * @param a the array into which the elements of this collection are to be stored, if it is big enough;
189: * otherwise, a new array of the same runtime type is allocated for this purpose.
190: * @return an array containing the elements of this collection.
191: */
192: public Object[] toArray(Object[] a) {
193: throw new UnsupportedOperationException(
194: "This operation is not supported");
195: }
196:
197: /**
198: * Answer true if this list has the same elements in the same order as the given list.
199: * Note that the standard equals test just tests for equality of two given list cells.
200: * While such a test is sufficient for many purposes, this test provides a broader equality definition,
201: * but is correspondingly more expensive to test.
202: * @param list a RDFList
203: * @return true
204: */
205: public boolean sameListAs(RDFList list) {
206: return this.delegate.sameListAs(list);
207: }
208:
209: }
|