
com.simplaex.bedrock.Triple Maven / Gradle / Ivy
package com.simplaex.bedrock;
import lombok.Value;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.List;
import java.util.function.Function;
@Value(staticConstructor = "of")
@Immutable
public class Triple implements Serializable, Comparable>, Tuple3 {
private A first;
private B second;
private C third;
@SuppressWarnings("unchecked")
@Override
public int compareTo(@Nonnull final Triple tuple) {
int r;
if (first == null) {
if (tuple.first == null) {
r = 0;
} else {
return -1;
}
} else if (tuple.first == null) {
return 1;
} else {
r = ((Comparable) first).compareTo(tuple.first);
}
if (r != 0) {
return r;
}
if (second == null) {
if (tuple.second == null) {
r = 0;
} else {
return -1;
}
} else if (tuple.second == null) {
return 1;
} else {
r = ((Comparable) second).compareTo(tuple.second);
}
if (r != 0) {
return r;
}
if (third == null) {
if (tuple.third == null) {
return 0;
} else {
return -1;
}
} else if (tuple.third == null) {
return 1;
} else {
return ((Comparable) third).compareTo(tuple.third);
}
}
@Nonnull
public static List toList(final Triple tuple) {
return new AbstractList() {
@Override
public D get(final int index) {
switch (index) {
case 0:
return tuple.getFirst();
case 1:
return tuple.getSecond();
case 2:
return tuple.getThird();
default:
return null;
}
}
@Override
public int size() {
return 3;
}
};
}
@Nonnull
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy