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.
/*
* Copyright (c) 2015, Haiyang Li.
*
* 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 com.landawn.abacus.util;
import java.util.Collection;
import java.util.Iterator;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.DoubleConsumer;
import com.landawn.abacus.util.function.FloatConsumer;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.IntConsumer;
import com.landawn.abacus.util.function.LongConsumer;
import com.landawn.abacus.util.function.TriConsumer;
import com.landawn.abacus.util.function.TriFunction;
import com.landawn.abacus.util.stream.Stream;
/**
*
* @since 0.8
*
* @author Haiyang Li
*
* @param
* @param
* @param
*/
public final class Triple {
public volatile L left;
public volatile M middle;
public volatile R right;
public Triple() {
}
Triple(final L l, final M m, final R r) {
this.left = l;
this.middle = m;
this.right = r;
}
public static Triple of(final L l, final M m, final R r) {
return new Triple<>(l, m, r);
}
public static Triple from(T[] a) {
if (N.isNullOrEmpty(a)) {
return new Triple<>(null, null, null);
} else if (a.length == 1) {
return new Triple<>(a[0], null, null);
} else if (a.length == 2) {
return new Triple<>(a[0], a[1], null);
} else {
return new Triple<>(a[0], a[1], a[2]);
}
}
public static Triple from(Collection extends T> c) {
if (N.isNullOrEmpty(c)) {
return new Triple<>(null, null, null);
} else if (c.size() == 1) {
return new Triple(c.iterator().next(), null, null);
} else if (c.size() == 2) {
final Iterator extends T> iter = c.iterator();
return new Triple(iter.next(), iter.next(), null);
} else {
final Iterator extends T> iter = c.iterator();
return new Triple(iter.next(), iter.next(), iter.next());
}
}
public L left() {
return left;
}
public M middle() {
return middle;
}
public R right() {
return right;
}
public L getLeft() {
return left;
}
public Triple setLeft(final L left) {
this.left = left;
return this;
}
public M getMiddle() {
return middle;
}
public Triple setMiddle(final M middle) {
this.middle = middle;
return this;
}
public R getRight() {
return right;
}
public Triple setRight(final R right) {
this.right = right;
return this;
}
public Triple set(final L left, final M middle, final R right) {
this.left = left;
this.middle = middle;
this.right = right;
return this;
}
// /**
// * Swap the left and right value. they must be same type.
// */
// public void reverse() {
// Object tmp = left;
// this.left = (L) right;
// this.right = (R) tmp;
// }
/**
*
* @return a new instance of Triple<R, M, L>.
*/
public Triple reversed() {
return new Triple<>(this.right, this.middle, this.left);
}
public Triple copy() {
return new Triple<>(this.left, this.middle, this.right);
}
public Object[] toArray() {
return new Object[] { left, middle, right };
}
public A[] toArray(A[] a) {
if (a.length < 3) {
a = N.copyOf(a, 3);
}
a[0] = (A) left;
a[1] = (A) middle;
a[2] = (A) right;
return a;
}
public void forEach(Consumer> comsumer) {
final Consumer