aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/util/Fingerprint.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/util/Fingerprint.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/util/Fingerprint.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/Fingerprint.java b/src/main/java/com/google/devtools/build/lib/util/Fingerprint.java
index 443b8a02ea..eb053f9be6 100644
--- a/src/main/java/com/google/devtools/build/lib/util/Fingerprint.java
+++ b/src/main/java/com/google/devtools/build/lib/util/Fingerprint.java
@@ -25,6 +25,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.UUID;
+import javax.annotation.Nullable;
+
/**
* Simplified wrapper for MD5 message digests. See also
* com.google.math.crypto.MD5HMAC for a similar interface.
@@ -139,6 +141,14 @@ public final class Fingerprint {
}
/**
+ * Updates the digest with a boolean value, correctly handling null.
+ */
+ public Fingerprint addNullableBoolean(Boolean input) {
+ addInt(input == null ? -1 : (input.booleanValue() ? 1 : 0));
+ return this;
+ }
+
+ /**
* Updates the digest with the little-endian bytes of a given int value.
*
* @param input the integer with which to update the digest
@@ -175,6 +185,22 @@ public final class Fingerprint {
}
/**
+ * Updates the digest with the little-endian bytes of a given int value, correctly distinguishing
+ * between null and non-null values.
+ *
+ * @param input the integer with which to update the digest
+ */
+ public Fingerprint addNullableInt(@Nullable Integer input) {
+ if (input == null) {
+ addInt(0);
+ } else {
+ addInt(1);
+ addInt(input);
+ }
+ return this;
+ }
+
+ /**
* Updates the digest with a UUID.
*
* @param uuid the UUID with which to update the digest. Must not be null.
@@ -199,6 +225,22 @@ public final class Fingerprint {
}
/**
+ * Updates the digest with a String using its length plus its UTF8 encoded bytes; if the string
+ * is null, then it uses -1 as the length.
+ *
+ * @param input the String with which to update the digest
+ * @see java.security.MessageDigest#update(byte[])
+ */
+ public Fingerprint addNullableString(@Nullable String input) {
+ if (input == null) {
+ addInt(-1);
+ } else {
+ addString(input);
+ }
+ return this;
+ }
+
+ /**
* Updates the digest with a String using its length and content.
*
* @param input the String with which to update the digest