001: /*
002: * $Header$
003: * $Revision: 125 $
004: * $Date: 2005-07-01 07:48:18 -0700 $
005: *
006: * ====================================================================
007: *
008: * Copyright 1999 The Apache Software Foundation
009: *
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: *
022: */
023: package org.apache.slide.search.basic;
024:
025: // import list
026: import java.util.AbstractSet;
027: import java.util.Collection;
028: import java.util.Vector;
029: import java.util.Iterator;
030:
031: /**
032: * An implementation of the {@link org.apache.slide.search.basic.IBasicResultSet
033: * IBasicResultSet} interface which keeps the order of added resources.
034: *
035: * @version $Revision: 125 $
036: *
037: **/
038: public class LuceneBasicResultSetImpl extends AbstractSet implements
039: IBasicResultSet {
040:
041: /**
042: * Indicated if the result set is truncated for any reason.
043: */
044: protected boolean partial = false;
045:
046: /**
047: * container of results
048: *
049: */
050: protected Vector container = new Vector();
051:
052: /**
053: * Creates an empty BasicResultSetImpl.
054: */
055: public LuceneBasicResultSetImpl() {
056: this (false);
057: }
058:
059: /**
060: * Creates an empty BasicResultSetImpl and sets the value
061: * returned by {@link #isPartialResultSet isPartialResultSet()}.
062: *
063: * @param isPartialResult the value to be returned by
064: * {@link #isPartialResultSet isPartialResultSet()}.
065: */
066: public LuceneBasicResultSetImpl(boolean isPartialResult) {
067: setPartialResultSet(isPartialResult);
068: }
069:
070: /**
071: * Creates a BasicResultSetImpl containing the elements of the given
072: * <code>collection</code>
073: *
074: * @param collection the Collection whose elements to add.
075: */
076: public LuceneBasicResultSetImpl(Collection collection) {
077: this (collection, false);
078: }
079:
080: /**
081: * Creates a BasicResultSetImpl containing the elements of the given
082: * <code>collection</code>
083: *
084: * @param collection the Collection whose elements to add.
085: * @param isPartialResult the value to be returned by
086: * {@link #isPartialResultSet isPartialResultSet()}.
087: */
088: public LuceneBasicResultSetImpl(Collection collection,
089: boolean isPartialResult) {
090: container.addAll(collection);
091: setPartialResultSet(isPartialResult);
092: }
093:
094: /**
095: * Returns <code>true</code> if the result set is truncated for any reason.
096: *
097: * @return <code>true</code> if the result set is truncated for any reason.
098: */
099: public boolean isPartialResultSet() {
100: return partial;
101: }
102:
103: /**
104: * Sets the value returned by {@link #isPartialResultSet isPartialResultSet()}.
105: *
106: * @param partial the new value to be returned by
107: * {@link #isPartialResultSet isPartialResultSet()}.
108: */
109: public void setPartialResultSet(boolean partial) {
110: this .partial = partial;
111: }
112:
113: // ------------------------------------------------------------------ Set methods
114:
115: public boolean add(Object o) {
116: return container.add(o);
117: }
118:
119: public boolean addAll(Collection c) {
120: return container.addAll(c);
121: }
122:
123: public boolean remove(Object o) {
124: return container.remove(o);
125: }
126:
127: public boolean removeAll(Collection c) {
128: return container.removeAll(c);
129: }
130:
131: public boolean retainAll(Collection c) {
132: return container.retainAll(c);
133: }
134:
135: public boolean contains(Object o) {
136: return container.contains(o);
137: }
138:
139: public boolean containsAll(Collection c) {
140: return container.containsAll(c);
141: }
142:
143: public boolean isEmpty() {
144: return container.size() == 0;
145: }
146:
147: public boolean equals(Object o) {
148: return container.equals(o);
149: }
150:
151: public void clear() {
152: container.clear();
153: }
154:
155: public int size() {
156: return container.size();
157: }
158:
159: public Iterator iterator() {
160: return container.iterator();
161: }
162:
163: public Object[] toArray() {
164: return container.toArray();
165: }
166:
167: public Object[] toArray(Object[] a) {
168: return container.toArray(a);
169: }
170:
171: }
|