Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 14 matching lines...) Expand all
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 package com.google.protobuf; 31 package com.google.protobuf;
32 32
33 import com.google.protobuf.Descriptors.Descriptor; 33 import com.google.protobuf.Descriptors.Descriptor;
34 import com.google.protobuf.Descriptors.FieldDescriptor; 34 import com.google.protobuf.Descriptors.FieldDescriptor;
35
36 import java.util.Collection; 35 import java.util.Collection;
37 import java.util.Collections; 36 import java.util.Collections;
38 import java.util.HashMap; 37 import java.util.HashMap;
39 import java.util.HashSet; 38 import java.util.HashSet;
40 import java.util.Map; 39 import java.util.Map;
41 import java.util.Set; 40 import java.util.Set;
42 41
43 /** 42 /**
44 * A table of known extensions, searchable by name or field number. When 43 * A table of known extensions, searchable by name or field number. When
45 * parsing a protocol message that might have extensions, you must provide 44 * parsing a protocol message that might have extensions, you must provide
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 * @author kenton@google.com Kenton Varda 93 * @author kenton@google.com Kenton Varda
95 */ 94 */
96 public class ExtensionRegistry extends ExtensionRegistryLite { 95 public class ExtensionRegistry extends ExtensionRegistryLite {
97 /** Construct a new, empty instance. */ 96 /** Construct a new, empty instance. */
98 public static ExtensionRegistry newInstance() { 97 public static ExtensionRegistry newInstance() {
99 return new ExtensionRegistry(); 98 return new ExtensionRegistry();
100 } 99 }
101 100
102 /** Get the unmodifiable singleton empty instance. */ 101 /** Get the unmodifiable singleton empty instance. */
103 public static ExtensionRegistry getEmptyRegistry() { 102 public static ExtensionRegistry getEmptyRegistry() {
104 return EMPTY; 103 return EMPTY_REGISTRY;
105 } 104 }
106 105
107 106
108 /** Returns an unmodifiable view of the registry. */ 107 /** Returns an unmodifiable view of the registry. */
109 @Override 108 @Override
110 public ExtensionRegistry getUnmodifiable() { 109 public ExtensionRegistry getUnmodifiable() {
111 return new ExtensionRegistry(this); 110 return new ExtensionRegistry(this);
112 } 111 }
113 112
114 /** A (Descriptor, Message) pair, returned by lookup methods. */ 113 /** A (Descriptor, Message) pair, returned by lookup methods. */
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 /** Add an extension from a generated file to the registry. */ 235 /** Add an extension from a generated file to the registry. */
237 public void add(final Extension<?, ?> extension) { 236 public void add(final Extension<?, ?> extension) {
238 if (extension.getExtensionType() != Extension.ExtensionType.IMMUTABLE && 237 if (extension.getExtensionType() != Extension.ExtensionType.IMMUTABLE &&
239 extension.getExtensionType() != Extension.ExtensionType.MUTABLE) { 238 extension.getExtensionType() != Extension.ExtensionType.MUTABLE) {
240 // do not support other extension types. ignore 239 // do not support other extension types. ignore
241 return; 240 return;
242 } 241 }
243 add(newExtensionInfo(extension), extension.getExtensionType()); 242 add(newExtensionInfo(extension), extension.getExtensionType());
244 } 243 }
245 244
245 /** Add an extension from a generated file to the registry. */
246 public void add(final GeneratedMessage.GeneratedExtension<?, ?> extension) {
247 add((Extension<?, ?>) extension);
248 }
249
246 static ExtensionInfo newExtensionInfo(final Extension<?, ?> extension) { 250 static ExtensionInfo newExtensionInfo(final Extension<?, ?> extension) {
247 if (extension.getDescriptor().getJavaType() == 251 if (extension.getDescriptor().getJavaType() ==
248 FieldDescriptor.JavaType.MESSAGE) { 252 FieldDescriptor.JavaType.MESSAGE) {
249 if (extension.getMessageDefaultInstance() == null) { 253 if (extension.getMessageDefaultInstance() == null) {
250 throw new IllegalStateException( 254 throw new IllegalStateException(
251 "Registered message-type extension had null default instance: " + 255 "Registered message-type extension had null default instance: " +
252 extension.getDescriptor().getFullName()); 256 extension.getDescriptor().getFullName());
253 } 257 }
254 return new ExtensionInfo(extension.getDescriptor(), 258 return new ExtensionInfo(extension.getDescriptor(),
255 (Message) extension.getMessageDefaultInstance()); 259 (Message) extension.getMessageDefaultInstance());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 this.mutableExtensionsByNumber = 308 this.mutableExtensionsByNumber =
305 Collections.unmodifiableMap(other.mutableExtensionsByNumber); 309 Collections.unmodifiableMap(other.mutableExtensionsByNumber);
306 } 310 }
307 311
308 private final Map<String, ExtensionInfo> immutableExtensionsByName; 312 private final Map<String, ExtensionInfo> immutableExtensionsByName;
309 private final Map<String, ExtensionInfo> mutableExtensionsByName; 313 private final Map<String, ExtensionInfo> mutableExtensionsByName;
310 private final Map<DescriptorIntPair, ExtensionInfo> immutableExtensionsByNumbe r; 314 private final Map<DescriptorIntPair, ExtensionInfo> immutableExtensionsByNumbe r;
311 private final Map<DescriptorIntPair, ExtensionInfo> mutableExtensionsByNumber; 315 private final Map<DescriptorIntPair, ExtensionInfo> mutableExtensionsByNumber;
312 316
313 ExtensionRegistry(boolean empty) { 317 ExtensionRegistry(boolean empty) {
314 super(ExtensionRegistryLite.getEmptyRegistry()); 318 super(EMPTY_REGISTRY_LITE);
315 this.immutableExtensionsByName = 319 this.immutableExtensionsByName =
316 Collections.<String, ExtensionInfo>emptyMap(); 320 Collections.<String, ExtensionInfo>emptyMap();
317 this.mutableExtensionsByName = 321 this.mutableExtensionsByName =
318 Collections.<String, ExtensionInfo>emptyMap(); 322 Collections.<String, ExtensionInfo>emptyMap();
319 this.immutableExtensionsByNumber = 323 this.immutableExtensionsByNumber =
320 Collections.<DescriptorIntPair, ExtensionInfo>emptyMap(); 324 Collections.<DescriptorIntPair, ExtensionInfo>emptyMap();
321 this.mutableExtensionsByNumber = 325 this.mutableExtensionsByNumber =
322 Collections.<DescriptorIntPair, ExtensionInfo>emptyMap(); 326 Collections.<DescriptorIntPair, ExtensionInfo>emptyMap();
323 } 327 }
324 private static final ExtensionRegistry EMPTY = new ExtensionRegistry(true); 328 static final ExtensionRegistry EMPTY_REGISTRY = new ExtensionRegistry(true);
325 329
326 private void add( 330 private void add(
327 final ExtensionInfo extension, 331 final ExtensionInfo extension,
328 final Extension.ExtensionType extensionType) { 332 final Extension.ExtensionType extensionType) {
329 if (!extension.descriptor.isExtension()) { 333 if (!extension.descriptor.isExtension()) {
330 throw new IllegalArgumentException( 334 throw new IllegalArgumentException(
331 "ExtensionRegistry.add() was given a FieldDescriptor for a regular " + 335 "ExtensionRegistry.add() was given a FieldDescriptor for a regular " +
332 "(non-extension) field."); 336 "(non-extension) field.");
333 } 337 }
334 338
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 @Override 387 @Override
384 public boolean equals(final Object obj) { 388 public boolean equals(final Object obj) {
385 if (!(obj instanceof DescriptorIntPair)) { 389 if (!(obj instanceof DescriptorIntPair)) {
386 return false; 390 return false;
387 } 391 }
388 final DescriptorIntPair other = (DescriptorIntPair)obj; 392 final DescriptorIntPair other = (DescriptorIntPair)obj;
389 return descriptor == other.descriptor && number == other.number; 393 return descriptor == other.descriptor && number == other.number;
390 } 394 }
391 } 395 }
392 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698