Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/ExternalEvaluation/Java/ExternalEvaluation.Service/src/com/google/protobuf/UnmodifiableLazyStringList.java @ 15014

Last change on this file since 15014 was 15014, checked in by pfleck, 7 years ago

Added code and tools for the ExternalEvaluationProblem. (e.g. Java-side evaluation)

File size: 4.8 KB
Line 
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3// http://code.google.com/p/protobuf/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
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
14// distribution.
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.
18//
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.
30
31package com.google.protobuf;
32
33import java.util.AbstractList;
34import java.util.RandomAccess;
35import java.util.ListIterator;
36import java.util.Iterator;
37
38/**
39 * An implementation of {@link LazyStringList} that wraps another
40 * {@link LazyStringList} such that it cannot be modified via the wrapper.
41 *
42 * @author jonp@google.com (Jon Perlow)
43 */
44public class UnmodifiableLazyStringList extends AbstractList<String>
45    implements LazyStringList, RandomAccess {
46
47  private final LazyStringList list;
48
49  public UnmodifiableLazyStringList(LazyStringList list) {
50    this.list = list;
51  }
52
53  @Override
54  public String get(int index) {
55    return list.get(index);
56  }
57
58  @Override
59  public int size() {
60    return list.size();
61  }
62
63  //@Override (Java 1.6 override semantics, but we must support 1.5)
64  public ByteString getByteString(int index) {
65    return list.getByteString(index);
66  }
67
68  //@Override (Java 1.6 override semantics, but we must support 1.5)
69  public void add(ByteString element) {
70    throw new UnsupportedOperationException();
71  }
72
73  //@Override (Java 1.6 override semantics, but we must support 1.5)
74  public ListIterator<String> listIterator(final int index) {
75    return new ListIterator<String>() {
76      ListIterator<String> iter = list.listIterator(index);
77
78      //@Override (Java 1.6 override semantics, but we must support 1.5)
79      public boolean hasNext() {
80        return iter.hasNext();
81      }
82
83      //@Override (Java 1.6 override semantics, but we must support 1.5)
84      public String next() {
85        return iter.next();
86      }
87
88      //@Override (Java 1.6 override semantics, but we must support 1.5)
89      public boolean hasPrevious() {
90        return iter.hasPrevious();
91      }
92
93      //@Override (Java 1.6 override semantics, but we must support 1.5)
94      public String previous() {
95        return iter.previous();
96      }
97
98      //@Override (Java 1.6 override semantics, but we must support 1.5)
99      public int nextIndex() {
100        return iter.nextIndex();
101      }
102
103      //@Override (Java 1.6 override semantics, but we must support 1.5)
104      public int previousIndex() {
105        return iter.previousIndex();
106      }
107
108      //@Override (Java 1.6 override semantics, but we must support 1.5)
109      public void remove() {
110        throw new UnsupportedOperationException();
111      }
112
113      //@Override (Java 1.6 override semantics, but we must support 1.5)
114      public void set(String o) {
115        throw new UnsupportedOperationException();
116      }
117
118      //@Override (Java 1.6 override semantics, but we must support 1.5)
119      public void add(String o) {
120        throw new UnsupportedOperationException();
121      }
122    };
123  }
124
125  @Override
126  public Iterator<String> iterator() {
127    return new Iterator<String>() {
128      Iterator<String> iter = list.iterator();
129
130      //@Override (Java 1.6 override semantics, but we must support 1.5)
131      public boolean hasNext() {
132        return iter.hasNext();
133      }
134
135      //@Override (Java 1.6 override semantics, but we must support 1.5)
136      public String next() {
137        return iter.next();
138      }
139
140      //@Override (Java 1.6 override semantics, but we must support 1.5)
141      public void remove() {
142        throw new UnsupportedOperationException();
143      }
144    };
145  }
146}
Note: See TracBrowser for help on using the repository browser.