001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.iterators;
017:
018: import org.apache.commons.collections.OrderedMapIterator;
019: import org.apache.commons.collections.Unmodifiable;
020:
021: /**
022: * Decorates an ordered map iterator such that it cannot be modified.
023: *
024: * @since Commons Collections 3.0
025: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
026: *
027: * @author Stephen Colebourne
028: */
029: public final class UnmodifiableOrderedMapIterator implements
030: OrderedMapIterator, Unmodifiable {
031:
032: /** The iterator being decorated */
033: private OrderedMapIterator iterator;
034:
035: //-----------------------------------------------------------------------
036: /**
037: * Decorates the specified iterator such that it cannot be modified.
038: *
039: * @param iterator the iterator to decorate
040: * @throws IllegalArgumentException if the iterator is null
041: */
042: public static OrderedMapIterator decorate(
043: OrderedMapIterator iterator) {
044: if (iterator == null) {
045: throw new IllegalArgumentException(
046: "OrderedMapIterator must not be null");
047: }
048: if (iterator instanceof Unmodifiable) {
049: return iterator;
050: }
051: return new UnmodifiableOrderedMapIterator(iterator);
052: }
053:
054: //-----------------------------------------------------------------------
055: /**
056: * Constructor.
057: *
058: * @param iterator the iterator to decorate
059: */
060: private UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) {
061: super ();
062: this .iterator = iterator;
063: }
064:
065: //-----------------------------------------------------------------------
066: public boolean hasNext() {
067: return iterator.hasNext();
068: }
069:
070: public Object next() {
071: return iterator.next();
072: }
073:
074: public boolean hasPrevious() {
075: return iterator.hasPrevious();
076: }
077:
078: public Object previous() {
079: return iterator.previous();
080: }
081:
082: public Object getKey() {
083: return iterator.getKey();
084: }
085:
086: public Object getValue() {
087: return iterator.getValue();
088: }
089:
090: public Object setValue(Object value) {
091: throw new UnsupportedOperationException(
092: "setValue() is not supported");
093: }
094:
095: public void remove() {
096: throw new UnsupportedOperationException(
097: "remove() is not supported");
098: }
099:
100: }
|