ru.yandex.bolts.collection.Tuple4 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bolts Show documentation
Show all versions of bolts Show documentation
Collections utilities used in various Yandex projects
The newest version!
package ru.yandex.bolts.collection;
import java.io.Serializable;
import ru.yandex.bolts.function.Function;
public class Tuple4 implements Serializable {
private static final long serialVersionUID = 5566029783258786962L;
public final T1 _1;
public final T2 _2;
public final T3 _3;
public final T4 _4;
public Tuple4(T1 _1, T2 _2, T3 _3, T4 _4) {
this._1 = _1;
this._2 = _2;
this._3 = _3;
this._4 = _4;
}
public T1 get1() {
return _1;
}
public T2 get2() {
return _2;
}
public T3 get3() {
return _3;
}
public T4 get4() {
return _4;
}
@SuppressWarnings("unchecked")
private A get(int a) {
switch (a) {
case 1: return (A) _1;
case 2: return (A) _2;
case 3: return (A) _3;
case 4: return (A) _4;
default: throw new IllegalArgumentException();
}
}
private Tuple2 get(int a, int b) {
return Tuple2.tuple(this.get(a), this.get(b));
}
private Tuple3 get(int a, int b, int c) {
return Tuple3.tuple(this.get(a), this.get(b), this.get(c));
}
public Tuple2 get12() {
return this.get(1, 2);
}
public Tuple2 get13() {
return this.get(1, 3);
}
public Tuple2 get14() {
return this.get(1, 4);
}
public Tuple2 get23() {
return this.get(2, 3);
}
public Tuple2 get24() {
return this.get(2, 4);
}
public Tuple2 get34() {
return this.get(3, 4);
}
public Tuple3 get123() {
return this.get(1, 2, 3);
}
public Tuple3 get124() {
return this.get(1, 2, 4);
}
public Tuple3 get234() {
return this.get(2, 3, 4);
}
public Tuple3 get134() {
return this.get(1, 3, 4);
}
@Override
public int hashCode() {
// generated by Eclipse
final int prime = 31;
int result = 1;
result = prime * result + ((_1 == null) ? 0 : _1.hashCode());
result = prime * result + ((_2 == null) ? 0 : _2.hashCode());
result = prime * result + ((_3 == null) ? 0 : _3.hashCode());
result = prime * result + ((_4 == null) ? 0 : _4.hashCode());
return result;
}
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object obj) {
// generated by Eclipse
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Tuple4 other = (Tuple4) obj;
if (_1 == null) {
if (other._1 != null) return false;
} else if (!_1.equals(other._1)) return false;
if (_2 == null) {
if (other._2 != null) return false;
} else if (!_2.equals(other._2)) return false;
if (_3 == null) {
if (other._3 != null) return false;
} else if (!_3.equals(other._3)) return false;
if (_4 == null) {
if (other._4 != null) return false;
} else if (!_4.equals(other._4)) return false;
return true;
}
@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ")";
}
public static Function, A> get1F() {
return Tuple4::get1;
}
public static Function, B> get2F() {
return Tuple4::get2;
}
public static Function, C> get3F() {
return Tuple4::get3;
}
public static Function, D> get4F() {
return Tuple4::get4;
}
public static Function, Tuple4> map1F(final Function m) {
return t -> tuple(m.apply(t._1), t._2, t._3, t._4);
}
public static Function, Tuple4> map2F(final Function m) {
return t -> tuple(t._1, m.apply(t._2), t._3, t._4);
}
public static Function, Tuple4> map3F(final Function m) {
return t -> tuple(t._1, t._2, m.apply(t._3), t._4);
}
public static Function, Tuple4> map4F(final Function m) {
return t -> tuple(t._1, t._2, t._3, m.apply(t._4));
}
public static Function> join(final Function fa, final Function fb, final Function fc, final Function fd) {
return e -> Tuple4.tuple(fa.apply(e), fb.apply(e), fc.apply(e), fd.apply(e));
}
private static Function, Tuple2> getF(final int e, final int f) {
return t -> t.get(e, f);
}
private static Function, Tuple3> getF(final int e, final int f, final int g) {
return t -> t.get(e, f, g);
}
public static Function, Tuple2> get12F() {
return getF(1, 2);
}
public static Function, Tuple2> get13F() {
return getF(1, 3);
}
public static Function, Tuple2> get14F() {
return getF(1, 4);
}
public static Function, Tuple2> get23F() {
return getF(2, 3);
}
public static Function, Tuple2> get24F() {
return getF(2, 4);
}
public static Function, Tuple2> get34F() {
return getF(3, 4);
}
public static Function, Tuple3> get123F() {
return getF(1, 2, 3);
}
public static Function, Tuple3> get124F() {
return getF(1, 2, 4);
}
public static Function, Tuple3> get134F() {
return getF(1, 3, 4);
}
public static Function, Tuple3> get234F() {
return getF(2, 3, 4);
}
public static Tuple4 tuple(A a, B b, C c, D d) {
return new Tuple4<>(a, b, c, d);
}
} //~