Memoize methods of ExternalId and ExternalId.Key

The results of the following methods does not change:

- ExternalId.toString()
- ExternalId.Key.sha1()
- ExternalId.Key.hashCode()

AutoValue provides the @Memoized annotation [1]. With it the return value
will be stored and not computed again.

[1] https://github.com/google/auto/blob/master/value/userguide/howto.md#-memoize-the-result-of-hashcode-or-tostring

Change-Id: Iad599d3351934f746e4cfcc9357697538e5eaaa4
diff --git a/java/com/google/gerrit/server/account/externalids/ExternalId.java b/java/com/google/gerrit/server/account/externalids/ExternalId.java
index 8bf095c..30f4094 100644
--- a/java/com/google/gerrit/server/account/externalids/ExternalId.java
+++ b/java/com/google/gerrit/server/account/externalids/ExternalId.java
@@ -191,6 +191,7 @@
      * notes branch.
      */
     @SuppressWarnings("deprecation") // Use Hashing.sha1 for compatibility.
+    @Memoized
     public ObjectId sha1() {
       String keyString = isCaseInsensitive() ? get().toLowerCase(Locale.US) : get();
       return ObjectId.fromRaw(Hashing.sha1().hashString(keyString, UTF_8).asBytes());
@@ -226,7 +227,8 @@
     }
 
     @Override
-    public final int hashCode() {
+    @Memoized
+    public int hashCode() {
       return Objects.hash(sha1());
     }
 
@@ -322,7 +324,8 @@
    * </pre>
    */
   @Override
-  public final String toString() {
+  @Memoized
+  public String toString() {
     Config c = new Config();
     writeToConfig(c);
     return c.toText();