LazyField.java
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
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 
31 package com.google.protobuf;
32 
33 import java.util.Iterator;
34 import java.util.Map.Entry;
35 
46 public class LazyField extends LazyFieldLite {
47 
53 
54  public LazyField(
56  super(extensionRegistry, bytes);
57 
58  this.defaultInstance = defaultInstance;
59  }
60 
61  @Override
62  public boolean containsDefaultInstance() {
63  return super.containsDefaultInstance() || value == defaultInstance;
64  }
65 
66  public MessageLite getValue() {
67  return getValue(defaultInstance);
68  }
69 
70  @Override
71  public int hashCode() {
72  return getValue().hashCode();
73  }
74 
75  @Override
76  public boolean equals(Object obj) {
77  return getValue().equals(obj);
78  }
79 
80  @Override
81  public String toString() {
82  return getValue().toString();
83  }
84 
85  // ====================================================
86 
91  static class LazyEntry<K> implements Entry<K, Object> {
92  private Entry<K, LazyField> entry;
93 
94  private LazyEntry(Entry<K, LazyField> entry) {
95  this.entry = entry;
96  }
97 
98  @Override
99  public K getKey() {
100  return entry.getKey();
101  }
102 
103  @Override
104  public Object getValue() {
105  LazyField field = entry.getValue();
106  if (field == null) {
107  return null;
108  }
109  return field.getValue();
110  }
111 
112  public LazyField getField() {
113  return entry.getValue();
114  }
115 
116  @Override
117  public Object setValue(Object value) {
118  if (!(value instanceof MessageLite)) {
119  throw new IllegalArgumentException(
120  "LazyField now only used for MessageSet, "
121  + "and the value of MessageSet must be an instance of MessageLite");
122  }
123  return entry.getValue().setValue((MessageLite) value);
124  }
125  }
126 
127  static class LazyIterator<K> implements Iterator<Entry<K, Object>> {
128  private Iterator<Entry<K, Object>> iterator;
129 
130  public LazyIterator(Iterator<Entry<K, Object>> iterator) {
131  this.iterator = iterator;
132  }
133 
134  @Override
135  public boolean hasNext() {
136  return iterator.hasNext();
137  }
138 
139  @Override
140  @SuppressWarnings("unchecked")
141  public Entry<K, Object> next() {
142  Entry<K, ?> entry = iterator.next();
143  if (entry.getValue() instanceof LazyField) {
144  return new LazyEntry<K>((Entry<K, LazyField>) entry);
145  }
146  return (Entry<K, Object>) entry;
147  }
148 
149  @Override
150  public void remove() {
151  iterator.remove();
152  }
153  }
154 }
K
#define K(t)
Definition: sha1.c:43
com.google.protobuf.LazyFieldLite.setValue
MessageLite setValue(MessageLite value)
Definition: LazyFieldLite.java:233
com.google.protobuf.LazyField.LazyField
LazyField(MessageLite defaultInstance, ExtensionRegistryLite extensionRegistry, ByteString bytes)
Definition: LazyField.java:54
com.google.protobuf.LazyField.getValue
MessageLite getValue()
Definition: LazyField.java:66
com.google.protobuf.LazyField.containsDefaultInstance
boolean containsDefaultInstance()
Definition: LazyField.java:62
bytes
uint8 bytes[10]
Definition: coded_stream_unittest.cc:153
com.google.protobuf.LazyField.toString
String toString()
Definition: LazyField.java:81
obj
GLsizei GLsizei GLuint * obj
Definition: glcorearb.h:3066
com.google.protobuf.ExtensionRegistryLite
Definition: ExtensionRegistryLite.java:70
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
com.google.protobuf.LazyField.hashCode
int hashCode()
Definition: LazyField.java:71
com.google.protobuf.LazyFieldLite
Definition: LazyFieldLite.java:56
java
com.google.protobuf.LazyField.equals
boolean equals(Object obj)
Definition: LazyField.java:76
com.google.protobuf.LazyFieldLite.extensionRegistry
ExtensionRegistryLite extensionRegistry
Definition: LazyFieldLite.java:102
com.google.protobuf.LazyField.defaultInstance
final MessageLite defaultInstance
Definition: LazyField.java:52
next
static size_t next(const upb_table *t, size_t i)
Definition: php/ext/google/protobuf/upb.c:4889
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
com.google.protobuf.LazyField
Definition: LazyField.java:46
com.google.protobuf.MessageLite
Definition: MessageLite.java:65
com.google.protobuf.ByteString
Definition: ByteString.java:67


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55