Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
eu.lunisolar.magma.func.tuple.LObjIntByteTriple Maven / Gradle / Ivy
/*
* This file is part of "lunisolar-magma".
*
* (C) Copyright 2014-2019 Lunisolar (http://lunisolar.eu/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.lunisolar.magma.func.tuple;
import eu.lunisolar.magma.basics.meta.LTuple;
import eu.lunisolar.magma.basics.Null;
import eu.lunisolar.magma.basics.fluent.Fluent;
import eu.lunisolar.magma.func.function.LFunction;
import eu.lunisolar.magma.func.function.to.*;
import eu.lunisolar.magma.func.operator.unary.*;
import eu.lunisolar.magma.func.operator.binary.*;
import eu.lunisolar.magma.func.predicate.*;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.*;
/**
* Exact equivalent of input parameters used in LTieByteConsumer.
*/
@SuppressWarnings("UnusedDeclaration")
public interface LObjIntByteTriple extends LTuple, LObjIntPair {
int SIZE = 3;
T first();
default T value() {
return first();
}
int second();
byte third();
default Object get(int index) {
switch (index) {
case 1 :
return first();
case 2 :
return second();
case 3 :
return third();
default :
throw new NoSuchElementException();
}
}
/** Tuple size */
default int size() {
return SIZE;
}
/** Static hashCode() implementation method that takes same arguments as fields of the LObjIntByteTriple and calculates hash from it. */
static int argHashCode(T a1, int a2, byte a3) {
final int prime = 31;
int result = 1;
result = prime * result + ((a1 == null) ? 0 : a1.hashCode());
result = prime * result + Integer.hashCode(a2);
result = prime * result + Byte.hashCode(a3);
return result;
}
/** Static equals() implementation that takes same arguments (doubled) as fields of the LObjIntByteTriple and checks if all values are equal. */
static boolean argEquals(T a1, int a2, byte a3, T b1, int b2, byte b3) {
return Null.equals(a1, b1) && //
a2 == b2 && //
a3 == b3; //
}
/**
* Static equals() implementation that takes two tuples asnd checks if they are equal.
*
* Tuples are considered equal if are implementing same interface and their tuple values are equal regardless of the implementing class.
*/
static boolean argEquals(LObjIntByteTriple the, Object that) {
return Null.equals(the, that, (one, two) -> {
// Intentionally all implementations of LObjIntByteTriple are allowed.
if (!(two instanceof LObjIntByteTriple)) {
return false;
}
LObjIntByteTriple other = (LObjIntByteTriple) two;
return argEquals(one.first(), one.second(), one.third(), other.first(), other.second(), other.third());
});
}
default Iterator iterator() {
return new Iterator() {
private int index;
@Override
public boolean hasNext() {
return index < SIZE;
}
@Override
public Object next() {
index++;
return get(index);
}
};
}
interface ComparableObjIntByteTriple> extends LObjIntByteTriple, Comparable> {
@Override
default int compareTo(LObjIntByteTriple that) {
return Null.compare(this, that, (one, two) -> {
int retval = 0;
return (retval = Null.compare(one.first(), two.first())) != 0 ? retval : //
(retval = Integer.compare(one.second(), two.second())) != 0 ? retval : //
(retval = Byte.compare(one.third(), two.third())) != 0 ? retval : 0; //
});
}
}
abstract class AbstractObjIntByteTriple implements LObjIntByteTriple {
@Override
public boolean equals(Object that) {
return LObjIntByteTriple.argEquals(this, that);
}
@Override
public int hashCode() {
return LObjIntByteTriple.argHashCode(first(), second(), third());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('(');
sb.append(first());
sb.append(',');
sb.append(second());
sb.append(',');
sb.append(third());
sb.append(')');
return sb.toString();
}
}
/**
* Mutable, non-comparable tuple.
*/
final class MutObjIntByteTriple extends AbstractObjIntByteTriple {
private T first;
private int second;
private byte third;
public MutObjIntByteTriple(T a1, int a2, byte a3) {
this.first = a1;
this.second = a2;
this.third = a3;
}
public static MutObjIntByteTriple of(T a1, int a2, byte a3) {
return new MutObjIntByteTriple(a1, a2, a3);
}
public static MutObjIntByteTriple copyOf(LObjIntByteTriple tuple) {
return of(tuple.first(), tuple.second(), tuple.third());
}
public T first() {
return first;
}
public MutObjIntByteTriple first(T first) {
this.first = first;
return this;
}
public int second() {
return second;
}
public MutObjIntByteTriple second(int second) {
this.second = second;
return this;
}
public byte third() {
return third;
}
public MutObjIntByteTriple third(byte third) {
this.third = third;
return this;
}
public MutObjIntByteTriple setFirst(T first) {
this.first = first;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutObjIntByteTriple setFirstIfArg(T first, LPredicate predicate) {
if (predicate.test(first)) {
this.first = first;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutObjIntByteTriple setFirstIfArgNotNull(R arg, LFunction func) {
if (arg != null) {
this.first = func.apply(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutObjIntByteTriple setFirstIf(LPredicate predicate, T first) {
if (predicate.test(this.first)) {
this.first = first;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutObjIntByteTriple setFirstIf(T first, LBiPredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(first, this.first)) {
this.first = first;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutObjIntByteTriple setFirstIf(LBiPredicate predicate, T first) {
if (predicate.test(this.first, first)) {
this.first = first;
}
return this;
}
public MutObjIntByteTriple setSecond(int second) {
this.second = second;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutObjIntByteTriple setSecondIfArg(int second, LIntPredicate predicate) {
if (predicate.test(second)) {
this.second = second;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutObjIntByteTriple setSecondIfArgNotNull(R arg, LToIntFunction func) {
if (arg != null) {
this.second = func.applyAsInt(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutObjIntByteTriple setSecondIf(LIntPredicate predicate, int second) {
if (predicate.test(this.second)) {
this.second = second;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutObjIntByteTriple setSecondIf(int second, LBiIntPredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(second, this.second)) {
this.second = second;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutObjIntByteTriple setSecondIf(LBiIntPredicate predicate, int second) {
if (predicate.test(this.second, second)) {
this.second = second;
}
return this;
}
public MutObjIntByteTriple setThird(byte third) {
this.third = third;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutObjIntByteTriple setThirdIfArg(byte third, LBytePredicate predicate) {
if (predicate.test(third)) {
this.third = third;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutObjIntByteTriple setThirdIfArgNotNull(R arg, LToByteFunction func) {
if (arg != null) {
this.third = func.applyAsByte(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutObjIntByteTriple setThirdIf(LBytePredicate predicate, byte third) {
if (predicate.test(this.third)) {
this.third = third;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutObjIntByteTriple setThirdIf(byte third, LBiBytePredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(third, this.third)) {
this.third = third;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutObjIntByteTriple setThirdIf(LBiBytePredicate predicate, byte third) {
if (predicate.test(this.third, third)) {
this.third = third;
}
return this;
}
public void reset() {
first = null;
second = 0;
third = (byte) 0;
}
}
/**
* Mutable, comparable tuple.
*/
final class MutCompObjIntByteTriple> extends AbstractObjIntByteTriple implements ComparableObjIntByteTriple {
private T first;
private int second;
private byte third;
public MutCompObjIntByteTriple(T a1, int a2, byte a3) {
this.first = a1;
this.second = a2;
this.third = a3;
}
public static > MutCompObjIntByteTriple of(T a1, int a2, byte a3) {
return new MutCompObjIntByteTriple(a1, a2, a3);
}
public static > MutCompObjIntByteTriple copyOf(LObjIntByteTriple tuple) {
return of(tuple.first(), tuple.second(), tuple.third());
}
public T first() {
return first;
}
public MutCompObjIntByteTriple first(T first) {
this.first = first;
return this;
}
public int second() {
return second;
}
public MutCompObjIntByteTriple second(int second) {
this.second = second;
return this;
}
public byte third() {
return third;
}
public MutCompObjIntByteTriple third(byte third) {
this.third = third;
return this;
}
public MutCompObjIntByteTriple setFirst(T first) {
this.first = first;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutCompObjIntByteTriple setFirstIfArg(T first, LPredicate predicate) {
if (predicate.test(first)) {
this.first = first;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutCompObjIntByteTriple setFirstIfArgNotNull(R arg, LFunction func) {
if (arg != null) {
this.first = func.apply(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutCompObjIntByteTriple setFirstIf(LPredicate predicate, T first) {
if (predicate.test(this.first)) {
this.first = first;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutCompObjIntByteTriple setFirstIf(T first, LBiPredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(first, this.first)) {
this.first = first;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutCompObjIntByteTriple setFirstIf(LBiPredicate predicate, T first) {
if (predicate.test(this.first, first)) {
this.first = first;
}
return this;
}
public MutCompObjIntByteTriple setSecond(int second) {
this.second = second;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutCompObjIntByteTriple setSecondIfArg(int second, LIntPredicate predicate) {
if (predicate.test(second)) {
this.second = second;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutCompObjIntByteTriple setSecondIfArgNotNull(R arg, LToIntFunction func) {
if (arg != null) {
this.second = func.applyAsInt(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutCompObjIntByteTriple setSecondIf(LIntPredicate predicate, int second) {
if (predicate.test(this.second)) {
this.second = second;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutCompObjIntByteTriple setSecondIf(int second, LBiIntPredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(second, this.second)) {
this.second = second;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutCompObjIntByteTriple setSecondIf(LBiIntPredicate predicate, int second) {
if (predicate.test(this.second, second)) {
this.second = second;
}
return this;
}
public MutCompObjIntByteTriple setThird(byte third) {
this.third = third;
return this;
}
/** Sets value if predicate(newValue) OR newValue::predicate is true */
public MutCompObjIntByteTriple setThirdIfArg(byte third, LBytePredicate predicate) {
if (predicate.test(third)) {
this.third = third;
}
return this;
}
/** Sets value derived from non-null argument, only if argument is not null. */
public MutCompObjIntByteTriple setThirdIfArgNotNull(R arg, LToByteFunction func) {
if (arg != null) {
this.third = func.applyAsByte(arg);
}
return this;
}
/** Sets value if predicate(current) OR current::predicate is true */
public MutCompObjIntByteTriple setThirdIf(LBytePredicate predicate, byte third) {
if (predicate.test(this.third)) {
this.third = third;
}
return this;
}
/** Sets new value if predicate predicate(newValue, current) OR newValue::something(current) is true. */
public MutCompObjIntByteTriple setThirdIf(byte third, LBiBytePredicate predicate) {
// the order of arguments is intentional, to allow predicate:
if (predicate.test(third, this.third)) {
this.third = third;
}
return this;
}
/** Sets new value if predicate predicate(current, newValue) OR current::something(newValue) is true. */
public MutCompObjIntByteTriple setThirdIf(LBiBytePredicate predicate, byte third) {
if (predicate.test(this.third, third)) {
this.third = third;
}
return this;
}
public void reset() {
first = null;
second = 0;
third = (byte) 0;
}
}
/**
* Immutable, non-comparable tuple.
*/
@Immutable
final class ImmObjIntByteTriple extends AbstractObjIntByteTriple {
private final T first;
private final int second;
private final byte third;
public ImmObjIntByteTriple(T a1, int a2, byte a3) {
this.first = a1;
this.second = a2;
this.third = a3;
}
public static ImmObjIntByteTriple of(T a1, int a2, byte a3) {
return new ImmObjIntByteTriple(a1, a2, a3);
}
public static ImmObjIntByteTriple copyOf(LObjIntByteTriple tuple) {
return of(tuple.first(), tuple.second(), tuple.third());
}
public T first() {
return first;
}
public int second() {
return second;
}
public byte third() {
return third;
}
}
/**
* Immutable, comparable tuple.
*/
@Immutable
final class ImmCompObjIntByteTriple> extends AbstractObjIntByteTriple implements ComparableObjIntByteTriple {
private final T first;
private final int second;
private final byte third;
public ImmCompObjIntByteTriple(T a1, int a2, byte a3) {
this.first = a1;
this.second = a2;
this.third = a3;
}
public static > ImmCompObjIntByteTriple of(T a1, int a2, byte a3) {
return new ImmCompObjIntByteTriple(a1, a2, a3);
}
public static > ImmCompObjIntByteTriple copyOf(LObjIntByteTriple tuple) {
return of(tuple.first(), tuple.second(), tuple.third());
}
public T first() {
return first;
}
public int second() {
return second;
}
public byte third() {
return third;
}
}
}