aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/google/common/io/protocol/ProtoBufType.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
commit15bf10329ff5ed4b039918df3f053eaf67851e1b (patch)
tree8cc167a495ef9e348ba84f56188fe583564604e5 /src/com/google/common/io/protocol/ProtoBufType.java
parent214e14d5efd24389ae5bd7c3debe4bb28dbd667a (diff)
downloadexternal_protobuf-15bf10329ff5ed4b039918df3f053eaf67851e1b.zip
external_protobuf-15bf10329ff5ed4b039918df3f053eaf67851e1b.tar.gz
external_protobuf-15bf10329ff5ed4b039918df3f053eaf67851e1b.tar.bz2
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'src/com/google/common/io/protocol/ProtoBufType.java')
-rw-r--r--src/com/google/common/io/protocol/ProtoBufType.java50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/com/google/common/io/protocol/ProtoBufType.java b/src/com/google/common/io/protocol/ProtoBufType.java
index 1aec8f9..4b6408e 100644
--- a/src/com/google/common/io/protocol/ProtoBufType.java
+++ b/src/com/google/common/io/protocol/ProtoBufType.java
@@ -1,4 +1,4 @@
-// Copyright 2007 The Android Open Source Project
+// Copyright 2007 Google Inc.
// All Rights Reserved.
package com.google.common.io.protocol;
@@ -9,7 +9,6 @@ import java.util.*;
* This class can be used to create a memory model of a .proto file. Currently,
* it is assumed that tags ids are not large. This could be improved by storing
* a start offset, relaxing the assumption to a dense number space.
- *
*/
public class ProtoBufType {
// Note: Values 0..15 are reserved for wire types!
@@ -121,4 +120,51 @@ public class ProtoBufType {
public String toString() {
return typeName;
}
+
+ /**
+ * {@inheritDoc}
+ * <p>Two ProtoBufTypes are equals if the fields types are the same.
+ */
+ public boolean equals(Object object) {
+ if (null == object) {
+ // trivial check
+ return false;
+ } else if (this == object) {
+ // trivial check
+ return true;
+ } else if (this.getClass() != object.getClass()) {
+ // different class
+ return false;
+ }
+ ProtoBufType other = (ProtoBufType) object;
+
+ return stringEquals(types, other.types);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode() {
+ if (types != null) {
+ return types.hashCode();
+ } else {
+ return super.hashCode();
+ }
+ }
+
+ public static boolean stringEquals(CharSequence a, CharSequence b) {
+ if (a == b) return true;
+ int length;
+ if (a != null && b != null && (length = a.length()) == b.length()) {
+ if (a instanceof String && b instanceof String) {
+ return a.equals(b);
+ } else {
+ for (int i = 0; i < length; i++) {
+ if (a.charAt(i) != b.charAt(i)) return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
}