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.
package org.xcsp.modeler.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.xcsp.common.FunctionalInterfaces.Intx1Predicate;
import org.xcsp.common.FunctionalInterfaces.Intx2Predicate;
import org.xcsp.common.FunctionalInterfaces.Intx3Predicate;
import org.xcsp.common.Range;
import org.xcsp.common.Range.Rangesx2;
import org.xcsp.common.Utilities;
import org.xcsp.common.enumerations.EnumerationCartesian;
import org.xcsp.common.enumerations.EnumerationOfCombinations;
import org.xcsp.common.enumerations.EnumerationOfPermutations;
public interface ProblemAPIOnVals extends ProblemAPIBase {
// ************************************************************************
// ***** Methods valuesIn() and valuesFrom()
// ************************************************************************
/**
* Builds and returns a 1-dimensional array of integers from the specified sequence of parameters. Each element of the sequence can be an
* {@code Integer}, a {@code Range}, an array (of any dimension), a Stream (or IntStream), a collection, etc. All integers are collected and
* concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param objects
* a sequence of objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] vals(Object... objects) {
return Utilities.collectInt(objects);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified sequence of parameters. Each element of the sequence can be an
* {@code Integer}, a {@code Range}, an array (of any dimension), a Stream (or IntStream), a collection, etc. All integers are collected and
* concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param object
* an object
* @param otherObjects
* a sequence of objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesIn(Object object, Object... otherObjects) {
return vals(object, otherObjects);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified stream. Each object of the stream is mapped to another object by the
* specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param stream
* a stream of objects
* @param f
* a function mapping objects of the stream into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(Stream stream, Function f) {
return valuesIn(stream.filter(o -> o != null).map(o -> f.apply(o)));
}
/**
* Builds and returns a 1-dimensional array of integers from the specified stream. Each integer of the stream is mapped to another object by the
* specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param stream
* a stream of integers
* @param f
* a function mapping integers of the stream into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(IntStream stream, Function f) {
return valuesFrom(stream.boxed(), f);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified array. Each object of the array is mapped to another object by the
* specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param t
* a 1-dimensional array of objects
* @param f
* a function mapping objects of the array into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(T[] t, Function f) {
return valuesFrom(Stream.of(t), f);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified collection. Each object of the collection is mapped to another object
* by the specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param c
* a collection of objects
* @param f
* a function mapping objects of the collection into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(Collection c, Function f) {
return valuesFrom(c.stream(), f);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified array. Each integer of the array is mapped to another object by the
* specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param t
* a 1-dimensional array of integers
* @param f
* a function mapping integers of the array into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(int[] t, Function f) {
return valuesFrom(IntStream.of(t).boxed(), f);
}
default int[] valuesFrom(char[] t, Function f) {
return valuesIn(IntStream.range(0, t.length).mapToObj(i -> f.apply(t[i])));
}
/**
* Builds and returns a 1-dimensional array of integers from the specified range. Each integer of the range is mapped to another object by the
* specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param r
* a range
* @param f
* a function mapping integers of the range into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(Range r, Function f) {
return valuesFrom(r.stream(), f);
}
/**
* Builds and returns a 1-dimensional array of integers from the specified double range. Each pair of integers of the double range is mapped to
* another object by the specified function. Then, all integers are collected and concatenated to form a 1-dimensional array. {@code null} values
* are discarded.
*
* @param r2
* a double range
* @param f
* a function mapping pairs of integers of the double range into other objects
* @return a 1-dimensional array formed of collected integers (occurrences of {@code null} being discarded}
*/
default int[] valuesFrom(Rangesx2 r2, BiFunction f) {
List