1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
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.Collection;
34 import java.util.List;
37 * An interface extending {@code List<String>} that also provides access to the
38 * items of the list as UTF8-encoded ByteString or byte[] objects. This is
39 * used by the protocol buffer implementation to support lazily converting bytes
40 * parsed over the wire to String objects until needed and also increases the
41 * efficiency of serialization if the String was never requested as the
42 * ByteString or byte[] is already cached. The ByteString methods are used in
43 * immutable API only and byte[] methods used in mutable API only for they use
44 * different representations for string/bytes fields.
46 * @author jonp@google.com (Jon Perlow)
48 public interface LazyStringList extends ProtocolStringList {
51 * Returns the element at the specified position in this list as a ByteString.
53 * @param index index of the element to return
54 * @return the element at the specified position in this list
55 * @throws IndexOutOfBoundsException if the index is out of range
56 * ({@code index < 0 || index >= size()})
58 ByteString getByteString(int index);
61 * Returns the element at the specified position in this list as byte[].
63 * @param index index of the element to return
64 * @return the element at the specified position in this list
65 * @throws IndexOutOfBoundsException if the index is out of range
66 * ({@code index < 0 || index >= size()})
68 byte[] getByteArray(int index);
71 * Appends the specified element to the end of this list (optional
74 * @param element element to be appended to this list
75 * @throws UnsupportedOperationException if the <tt>add</tt> operation
76 * is not supported by this list
78 void add(ByteString element);
81 * Appends the specified element to the end of this list (optional
84 * @param element element to be appended to this list
85 * @throws UnsupportedOperationException if the <tt>add</tt> operation
86 * is not supported by this list
88 void add(byte[] element);
91 * Replaces the element at the specified position in this list with the
92 * specified element (optional operation).
94 * @param index index of the element to replace
95 * @param element the element to be stored at the specified position
96 * @throws UnsupportedOperationException if the <tt>set</tt> operation
97 * is not supported by this list
98 * IndexOutOfBoundsException if the index is out of range
99 * ({@code index < 0 || index >= size()})
101 void set(int index, ByteString element);
104 * Replaces the element at the specified position in this list with the
105 * specified element (optional operation).
107 * @param index index of the element to replace
108 * @param element the element to be stored at the specified position
109 * @throws UnsupportedOperationException if the <tt>set</tt> operation
110 * is not supported by this list
111 * IndexOutOfBoundsException if the index is out of range
112 * ({@code index < 0 || index >= size()})
114 void set(int index, byte[] element);
117 * Appends all elements in the specified ByteString collection to the end of
120 * @param c collection whose elements are to be added to this list
121 * @return true if this list changed as a result of the call
122 * @throws UnsupportedOperationException if the <tt>addAllByteString</tt>
123 * operation is not supported by this list
125 boolean addAllByteString(Collection<? extends ByteString> c);
128 * Appends all elements in the specified byte[] collection to the end of
131 * @param c collection whose elements are to be added to this list
132 * @return true if this list changed as a result of the call
133 * @throws UnsupportedOperationException if the <tt>addAllByteArray</tt>
134 * operation is not supported by this list
136 boolean addAllByteArray(Collection<byte[]> c);
139 * Returns an unmodifiable List of the underlying elements, each of which is
140 * either a {@code String} or its equivalent UTF-8 encoded {@code ByteString}
141 * or byte[]. It is an error for the caller to modify the returned
142 * List, and attempting to do so will result in an
143 * {@link UnsupportedOperationException}.
145 List<?> getUnderlyingElements();
148 * Merges all elements from another LazyStringList into this one. This method
149 * differs from {@link #addAll(Collection)} on that underlying byte arrays are
150 * copied instead of reference shared. Immutable API doesn't need to use this
151 * method as byte[] is not used there at all.
153 void mergeFrom(LazyStringList other);
156 * Returns a mutable view of this list. Changes to the view will be made into
157 * the original list. This method is used in mutable API only.
159 List<byte[]> asByteArrayList();
161 /** Returns an unmodifiable view of the list. */
162 LazyStringList getUnmodifiableView();