001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.util;
028:
029: import java.util.Collection;
030:
031: /**
032: * A synchronized version of TimeSpanSet
033: **/
034: public class SynchronizedTimeSpanSet extends TimeSpanSet {
035:
036: // constructors
037: public SynchronizedTimeSpanSet() {
038: super ();
039: }
040:
041: public SynchronizedTimeSpanSet(int i) {
042: super (i);
043: }
044:
045: public SynchronizedTimeSpanSet(Collection c) {
046: super (c);
047: }
048:
049: public SynchronizedTimeSpanSet(TimeSpanSet t) {
050: super (t.size);
051:
052: synchronized (t) {
053: unsafeUpdate(t);
054: }
055: }
056:
057: // Synchronization of ArrayList methods -
058:
059: /**
060: * BOZO - write a comment
061: * Should simply return false
062: */
063: public synchronized boolean add(Object o) {
064: return super .add(o);
065: }
066:
067: /**
068: * BOZO - write a comment
069: * Should simply return false
070: */
071: public synchronized boolean addAll(Collection objects) {
072: synchronized (objects) {
073: return super .addAll(objects);
074: }
075: }
076:
077: public synchronized void clear() {
078: super .clear();
079: }
080:
081: public synchronized boolean contains(Object o) {
082: return super .contains(o);
083: }
084:
085: public synchronized boolean containsAll(Collection c) {
086: synchronized (c) {
087: return super .containsAll(c);
088: }
089: }
090:
091: public synchronized Object get(int index) {
092: return super .get(index);
093: }
094:
095: public synchronized int indexOf(Object elem) {
096: return super .indexOf(elem);
097: }
098:
099: public synchronized int lastIndexOf(Object elem) {
100: return super .lastIndexOf(elem);
101: }
102:
103: /**
104: * BOZO - write a comment
105: * Should simply return false
106: */
107: public synchronized boolean remove(Object o) {
108: return super .remove(o);
109: }
110:
111: public synchronized Object remove(int index) {
112: return super .remove(index);
113: }
114:
115: /**
116: * BOZO - write a comment
117: * Should simply return false
118: */
119: public synchronized boolean removeAll(Collection objects) {
120: synchronized (objects) {
121: return super .removeAll(objects);
122: }
123: }
124:
125: /**
126: * BOZO - write a comment
127: * Should simply return false
128: */
129: public synchronized boolean retainAll(Collection objects) {
130: synchronized (objects) {
131: return super .removeAll(objects);
132: }
133: }
134:
135: public synchronized int size() {
136: return super .size();
137: }
138:
139: public synchronized Object[] toArray() {
140: return super .toArray();
141: }
142:
143: public synchronized Object[] toArray(Object a[]) {
144: return super .toArray(a);
145: }
146:
147: public synchronized String toString() {
148: return super .toString();
149: }
150:
151: public synchronized Object last() {
152: return super .last();
153: }
154:
155: public synchronized Collection filter(UnaryPredicate predicate) {
156: return super .filter(predicate);
157: }
158:
159: /** @return the intersecting Element with the smallest timespan.
160: * The result is undefined if there is a tie for smallest and null
161: * if there are no elements.
162: **/
163: public synchronized Object getMinimalIntersectingElement(
164: final long time) {
165: return super .getMinimalIntersectingElement(time);
166: }
167:
168: public synchronized boolean equals(Object o) {
169: synchronized (o) {
170: return super .equals(o);
171: }
172: }
173:
174: public synchronized int hashCode() {
175: return super .hashCode();
176: }
177:
178: /**
179: * unsafeUpdate - not synchronized. As a protected method it assumes that
180: * caller already has the synch lock.
181: * Should only be used if c has already been validated.
182: * @return boolean - true if any elements added else false.
183: */
184: protected boolean unsafeUpdate(Collection c) {
185: synchronized (c) {
186: return super.unsafeUpdate(c);
187: }
188: }
189:
190: }
|