aboutsummaryrefslogtreecommitdiffhomepage
path: root/java/core/src/main/java/com/google/protobuf/MapEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/MapEntry.java')
-rw-r--r--java/core/src/main/java/com/google/protobuf/MapEntry.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/MapEntry.java b/java/core/src/main/java/com/google/protobuf/MapEntry.java
index 7e8e9aad..0849b821 100644
--- a/java/core/src/main/java/com/google/protobuf/MapEntry.java
+++ b/java/core/src/main/java/com/google/protobuf/MapEntry.java
@@ -33,7 +33,6 @@ package com.google.protobuf;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
-
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
@@ -171,7 +170,7 @@ public final class MapEntry<K, V> extends AbstractMessage {
@Override
public Builder<K, V> toBuilder() {
- return new Builder<K, V>(metadata, key, value);
+ return new Builder<K, V>(metadata, key, value, true, true);
}
@Override
@@ -247,15 +246,19 @@ public final class MapEntry<K, V> extends AbstractMessage {
private final Metadata<K, V> metadata;
private K key;
private V value;
+ private boolean hasKey;
+ private boolean hasValue;
private Builder(Metadata<K, V> metadata) {
- this(metadata, metadata.defaultKey, metadata.defaultValue);
+ this(metadata, metadata.defaultKey, metadata.defaultValue, false, false);
}
- private Builder(Metadata<K, V> metadata, K key, V value) {
+ private Builder(Metadata<K, V> metadata, K key, V value, boolean hasKey, boolean hasValue) {
this.metadata = metadata;
this.key = key;
this.value = value;
+ this.hasKey = hasKey;
+ this.hasValue = hasValue;
}
public K getKey() {
@@ -268,21 +271,25 @@ public final class MapEntry<K, V> extends AbstractMessage {
public Builder<K, V> setKey(K key) {
this.key = key;
+ this.hasKey = true;
return this;
}
public Builder<K, V> clearKey() {
this.key = metadata.defaultKey;
+ this.hasKey = false;
return this;
}
public Builder<K, V> setValue(V value) {
this.value = value;
+ this.hasValue = true;
return this;
}
public Builder<K, V> clearValue() {
this.value = metadata.defaultValue;
+ this.hasValue = false;
return this;
}
@@ -404,7 +411,7 @@ public final class MapEntry<K, V> extends AbstractMessage {
@Override
public boolean hasField(FieldDescriptor field) {
checkFieldDescriptor(field);
- return true;
+ return field.getNumber() == 1 ? hasKey : hasValue;
}
@Override
@@ -438,7 +445,7 @@ public final class MapEntry<K, V> extends AbstractMessage {
@Override
@SuppressWarnings("unchecked")
public Builder<K, V> clone() {
- return new Builder(metadata, key, value);
+ return new Builder(metadata, key, value, hasKey, hasValue);
}
}
@@ -448,4 +455,9 @@ public final class MapEntry<K, V> extends AbstractMessage {
}
return true;
}
+
+ /** Returns the metadata only for experimental runtime. */
+ final Metadata<K, V> getMetadata() {
+ return metadata;
+ }
}