com.landawn.abacus.util.BytePair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-util-all-jdk7 Show documentation
Show all versions of abacus-util-all-jdk7 Show documentation
A general programming library in Java
package com.landawn.abacus.util;
import com.landawn.abacus.util.stream.Stream;
public class BytePair {
public final byte _1;
public final byte _2;
BytePair() {
this((byte) 0, (byte) 0);
}
BytePair(byte _1, byte _2) {
this._1 = _1;
this._2 = _2;
}
public static BytePair of(byte _1, byte _2) {
return new BytePair(_1, _2);
}
public static BytePair from(final byte[] a) {
if (N.isNullOrEmpty(a)) {
return new BytePair();
} else if (a.length == 1) {
return new BytePair(a[0], (byte) 0);
} else {
return new BytePair(a[0], a[1]);
}
}
public byte min() {
return N.min(_1, _2);
}
public byte max() {
return N.max(_1, _2);
}
public int sum() {
return _1 + _2;
}
public double average() {
return (0d + _1 + _2) / 2;
}
public BytePair reversed() {
return new BytePair(_2, _1);
}
public byte[] toArray() {
return new byte[] { _1, _2 };
}
public ByteList toList() {
return ByteList.of(_1, _2);
}
public void forEach(Try.ByteConsumer comsumer) throws E {
comsumer.accept(this._1);
comsumer.accept(this._2);
}
public void accept(Try.Consumer action) throws E {
action.accept(this);
}
public U map(Try.Function mapper) throws E {
return mapper.apply(this);
}
public Optional filter(final Try.Predicate predicate) throws E {
return predicate.test(this) ? Optional.of(this) : Optional. empty();
}
public Stream stream() {
return Stream.of(this);
}
@Override
public int hashCode() {
return 31 * _1 + this._2;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof BytePair)) {
return false;
} else {
BytePair other = (BytePair) obj;
return this._1 == other._1 && this._2 == other._2;
}
}
@Override
public String toString() {
return "[" + this._1 + ", " + this._2 + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy