com.landawn.abacus.util.f Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* Copyright (C) 2017 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.math.RoundingMode;
import com.landawn.abacus.annotation.Beta;
@Beta
public final class f {
private static final String ARRAY_PRINT_SEPERATOR = IOUtil.LINE_SEPARATOR;
static final char CHAR_0 = (char) 0;
static final byte BYTE_0 = (byte) 0;
static final byte BYTE_1 = (byte) 1;
static final short SHORT_0 = (short) 0;
private f() {
// utility class.
}
public static void replaceAlll(final T[] a, final Try.UnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] = operator.apply(a[i]);
}
}
public static void replaceIff(final T[] a, final Try.Predicate super T, E> predicate, final T newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
if (predicate.test(a[i])) {
a[i] = newValue;
}
}
}
public static T[] mapp(final T[] a, final Try.UnaryOperator func) throws E {
if (a == null) {
return null;
}
return map((Class) a.getClass().getComponentType(), a, func);
}
public static R[] map(final Class cls, final T[] a, final Try.Function super T, R, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final R[] c = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
c[i] = func.apply(a[i]);
}
return c;
}
public static boolean[] mapToBoolean(final T[] a, final Try.ToBooleanFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final boolean[] c = new boolean[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsBoolean(a[i]);
}
return c;
}
public static char[] mapToChar(final T[] a, final Try.ToCharFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final char[] c = new char[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsChar(a[i]);
}
return c;
}
public static byte[] mapToByte(final T[] a, final Try.ToByteFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final byte[] c = new byte[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsByte(a[i]);
}
return c;
}
public static short[] mapToShort(final T[] a, final Try.ToShortFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final short[] c = new short[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsShort(a[i]);
}
return c;
}
public static int[] mapToInt(final T[] a, final Try.ToIntFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final int[] c = new int[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsInt(a[i]);
}
return c;
}
public static long[] mapToLong(final T[] a, final Try.ToLongFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final long[] c = new long[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsLong(a[i]);
}
return c;
}
public static float[] mapToFloat(final T[] a, final Try.ToFloatFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final float[] c = new float[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsFloat(a[i]);
}
return c;
}
public static double[] mapToDouble(final T[] a, final Try.ToDoubleFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final double[] c = new double[len];
for (int i = 0; i < len; i++) {
c[i] = func.applyAsDouble(a[i]);
}
return c;
}
public static T[] mapToObj(final Class cls, final boolean[] a, final Try.BooleanFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final boolean[][] a, final Try.BooleanFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final boolean[][][] a, final Try.BooleanFunction extends T, E> mapper)
throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final char[] a, final Try.CharFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final char[][] a, final Try.CharFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final char[][][] a, final Try.CharFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final byte[] a, final Try.ByteFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final byte[][] a, final Try.ByteFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final byte[][][] a, final Try.ByteFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final short[] a, final Try.ShortFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final short[][] a, final Try.ShortFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final short[][][] a, final Try.ShortFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final int[] a, final Try.IntFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final int[][] a, final Try.IntFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final int[][][] a, final Try.IntFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final long[] a, final Try.LongFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final long[][] a, final Try.LongFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final long[][][] a, final Try.LongFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final float[] a, final Try.FloatFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final float[][] a, final Try.FloatFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final float[][][] a, final Try.FloatFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[] mapToObj(final Class cls, final double[] a, final Try.DoubleFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[] result = N.newArray(cls, len);
for (int i = 0; i < len; i++) {
result[i] = mapper.apply(a[i]);
}
return result;
}
public static T[][] mapToObj(final Class cls, final double[][] a, final Try.DoubleFunction extends T, E> mapper) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static T[][][] mapToObj(final Class cls, final double[][][] a, final Try.DoubleFunction extends T, E> mapper)
throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final T[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
result[i] = mapToObj(cls, a[i], mapper);
}
return result;
}
public static A[] zipp(final A[] a, final B[] b, final Try.BiFunction super A, ? super B, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType(), a, b, zipFunction);
}
public static R[] zip(final Class cls, final A[] a, final B[] b,
final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[] result = N.newArray(cls, N.min(lenA, lenB));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
return result;
}
public static A[] zipp(final A[] a, final B[] b, final A valueForNoneA, final B valueForNoneB,
final Try.BiFunction super A, ? super B, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType(), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
public static R[] zip(final Class cls, final A[] a, final B[] b, final A valueForNoneA, final B valueForNoneB,
final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
return zip(N.max(lenA, lenB), cls, a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static R[] zip(final int len, final Class cls, final A[] a, final B[] b, final A valueForNoneA,
final B valueForNoneB, final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[] result = N.newArray(cls, len);
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zipFunction.apply(valueForNoneA, b[i]);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], valueForNoneB);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zipFunction.apply(valueForNoneA, valueForNoneB);
}
}
return result;
}
public static A[] zipp(final A[] a, final B[] b, final C[] c,
final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType(), a, b, c, zipFunction);
}
public static R[] zip(final Class cls, final A[] a, final B[] b, final C[] c,
final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[] result = N.newArray(cls, N.min(lenA, lenB, lenC));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
return result;
}
public static A[] zipp(final A[] a, final B[] b, final C[] c, final A valueForNoneA, final B valueForNoneB,
final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType(), a, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
public static R[] zip(final Class cls, final A[] a, final B[] b, final C[] c, final A valueForNoneA,
final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
return zip(N.max(lenA, lenB, lenC), cls, a, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
private static R[] zip(final int len, final Class cls, final A[] a, final B[] b, final C[] c, final A valueForNoneA,
final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[] result = N.newArray(cls, len);
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zipFunction.apply(i < lenA ? a[i] : valueForNoneA, i < lenB ? b[i] : valueForNoneB, i < lenC ? c[i] : valueForNoneC);
}
}
return result;
}
public static String println(final T[] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
return N.println(N.toString(a));
}
}
public static String println(final T[][] a) {
return ff.println(a);
}
public static String println(final T[][][] a) {
return fff.println(a);
}
public static final class ff {
private ff() {
// Singleton
}
public static void replaceAll(final T[][] a, final Try.UnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
f.replaceAlll(a[i], operator);
}
}
public static void replaceIf(final T[][] a, final Try.Predicate super T, E> predicate, final T newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
f.replaceIff(a[i], predicate, newValue);
}
}
public static T[][] reshape(final T[] a, final int m) {
N.checkArgument(m > 0, "'m' must be positive number: m = %s", m);
// if (N.isNullOrEmpty(a)) {
// return new T[0][0];
// }
final int len = a.length;
final int n = Matth.divide(len, m, RoundingMode.CEILING);
final T[][] c = N.newArray(a.getClass(), n);
for (int i = 0, from = 0; i < n; i++, from += m) {
c[i] = N.copyOfRange(a, from, from + N.min(len - from, m));
}
return c;
}
public static T[] flatten(final T[][] a) {
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
count += (a[i] == null ? 0 : a[i].length);
}
final T[] c = N.newArray(a.getClass().getComponentType().getComponentType(), count);
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
N.copy(a[i], 0, c, from, a[i].length);
from += a[i].length;
}
return c;
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flattOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final T[][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final T[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (T[] e : a) {
if (N.notNullOrEmpty(e)) {
N.copy(tmp, idx, e, 0, e.length);
idx += e.length;
}
}
}
public static T[][] map(final T[][] a, final Try.UnaryOperator func) throws E {
if (a == null) {
return null;
}
return map((Class) a.getClass().getComponentType().getComponentType(), a, func);
}
public static R[][] map(final Class cls, final T[][] a, final Try.Function super T, R, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final R[][] c = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0; i < len; i++) {
c[i] = f.map(cls, a[i], func);
}
return c;
}
public static boolean[][] mapToBoolean(final T[][] a, final Try.ToBooleanFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final boolean[][] c = new boolean[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToBoolean(a[i], func);
}
return c;
}
public static char[][] mapToChar(final T[][] a, final Try.ToCharFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final char[][] c = new char[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToChar(a[i], func);
}
return c;
}
public static byte[][] mapToByte(final T[][] a, final Try.ToByteFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final byte[][] c = new byte[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToByte(a[i], func);
}
return c;
}
public static short[][] mapToShort(final T[][] a, final Try.ToShortFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final short[][] c = new short[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToShort(a[i], func);
}
return c;
}
public static int[][] mapToInt(final T[][] a, final Try.ToIntFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final int[][] c = new int[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToInt(a[i], func);
}
return c;
}
public static long[][] mapToLong(final T[][] a, final Try.ToLongFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final long[][] c = new long[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToLong(a[i], func);
}
return c;
}
public static float[][] mapToFloat(final T[][] a, final Try.ToFloatFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final float[][] c = new float[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToFloat(a[i], func);
}
return c;
}
public static double[][] mapToDouble(final T[][] a, final Try.ToDoubleFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final double[][] c = new double[len][];
for (int i = 0; i < len; i++) {
c[i] = f.mapToDouble(a[i], func);
}
return c;
}
private static R[] zip(final int len, final Class cls, final A[] a, final B[] b, final A valueForNoneA,
final B valueForNoneB, final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[] result = N.newArray(cls, len);
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zipFunction.apply(valueForNoneA, b[i]);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], valueForNoneB);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zipFunction.apply(valueForNoneA, valueForNoneB);
}
}
return result;
}
private static R[] zip(final int len, final Class cls, final A[] a, final B[] b, final C[] c,
final A valueForNoneA, final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[] result = N.newArray(cls, len);
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zipFunction.apply(i < lenA ? a[i] : valueForNoneA, i < lenB ? b[i] : valueForNoneB, i < lenC ? c[i] : valueForNoneC);
}
}
return result;
}
public static A[][] zip(final A[][] a, final B[][] b, final Try.BiFunction super A, ? super B, A, E> zipFunction)
throws E {
return zip((Class) a.getClass().getComponentType().getComponentType(), a, b, zipFunction);
}
public static R[][] zip(final Class cls, final A[][] a, final B[][] b,
final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[][] result = N.newArray(N.newArray(cls, 0).getClass(), N.min(lenA, lenB));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = f.zip(cls, a[i], b[i], zipFunction);
}
return result;
}
public static A[][] zip(final A[][] a, final B[][] b, final A valueForNoneA, final B valueForNoneB,
final Try.BiFunction super A, ? super B, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType(), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
public static R[][] zip(final Class cls, final A[][] a, final B[][] b, final A valueForNoneA, final B valueForNoneB,
final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b)), N.max(maxSubArrayLen(a), maxSubArrayLen(b)), cls, a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static R[][] zip(final int len, final int rowLen, final Class cls, final A[][] a, final B[][] b,
final A valueForNoneA, final B valueForNoneB, final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zip(rowLen, cls, a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zip(rowLen, cls, null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zip(rowLen, cls, a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zip(rowLen, cls, null, null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static A[][] zip(final A[][] a, final B[][] b, final C[][] c,
final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType(), a, b, c, zipFunction);
}
public static R[][] zip(final Class cls, final A[][] a, final B[][] b, final C[][] c,
final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[][] result = N.newArray(N.newArray(cls, 0).getClass(), N.min(lenA, lenB, lenC));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = f.zip(cls, a[i], b[i], c[i], zipFunction);
}
return result;
}
public static A[][] zip(final A[][] a, final B[][] b, final C[][] c, final A valueForNoneA, final B valueForNoneB,
final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType(), a, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
public static R[][] zip(final Class cls, final A[][] a, final B[][] b, final C[][] c, final A valueForNoneA,
final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b), N.len(c)), N.max(maxSubArrayLen(a), maxSubArrayLen(b), maxSubArrayLen(c)), cls, a, b, c, valueForNoneA,
valueForNoneB, valueForNoneC, zipFunction);
}
private static R[][] zip(final int len, final int rowLen, final Class cls, final A[][] a, final B[][] b,
final C[][] c, final A valueForNoneA, final B valueForNoneB, final C valueForNoneC,
final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[][] result = N.newArray(N.newArray(cls, 0).getClass(), len);
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zip(rowLen, cls, a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zip(rowLen, cls, i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB,
valueForNoneC, zipFunction);
}
}
return result;
}
public static int minSubArrayLen(T[][] a) {
if (a == null) {
return 0;
}
final int len = a.length;
int minLen = 0;
for (int i = 0; i < len; i++) {
minLen = N.min(minLen, a[i] == null ? 0 : a[i].length);
}
return minLen;
}
public static int maxSubArrayLen(T[][] a) {
if (a == null) {
return 0;
}
final int len = N.len(a);
int maxLen = 0;
for (int i = 0; i < len; i++) {
maxLen = N.max(maxLen, a[i] == null ? 0 : a[i].length);
}
return maxLen;
}
static String println(final T[][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final T[] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(", ");
}
sb.append(ai[j]);
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
}
public static final class fff {
private fff() {
// Singleton
}
public static void replaceAll(final T[][][] a, final Try.UnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
ff.replaceAll(a[i], operator);
}
}
public static void replaceIf(final T[][][] a, final Try.Predicate super T, E> predicate, final T newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
ff.replaceIf(a[i], predicate, newValue);
}
}
public static T[][][] reshape(final T[] a, final int m, final int l) {
N.checkArgNotNull(a, "a");
N.checkArgument(m > 0 && l > 0, "'m' and 'l' must be positive number: m = %s, l = %s", m, l);
// if (N.isNullOrEmpty(a)) {
// return new T[0][0][0];
// }
final int len = a.length;
final int n = Matth.divide(len, m * l, RoundingMode.CEILING);
final T[][][] c = N.newArray(N.newArray(a.getClass(), 0).getClass(), n);
for (int i = 0, from = 0; i < n; i++) {
c[i] = N.newArray(a.getClass(), N.min(m, Matth.divide(len - from, l, RoundingMode.CEILING)));
for (int j = 0, y = c[i].length; j < y; j++, from += l) {
c[i][j] = N.copyOfRange(a, from, from + N.min(len - from, l));
}
}
return c;
}
public static T[] flatten(final T[][][] a) {
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
count += (a[i][j] == null ? 0 : a[i][j].length);
}
}
final T[] c = N.newArray(a.getClass().getComponentType().getComponentType().getComponentType(), count);
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
N.copy(a[i][j], 0, c, from, a[i][j].length);
from += a[i][j].length;
}
}
return c;
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flattOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final T[][][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final T[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (T[][] e : a) {
if (N.notNullOrEmpty(e)) {
for (T[] ee : e) {
if (N.notNullOrEmpty(ee)) {
N.copy(tmp, idx, ee, 0, ee.length);
idx += ee.length;
}
}
}
}
}
public static T[][][] map(final T[][][] a, final Try.UnaryOperator func) throws E {
if (a == null) {
return null;
}
return map((Class) a.getClass().getComponentType().getComponentType().getComponentType(), a, func);
}
public static R[][][] map(final Class cls, final T[][][] a, final Try.Function super T, R, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final R[][][] c = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), len);
for (int i = 0; i < len; i++) {
c[i] = ff.map(cls, a[i], func);
}
return c;
}
public static boolean[][][] mapToBoolean(final T[][][] a, final Try.ToBooleanFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final boolean[][][] c = new boolean[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToBoolean(a[i], func);
}
return c;
}
public static char[][][] mapToChar(final T[][][] a, final Try.ToCharFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final char[][][] c = new char[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToChar(a[i], func);
}
return c;
}
public static byte[][][] mapToByte(final T[][][] a, final Try.ToByteFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final byte[][][] c = new byte[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToByte(a[i], func);
}
return c;
}
public static short[][][] mapToShort(final T[][][] a, final Try.ToShortFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final short[][][] c = new short[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToShort(a[i], func);
}
return c;
}
public static int[][][] mapToInt(final T[][][] a, final Try.ToIntFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final int[][][] c = new int[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToInt(a[i], func);
}
return c;
}
public static long[][][] mapToLong(final T[][][] a, final Try.ToLongFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final long[][][] c = new long[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToLong(a[i], func);
}
return c;
}
public static float[][][] mapToFloat(final T[][][] a, final Try.ToFloatFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final float[][][] c = new float[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToFloat(a[i], func);
}
return c;
}
public static double[][][] mapToDouble(final T[][][] a, final Try.ToDoubleFunction super T, E> func) throws E {
if (a == null) {
return null;
}
final int len = N.len(a);
final double[][][] c = new double[len][][];
for (int i = 0; i < len; i++) {
c[i] = ff.mapToDouble(a[i], func);
}
return c;
}
public static A[][][] zip(final A[][][] a, final B[][][] b, final Try.BiFunction super A, ? super B, A, E> zipFunction)
throws E {
return zip((Class) a.getClass().getComponentType().getComponentType().getComponentType(), a, b, zipFunction);
}
public static R[][][] zip(final Class cls, final A[][][] a, final B[][][] b,
final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), N.min(lenA, lenB));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = ff.zip(cls, a[i], b[i], zipFunction);
}
return result;
}
public static A[][][] zip(final A[][][] a, final B[][][] b, final A valueForNoneA, final B valueForNoneB,
final Try.BiFunction super A, ? super B, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType().getComponentType(), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
public static R[][][] zip(final Class cls, final A[][][] a, final B[][][] b, final A valueForNoneA,
final B valueForNoneB, final Try.BiFunction super A, ? super B, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final R[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), N.max(lenA, lenB));
for (int i = 0, min = N.min(lenA, lenB); i < min; i++) {
result[i] = ff.zip(cls, a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB) {
for (int i = lenA; i < lenB; i++) {
result[i] = ff.zip(cls, null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA) {
for (int i = lenB; i < lenA; i++) {
result[i] = ff.zip(cls, a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static A[][][] zip(final A[][][] a, final B[][][] b, final C[][][] c,
final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType().getComponentType(), a, b, c, zipFunction);
}
public static R[][][] zip(final Class cls, final A[][][] a, final B[][][] b, final C[][][] c,
final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), N.min(lenA, lenB, lenC));
for (int i = 0, len = result.length; i < len; i++) {
result[i] = ff.zip(cls, a[i], b[i], c[i], zipFunction);
}
return result;
}
public static A[][][] zip(final A[][][] a, final B[][][] b, final C[][][] c, final A valueForNoneA,
final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, A, E> zipFunction) throws E {
return zip((Class) a.getClass().getComponentType().getComponentType().getComponentType(), a, b, c, valueForNoneA, valueForNoneB, valueForNoneC,
zipFunction);
}
public static R[][][] zip(final Class cls, final A[][][] a, final B[][][] b, final C[][][] c,
final A valueForNoneA, final B valueForNoneB, final C valueForNoneC, final Try.TriFunction super A, ? super B, ? super C, R, E> zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final R[][][] result = N.newArray(N.newArray(N.newArray(cls, 0).getClass(), 0).getClass(), N.max(lenA, lenB, lenC));
for (int i = 0, min = N.min(lenA, lenB, lenC); i < min; i++) {
result[i] = ff.zip(cls, a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
for (int i = N.min(lenA, lenB, lenC), len = result.length; i < len; i++) {
result[i] = ff.zip(cls, i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB, valueForNoneC,
zipFunction);
}
return result;
}
static String println(final T[][][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(ARRAY_PRINT_SEPERATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final T[][] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(" ");
}
if (ai[j] == null) {
sb.append("null");
} else if (ai[j].length == 0) {
sb.append("[]");
} else {
final T[] aij = ai[j];
sb.append('[');
for (int k = 0, aijLen = aij.length; k < aijLen; k++) {
if (k > 0) {
sb.append(", ");
}
sb.append(aij[k]);
}
sb.append(']');
}
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
}
public static void replaceAll(final boolean[] a, final Try.BooleanUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] = operator.applyAsBoolean(a[i]);
}
}
public static void replaceAll(final boolean[][] a, final Try.BooleanUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceAll(final boolean[][][] a, final Try.BooleanUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceIf(final boolean[] a, final Try.BooleanPredicate predicate, final boolean newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
if (predicate.test(a[i])) {
a[i] = newValue;
}
}
}
public static void replaceIf(final boolean[][] a, final Try.BooleanPredicate predicate, final boolean newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceIf(a[i], predicate, newValue);
}
}
public static void replaceIf(final boolean[][][] a, final Try.BooleanPredicate predicate, final boolean newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceIf(a[i], predicate, newValue);
}
}
public static boolean[][] reshape(final boolean[] a, final int m) {
N.checkArgument(m > 0, "'m' must be positive number: m = %s", m);
if (N.isNullOrEmpty(a)) {
return new boolean[0][0];
}
final int len = a.length;
final int n = Matth.divide(len, m, RoundingMode.CEILING);
final boolean[][] c = new boolean[n][];
for (int i = 0, from = 0; i < n; i++, from += m) {
c[i] = N.copyOfRange(a, from, from + N.min(len - from, m));
}
return c;
}
public static boolean[][][] reshape(final boolean[] a, final int m, final int l) {
N.checkArgument(m > 0 && l > 0, "'m' and 'l' must be positive number: m = %s, l = %s", m, l);
if (N.isNullOrEmpty(a)) {
return new boolean[0][0][0];
}
final int len = a.length;
final int n = Matth.divide(len, m * l, RoundingMode.CEILING);
final boolean[][][] c = new boolean[n][][];
for (int i = 0, from = 0; i < n; i++) {
c[i] = new boolean[N.min(m, Matth.divide(len - from, l, RoundingMode.CEILING))][];
for (int j = 0, y = c[i].length; j < y; j++, from += l) {
c[i][j] = N.copyOfRange(a, from, from + N.min(len - from, l));
}
}
return c;
}
public static boolean[] flatten(final boolean[][] a) {
if (N.isNullOrEmpty(a)) {
return N.EMPTY_BOOLEAN_ARRAY;
}
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
count += (a[i] == null ? 0 : a[i].length);
}
final boolean[] c = new boolean[count];
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
N.copy(a[i], 0, c, from, a[i].length);
from += a[i].length;
}
return c;
}
public static boolean[] flatten(final boolean[][][] a) {
if (N.isNullOrEmpty(a)) {
return N.EMPTY_BOOLEAN_ARRAY;
}
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
count += (a[i][j] == null ? 0 : a[i][j].length);
}
}
final boolean[] c = new boolean[count];
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
N.copy(a[i][j], 0, c, from, a[i][j].length);
from += a[i][j].length;
}
}
return c;
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flatOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final boolean[][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final boolean[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (boolean[] e : a) {
if (N.notNullOrEmpty(e)) {
N.copy(tmp, idx, e, 0, e.length);
idx += e.length;
}
}
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flatOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final boolean[][][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final boolean[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (boolean[][] e : a) {
if (N.notNullOrEmpty(e)) {
for (boolean[] ee : e) {
if (N.notNullOrEmpty(ee)) {
N.copy(tmp, idx, ee, 0, ee.length);
idx += ee.length;
}
}
}
}
}
public static boolean[] zip(final boolean[] a, final boolean[] b, final Try.BooleanBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[] result = new boolean[N.min(lenA, lenB)];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
return result;
}
public static boolean[] zip(final boolean[] a, final boolean[] b, final boolean valueForNoneA, final boolean valueForNoneB,
final Try.BooleanBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
return zip(N.max(lenA, lenB), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static boolean[] zip(final int len, final boolean[] a, final boolean[] b, final boolean valueForNoneA,
final boolean valueForNoneB, final Try.BooleanBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[] result = new boolean[len];
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zipFunction.apply(valueForNoneA, b[i]);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], valueForNoneB);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zipFunction.apply(valueForNoneA, valueForNoneB);
}
}
return result;
}
public static boolean[] zip(final boolean[] a, final boolean[] b, final boolean[] c,
final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[] result = new boolean[N.min(lenA, lenB, lenC)];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
return result;
}
public static boolean[] zip(final boolean[] a, final boolean[] b, final boolean[] c, final boolean valueForNoneA,
final boolean valueForNoneB, final boolean valueForNoneC, final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
return zip(N.max(lenA, lenB, lenC), a, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
private static boolean[] zip(final int len, final boolean[] a, final boolean[] b, final boolean[] c, final boolean valueForNoneA,
final boolean valueForNoneB, final boolean valueForNoneC, final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[] result = new boolean[len];
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zipFunction.apply(i < lenA ? a[i] : valueForNoneA, i < lenB ? b[i] : valueForNoneB, i < lenC ? c[i] : valueForNoneC);
}
}
return result;
}
public static boolean[][] zip(final boolean[][] a, final boolean[][] b, final Try.BooleanBiFunction zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[][] result = new boolean[N.min(lenA, lenB)][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], zipFunction);
}
return result;
}
public static boolean[][] zip(final boolean[][] a, final boolean[][] b, final boolean valueForNoneA, final boolean valueForNoneB,
final Try.BooleanBiFunction zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b)), N.max(maxSubArrayLen(a), maxSubArrayLen(b)), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static boolean[][] zip(final int len, final int rowLen, final boolean[][] a, final boolean[][] b, final boolean valueForNoneA,
final boolean valueForNoneB, final Try.BooleanBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[][] result = new boolean[len][];
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zip(rowLen, a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zip(rowLen, null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zip(rowLen, a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zip(rowLen, null, null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static boolean[][] zip(final boolean[][] a, final boolean[][] b, final boolean[][] c,
final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[][] result = new boolean[N.min(lenA, lenB, lenC)][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], c[i], zipFunction);
}
return result;
}
public static boolean[][] zip(final boolean[][] a, final boolean[][] b, final boolean[][] c, final boolean valueForNoneA,
final boolean valueForNoneB, final boolean valueForNoneC, final Try.BooleanTriFunction zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b), N.len(c)), N.max(maxSubArrayLen(a), maxSubArrayLen(b), maxSubArrayLen(c)), a, b, c, valueForNoneA, valueForNoneB,
valueForNoneC, zipFunction);
}
private static boolean[][] zip(final int len, final int rowLen, final boolean[][] a, final boolean[][] b, final boolean[][] c,
final boolean valueForNoneA, final boolean valueForNoneB, final boolean valueForNoneC, final Try.BooleanTriFunction zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[][] result = new boolean[len][];
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zip(rowLen, a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zip(rowLen, i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB, valueForNoneC,
zipFunction);
}
}
return result;
}
public static boolean[][][] zip(final boolean[][][] a, final boolean[][][] b, final Try.BooleanBiFunction zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[][][] result = new boolean[N.min(lenA, lenB)][][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], zipFunction);
}
return result;
}
public static boolean[][][] zip(final boolean[][][] a, final boolean[][][] b, final boolean valueForNoneA,
final boolean valueForNoneB, final Try.BooleanBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final boolean[][][] result = new boolean[N.max(lenA, lenB)][][];
for (int i = 0, min = N.min(lenA, lenB); i < min; i++) {
result[i] = zip(a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB) {
for (int i = lenA; i < lenB; i++) {
result[i] = zip(null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA) {
for (int i = lenB; i < lenA; i++) {
result[i] = zip(a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static boolean[][][] zip(final boolean[][][] a, final boolean[][][] b, final boolean[][][] c,
final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[][][] result = new boolean[N.min(lenA, lenB, lenC)][][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], c[i], zipFunction);
}
return result;
}
public static boolean[][][] zip(final boolean[][][] a, final boolean[][][] b, final boolean[][][] c, final boolean valueForNoneA,
final boolean valueForNoneB, final boolean valueForNoneC, final Try.BooleanTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final boolean[][][] result = new boolean[N.max(lenA, lenB, lenC)][][];
for (int i = 0, min = N.min(lenA, lenB, lenC); i < min; i++) {
result[i] = zip(a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
for (int i = N.min(lenA, lenB, lenC), len = result.length; i < len; i++) {
result[i] = zip(i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
return result;
}
public static String println(final boolean[] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
return N.println(N.toString(a));
}
}
public static String println(final boolean[][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final boolean[] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(", ");
}
sb.append(ai[j]);
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
public static String println(final boolean[][][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(ARRAY_PRINT_SEPERATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final boolean[][] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(" ");
}
if (ai[j] == null) {
sb.append("null");
} else if (ai[j].length == 0) {
sb.append("[]");
} else {
final boolean[] aij = ai[j];
sb.append('[');
for (int k = 0, aijLen = aij.length; k < aijLen; k++) {
if (k > 0) {
sb.append(", ");
}
sb.append(aij[k]);
}
sb.append(']');
}
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
public static int minSubArrayLen(boolean[][] a) {
if (a == null) {
return 0;
}
final int len = a.length;
int minLen = 0;
for (int i = 0; i < len; i++) {
minLen = N.min(minLen, a[i] == null ? 0 : a[i].length);
}
return minLen;
}
public static int maxSubArrayLen(boolean[][] a) {
if (a == null) {
return 0;
}
final int len = a.length;
int maxLen = 0;
for (int i = 0; i < len; i++) {
maxLen = N.max(maxLen, a[i] == null ? 0 : a[i].length);
}
return maxLen;
}
public static void plus(final char[] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] += param;
}
}
public static void plus(final char[][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
plus(a[i], param);
}
}
public static void plus(final char[][][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
plus(a[i], param);
}
}
public static void minus(final char[] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] -= param;
}
}
public static void minus(final char[][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
minus(a[i], param);
}
}
public static void minus(final char[][][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
minus(a[i], param);
}
}
public static void multipliedBy(final char[] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] *= param;
}
}
public static void multipliedBy(final char[][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
multipliedBy(a[i], param);
}
}
public static void multipliedBy(final char[][][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
multipliedBy(a[i], param);
}
}
public static void dividedBy(final char[] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] /= param;
}
}
public static void dividedBy(final char[][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
dividedBy(a[i], param);
}
}
public static void dividedBy(final char[][][] a, final int param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
dividedBy(a[i], param);
}
}
public static void replaceAll(final char[] a, final Try.CharUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] = operator.applyAsChar(a[i]);
}
}
public static void replaceAll(final char[][] a, final Try.CharUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceAll(final char[][][] a, final Try.CharUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceIf(final char[] a, final Try.CharPredicate predicate, final char newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
if (predicate.test(a[i])) {
a[i] = newValue;
}
}
}
public static void replaceIf(final char[][] a, final Try.CharPredicate predicate, final char newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceIf(a[i], predicate, newValue);
}
}
public static void replaceIf(final char[][][] a, final Try.CharPredicate predicate, final char newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceIf(a[i], predicate, newValue);
}
}
public static char[][] reshape(final char[] a, final int m) {
N.checkArgument(m > 0, "'m' must be positive number: m = %s", m);
if (N.isNullOrEmpty(a)) {
return new char[0][0];
}
final int len = a.length;
final int n = Matth.divide(len, m, RoundingMode.CEILING);
final char[][] c = new char[n][];
for (int i = 0, from = 0; i < n; i++, from += m) {
c[i] = N.copyOfRange(a, from, from + N.min(len - from, m));
}
return c;
}
public static char[][][] reshape(final char[] a, final int m, final int l) {
N.checkArgument(m > 0 && l > 0, "'m' and 'l' must be positive number: m = %s, l = %s", m, l);
if (N.isNullOrEmpty(a)) {
return new char[0][0][0];
}
final int len = a.length;
final int n = Matth.divide(len, m * l, RoundingMode.CEILING);
final char[][][] c = new char[n][][];
for (int i = 0, from = 0; i < n; i++) {
c[i] = new char[N.min(m, Matth.divide(len - from, l, RoundingMode.CEILING))][];
for (int j = 0, y = c[i].length; j < y; j++, from += l) {
c[i][j] = N.copyOfRange(a, from, from + N.min(len - from, l));
}
}
return c;
}
public static char[] flatten(final char[][] a) {
if (N.isNullOrEmpty(a)) {
return N.EMPTY_CHAR_ARRAY;
}
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
count += (a[i] == null ? 0 : a[i].length);
}
final char[] c = new char[count];
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
N.copy(a[i], 0, c, from, a[i].length);
from += a[i].length;
}
return c;
}
public static char[] flatten(final char[][][] a) {
if (N.isNullOrEmpty(a)) {
return N.EMPTY_CHAR_ARRAY;
}
int count = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
count += (a[i][j] == null ? 0 : a[i][j].length);
}
}
final char[] c = new char[count];
int from = 0;
for (int i = 0, n = a.length; i < n; i++) {
if (N.isNullOrEmpty(a[i])) {
continue;
}
for (int j = 0, m = a[i].length; j < m; j++) {
if (N.isNullOrEmpty(a[i][j])) {
continue;
}
N.copy(a[i][j], 0, c, from, a[i][j].length);
from += a[i][j].length;
}
}
return c;
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flatOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final char[][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final char[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (char[] e : a) {
if (N.notNullOrEmpty(e)) {
N.copy(tmp, idx, e, 0, e.length);
idx += e.length;
}
}
}
/**
* flatten -> execute {@code op} -> set values back.
*
*
* f.flatOp(a, t -> N.sort(t));
*
*
*
* @param a
* @param op
* @throws E
*/
public static void flatOp(final char[][][] a, Try.Consumer op) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
final char[] tmp = flatten(a);
op.accept(tmp);
int idx = 0;
for (char[][] e : a) {
if (N.notNullOrEmpty(e)) {
for (char[] ee : e) {
if (N.notNullOrEmpty(ee)) {
N.copy(tmp, idx, ee, 0, ee.length);
idx += ee.length;
}
}
}
}
}
public static char[] zip(final char[] a, final char[] b, final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[] result = new char[N.min(lenA, lenB)];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
return result;
}
public static char[] zip(final char[] a, final char[] b, final char valueForNoneA, final char valueForNoneB,
final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
return zip(N.max(lenA, lenB), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static char[] zip(final int len, final char[] a, final char[] b, final char valueForNoneA, final char valueForNoneB,
final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[] result = new char[len];
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i]);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zipFunction.apply(valueForNoneA, b[i]);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], valueForNoneB);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zipFunction.apply(valueForNoneA, valueForNoneB);
}
}
return result;
}
public static char[] zip(final char[] a, final char[] b, final char[] c, final Try.CharTriFunction zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[] result = new char[N.min(lenA, lenB, lenC)];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
return result;
}
public static char[] zip(final char[] a, final char[] b, final char[] c, final char valueForNoneA, final char valueForNoneB,
final char valueForNoneC, final Try.CharTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
return zip(N.max(lenA, lenB, lenC), a, b, c, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
private static char[] zip(final int len, final char[] a, final char[] b, final char[] c, final char valueForNoneA,
final char valueForNoneB, final char valueForNoneC, final Try.CharTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[] result = new char[len];
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zipFunction.apply(a[i], b[i], c[i]);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zipFunction.apply(i < lenA ? a[i] : valueForNoneA, i < lenB ? b[i] : valueForNoneB, i < lenC ? c[i] : valueForNoneC);
}
}
return result;
}
public static char[][] zip(final char[][] a, final char[][] b, final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[][] result = new char[N.min(lenA, lenB)][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], zipFunction);
}
return result;
}
public static char[][] zip(final char[][] a, final char[][] b, final char valueForNoneA, final char valueForNoneB,
final Try.CharBiFunction zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b)), N.max(maxSubArrayLen(a), maxSubArrayLen(b)), a, b, valueForNoneA, valueForNoneB, zipFunction);
}
private static char[][] zip(final int len, final int rowLen, final char[][] a, final char[][] b, final char valueForNoneA,
final char valueForNoneB, final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[][] result = new char[len][];
for (int i = 0, min = N.min(lenA, lenB, len); i < min; i++) {
result[i] = zip(rowLen, a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB && lenA < len) {
for (int i = lenA, min = N.min(lenB, len); i < min; i++) {
result[i] = zip(rowLen, null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA && lenB < len) {
for (int i = lenB, min = N.min(lenA, len); i < min; i++) {
result[i] = zip(rowLen, a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
if (N.max(lenA, lenB) < len) {
for (int i = N.max(lenA, lenB); i < len; i++) {
result[i] = zip(rowLen, null, null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static char[][] zip(final char[][] a, final char[][] b, final char[][] c, final Try.CharTriFunction zipFunction)
throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[][] result = new char[N.min(lenA, lenB, lenC)][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], c[i], zipFunction);
}
return result;
}
public static char[][] zip(final char[][] a, final char[][] b, final char[][] c, final char valueForNoneA, final char valueForNoneB,
final char valueForNoneC, final Try.CharTriFunction zipFunction) throws E {
return zip(N.max(N.len(a), N.len(b), N.len(c)), N.max(maxSubArrayLen(a), maxSubArrayLen(b), maxSubArrayLen(c)), a, b, c, valueForNoneA, valueForNoneB,
valueForNoneC, zipFunction);
}
private static char[][] zip(final int len, final int rowLen, final char[][] a, final char[][] b, final char[][] c,
final char valueForNoneA, final char valueForNoneB, final char valueForNoneC, final Try.CharTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[][] result = new char[len][];
for (int i = 0, min = N.min(lenA, lenB, lenC, len); i < min; i++) {
result[i] = zip(rowLen, a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
if (N.min(lenA, lenB, lenC) < len) {
for (int i = N.min(lenA, lenB, lenC); i < len; i++) {
result[i] = zip(rowLen, i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB, valueForNoneC,
zipFunction);
}
}
return result;
}
public static char[][][] zip(final char[][][] a, final char[][][] b, final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[][][] result = new char[N.min(lenA, lenB)][][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], zipFunction);
}
return result;
}
public static char[][][] zip(final char[][][] a, final char[][][] b, final char valueForNoneA, final char valueForNoneB,
final Try.CharBiFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final char[][][] result = new char[N.max(lenA, lenB)][][];
for (int i = 0, min = N.min(lenA, lenB); i < min; i++) {
result[i] = zip(a[i], b[i], valueForNoneA, valueForNoneB, zipFunction);
}
if (lenA < lenB) {
for (int i = lenA; i < lenB; i++) {
result[i] = zip(null, b[i], valueForNoneA, valueForNoneB, zipFunction);
}
} else if (lenB < lenA) {
for (int i = lenB; i < lenA; i++) {
result[i] = zip(a[i], null, valueForNoneA, valueForNoneB, zipFunction);
}
}
return result;
}
public static char[][][] zip(final char[][][] a, final char[][][] b, final char[][][] c,
final Try.CharTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[][][] result = new char[N.min(lenA, lenB, lenC)][][];
for (int i = 0, len = result.length; i < len; i++) {
result[i] = zip(a[i], b[i], c[i], zipFunction);
}
return result;
}
public static char[][][] zip(final char[][][] a, final char[][][] b, final char[][][] c, final char valueForNoneA,
final char valueForNoneB, final char valueForNoneC, final Try.CharTriFunction zipFunction) throws E {
final int lenA = N.len(a);
final int lenB = N.len(b);
final int lenC = N.len(c);
final char[][][] result = new char[N.max(lenA, lenB, lenC)][][];
for (int i = 0, min = N.min(lenA, lenB, lenC); i < min; i++) {
result[i] = zip(a[i], b[i], c[i], valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
for (int i = N.min(lenA, lenB, lenC), len = result.length; i < len; i++) {
result[i] = zip(i < lenA ? a[i] : null, i < lenB ? b[i] : null, i < lenC ? c[i] : null, valueForNoneA, valueForNoneB, valueForNoneC, zipFunction);
}
return result;
}
public static String println(final char[] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
return N.println(N.toString(a));
}
}
public static String println(final char[][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final char[] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(", ");
}
sb.append(ai[j]);
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
public static String println(final char[][][] a) {
if (a == null) {
return N.println("null");
} else if (a.length == 0) {
return N.println("[]");
} else {
final int len = a.length;
final StringBuilder sb = Objectory.createStringBuilder();
String str = null;
try {
sb.append('[');
for (int i = 0; i < len; i++) {
if (i > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(ARRAY_PRINT_SEPERATOR).append(' ');
}
if (a[i] == null) {
sb.append("null");
} else if (a[i].length == 0) {
sb.append("[]");
} else {
final char[][] ai = a[i];
sb.append('[');
for (int j = 0, aiLen = ai.length; j < aiLen; j++) {
if (j > 0) {
sb.append(',').append(IOUtil.LINE_SEPARATOR).append(" ");
}
if (ai[j] == null) {
sb.append("null");
} else if (ai[j].length == 0) {
sb.append("[]");
} else {
final char[] aij = ai[j];
sb.append('[');
for (int k = 0, aijLen = aij.length; k < aijLen; k++) {
if (k > 0) {
sb.append(", ");
}
sb.append(aij[k]);
}
sb.append(']');
}
}
sb.append(']');
}
}
sb.append(']');
str = sb.toString();
} finally {
Objectory.recycle(sb);
}
N.println(str);
return str;
}
}
public static int minSubArrayLen(char[][] a) {
if (a == null) {
return 0;
}
final int len = a.length;
int minLen = 0;
for (int i = 0; i < len; i++) {
minLen = N.min(minLen, a[i] == null ? 0 : a[i].length);
}
return minLen;
}
public static int maxSubArrayLen(char[][] a) {
if (a == null) {
return 0;
}
final int len = a.length;
int maxLen = 0;
for (int i = 0; i < len; i++) {
maxLen = N.max(maxLen, a[i] == null ? 0 : a[i].length);
}
return maxLen;
}
public static void plus(final byte[] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] += param;
}
}
public static void plus(final byte[][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
plus(a[i], param);
}
}
public static void plus(final byte[][][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
plus(a[i], param);
}
}
public static void minus(final byte[] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] -= param;
}
}
public static void minus(final byte[][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
minus(a[i], param);
}
}
public static void minus(final byte[][][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
minus(a[i], param);
}
}
public static void multipliedBy(final byte[] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] *= param;
}
}
public static void multipliedBy(final byte[][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
multipliedBy(a[i], param);
}
}
public static void multipliedBy(final byte[][][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
multipliedBy(a[i], param);
}
}
public static void dividedBy(final byte[] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] /= param;
}
}
public static void dividedBy(final byte[][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
dividedBy(a[i], param);
}
}
public static void dividedBy(final byte[][][] a, final byte param) {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
dividedBy(a[i], param);
}
}
public static void replaceAll(final byte[] a, final Try.ByteUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
a[i] = operator.applyAsByte(a[i]);
}
}
public static void replaceAll(final byte[][] a, final Try.ByteUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceAll(final byte[][][] a, final Try.ByteUnaryOperator operator) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
replaceAll(a[i], operator);
}
}
public static void replaceIf(final byte[] a, final Try.BytePredicate predicate, final byte newValue) throws E {
if (N.isNullOrEmpty(a)) {
return;
}
for (int i = 0, n = a.length; i < n; i++) {
if (predicate.test(a[i])) {
a[i] = newValue;
}
}
}
public static