diff options
author | 2016-06-29 14:24:16 +0200 | |
---|---|---|
committer | 2016-06-30 15:11:05 +0200 | |
commit | a18add1613574a15c81f60bde847c5d7b2bedcb5 (patch) | |
tree | 103fa812c66403f5e8caefb898ea3f18107865dc /third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java | |
parent | 14c7964b8bc0da2bab65b1c28aa8c302846d7720 (diff) |
Adds the source of the checker framework
This needs to predate the rest of the changes to the checker framework to keep the build green.
Also add the source of javacutil part of the checker framework, that will be included in the next change.
Change-Id: Ie18d0e8e21035ce5141416e552a83d893f71b88b
Diffstat (limited to 'third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java')
-rw-r--r-- | third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java new file mode 100644 index 0000000000..0d8a862f08 --- /dev/null +++ b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/Pair.java @@ -0,0 +1,69 @@ +package org.checkerframework.javacutil; + +/*>>> +import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.dataflow.qual.SideEffectFree; +*/ + +/** + * Simple pair class for multiple returns. + * + * TODO: as class is immutable, use @Covariant annotation. + */ +public class Pair<V1, V2> { + public final V1 first; + public final V2 second; + + private Pair(V1 v1, V2 v2) { + this.first = v1; + this.second = v2; + } + + public static <V1, V2> Pair<V1, V2> of(V1 v1, V2 v2) { + return new Pair<V1, V2>(v1, v2); + } + + /*@SideEffectFree*/ + @Override + public String toString() { + return "Pair(" + first + ", " + second + ")"; + } + + private int hashCode = -1; + + /*@Pure*/ + @Override + public int hashCode() { + if (hashCode == -1) { + hashCode = 31; + if (first != null) { + hashCode += 17 * first.hashCode(); + } + if (second != null) { + hashCode += 17 * second.hashCode(); + } + } + return hashCode; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Pair)) { + return false; + } + @SuppressWarnings("unchecked") + Pair<V1, V2> other = (Pair<V1, V2>) o; + if (this.first == null) { + if (other.first != null) return false; + } else { + if (!this.first.equals(other.first)) return false; + } + if (this.second == null) { + if (other.second != null) return false; + } else { + if (!this.second.equals(other.second)) return false; + } + + return true; + } +} |