Skip to content

Instantly share code, notes, and snippets.

@saket
Last active February 3, 2018 08:34
Show Gist options
  • Save saket/1a1d9552c9769d42d1f4ad363804bdd7 to your computer and use it in GitHub Desktop.
Save saket/1a1d9552c9769d42d1f4ad363804bdd7 to your computer and use it in GitHub Desktop.
import android.support.annotation.Nullable;
import com.google.auto.value.AutoValue;
/**
* Copied from {@link android.support.v4.util.Pair} to remove all @Nullable annotations.
* <p>
* Container to ease passing around a tuple of two objects.
*/
public abstract class Pair<F, S> {
public abstract F first();
public abstract S second();
public static <A, B> Pair<A, B> create(A first, B second) {
return new AutoValue_Pair_NonNullPair<>(first, second);
}
public static <A, B> Pair<A, B> createNullable(@Nullable A first, @Nullable B second) {
return new AutoValue_Pair_NullablePair<>(first, second);
}
@AutoValue
abstract static class NonNullPair<F, S> extends Pair<F, S> {
public abstract F first();
public abstract S second();
}
@AutoValue
abstract static class NullablePair<F, S> extends Pair<F, S> {
@Nullable
public abstract F first();
@Nullable
public abstract S second();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment