001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.collections.iterators;
018
019 import org.apache.commons.collections.OrderedMapIterator;
020 import org.apache.commons.collections.Unmodifiable;
021
022 /**
023 * Decorates an ordered map iterator such that it cannot be modified.
024 *
025 * @since Commons Collections 3.0
026 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
027 *
028 * @author Stephen Colebourne
029 */
030 public final class UnmodifiableOrderedMapIterator implements 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(OrderedMapIterator iterator) {
043 if (iterator == null) {
044 throw new IllegalArgumentException("OrderedMapIterator must not be null");
045 }
046 if (iterator instanceof Unmodifiable) {
047 return iterator;
048 }
049 return new UnmodifiableOrderedMapIterator(iterator);
050 }
051
052 //-----------------------------------------------------------------------
053 /**
054 * Constructor.
055 *
056 * @param iterator the iterator to decorate
057 */
058 private UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) {
059 super();
060 this.iterator = iterator;
061 }
062
063 //-----------------------------------------------------------------------
064 public boolean hasNext() {
065 return iterator.hasNext();
066 }
067
068 public Object next() {
069 return iterator.next();
070 }
071
072 public boolean hasPrevious() {
073 return iterator.hasPrevious();
074 }
075
076 public Object previous() {
077 return iterator.previous();
078 }
079
080 public Object getKey() {
081 return iterator.getKey();
082 }
083
084 public Object getValue() {
085 return iterator.getValue();
086 }
087
088 public Object setValue(Object value) {
089 throw new UnsupportedOperationException("setValue() is not supported");
090 }
091
092 public void remove() {
093 throw new UnsupportedOperationException("remove() is not supported");
094 }
095
096 }