1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 package com.google.protobuf;
33 import java.util.AbstractList;
34 import java.util.RandomAccess;
35 import java.util.List;
36 import java.util.ListIterator;
37 import java.util.Iterator;
40 * An implementation of {@link LazyStringList} that wraps another
41 * {@link LazyStringList} such that it cannot be modified via the wrapper.
43 * @author jonp@google.com (Jon Perlow)
45 public class UnmodifiableLazyStringList extends AbstractList<String>
46 implements LazyStringList, RandomAccess {
48 private final LazyStringList list;
50 public UnmodifiableLazyStringList(LazyStringList list) {
55 public String get(int index) {
56 return list.get(index);
64 //@Override (Java 1.6 override semantics, but we must support 1.5)
65 public ByteString getByteString(int index) {
66 return list.getByteString(index);
69 //@Override (Java 1.6 override semantics, but we must support 1.5)
70 public void add(ByteString element) {
71 throw new UnsupportedOperationException();
74 //@Override (Java 1.6 override semantics, but we must support 1.5)
75 public ListIterator<String> listIterator(final int index) {
76 return new ListIterator<String>() {
77 ListIterator<String> iter = list.listIterator(index);
79 //@Override (Java 1.6 override semantics, but we must support 1.5)
80 public boolean hasNext() {
81 return iter.hasNext();
84 //@Override (Java 1.6 override semantics, but we must support 1.5)
85 public String next() {
89 //@Override (Java 1.6 override semantics, but we must support 1.5)
90 public boolean hasPrevious() {
91 return iter.hasPrevious();
94 //@Override (Java 1.6 override semantics, but we must support 1.5)
95 public String previous() {
96 return iter.previous();
99 //@Override (Java 1.6 override semantics, but we must support 1.5)
100 public int nextIndex() {
101 return iter.nextIndex();
104 //@Override (Java 1.6 override semantics, but we must support 1.5)
105 public int previousIndex() {
106 return iter.previousIndex();
109 //@Override (Java 1.6 override semantics, but we must support 1.5)
110 public void remove() {
111 throw new UnsupportedOperationException();
114 //@Override (Java 1.6 override semantics, but we must support 1.5)
115 public void set(String o) {
116 throw new UnsupportedOperationException();
119 //@Override (Java 1.6 override semantics, but we must support 1.5)
120 public void add(String o) {
121 throw new UnsupportedOperationException();
127 public Iterator<String> iterator() {
128 return new Iterator<String>() {
129 Iterator<String> iter = list.iterator();
131 //@Override (Java 1.6 override semantics, but we must support 1.5)
132 public boolean hasNext() {
133 return iter.hasNext();
136 //@Override (Java 1.6 override semantics, but we must support 1.5)
137 public String next() {
141 //@Override (Java 1.6 override semantics, but we must support 1.5)
142 public void remove() {
143 throw new UnsupportedOperationException();
148 public List<?> getUnderlyingElements() {
149 // The returned value is already unmodifiable.
150 return list.getUnderlyingElements();