All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.checkerframework.javacutil.Pair Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0
Show newest version
package org.checkerframework.javacutil;

import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
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 { public final V1 first; public final V2 second; private Pair(V1 v1, V2 v2) { this.first = v1; this.second = v2; } public static Pair of(V1 v1, V2 v2) { return new Pair<>(v1, v2); } @SideEffectFree @Override public String toString() { return "Pair(" + first + ", " + second + ")"; } private int hashCode = -1; @Pure @Override public int hashCode() { if (hashCode == -1) { hashCode = Objects.hash(first, second); } return hashCode; } @Override public boolean equals(@Nullable Object o) { if (!(o instanceof Pair)) { return false; } @SuppressWarnings("unchecked") Pair other = (Pair) o; return Objects.equals(this.first, other.first) && Objects.equals(this.second, other.second); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy