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.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
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.FunctionalInterfaces.Intx4Predicate;
import org.xcsp.common.FunctionalInterfaces.Intx5Predicate;
import org.xcsp.common.IVar;
import org.xcsp.common.Range;
import org.xcsp.common.Range.Rangesx2;
import org.xcsp.common.Range.Rangesx3;
import org.xcsp.common.Range.Rangesx4;
import org.xcsp.common.Range.Rangesx5;
import org.xcsp.common.Utilities;
public interface ProblemAPIOnVars extends ProblemAPIBase {
// ************************************************************************
// ***** Methods vars()
// ************************************************************************
// COMMENT : I was unable to keep only one generic method
// because it makes calls ambiguous due to type erasure (the bounded return type is not sufficient)
/**
* Builds and returns a 1-dimensional array of variables from the specified sequence of parameters. All variables encountered in the parameters,
* extracting them from arrays (of any dimension), collections and streams, are recursively collected in order, and concatenated to form a
* 1-dimensional array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param first
* a first object that may involve one or several variables (possibly in arrays, collections and streams)
* @param others
* other objects that may involve one or several variables (possibly in arrays, collections and streams)
* @return a 1-dimensional array of variables
*/
default T[] vars(Object first, Object... others) {
return imp().vars(IntStream.range(0, others.length + 1).mapToObj(i -> i == 0 ? first : others[i - 1]));
}
/**
* Returns a 1-dimensional array containing the specified variables.
*
* @param x
* a first variable
* @param others
* a sequence of other variables
* @return a 1-dimensional array containing the specified variables
*/
default T[] vars(T x, T... others) {
return vars((Object) x, others);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified array. All variables are collected in order, and {@code null} values
* are simply discarded.
*
* @param vars
* a 2-dimensional array of variables
* @return a 1-dimensional array of variables
*/
default T[] vars(T[][] vars) {
return vars((Object) vars);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified array. All variables are collected in order, and {@code null} values
* are simply discarded.
*
* @param vars
* a 3-dimensional array of variables
* @return a 1-dimensional array of variables
*/
default T[] vars(T[][][] vars) {
return vars((Object) vars);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified parameters. All variables encountered in the first parameter,
* extracting them from arrays (of any dimension), collections and streams, are recursively collected in order, and concatenated to form a
* 1-dimensional array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param first
* an object that may involve one or several variables (possibly in arrays, collections and streams)
* @param x
* a variable
* @return a 1-dimensional array of variables
*/
default T[] vars(Object first, T x) {
return vars(first, (Object) x);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified parameters. All variables encountered in the parameters, extracting
* them from arrays (of any dimension), collections and streams, are recursively collected in order, and concatenated to form a 1-dimensional
* array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param first
* an object that may involve one or several variables (possibly in arrays, collections and streams)
* @param x
* a 1-dimensional array of variables
* @return a 1-dimensional array of variables
*/
default T[] vars(Object first, T[] x) {
return vars(first, (Object) x);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified parameters. All variables encountered in the parameters, extracting
* them from arrays (of any dimension), collections and streams, are recursively collected in order, and concatenated to form a 1-dimensional
* array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param first
* an object that may involve one or several variables (possibly in arrays, collections and streams)
* @param x
* a 2-dimensional array of variables
* @return a 1-dimensional array of variables
*/
default T[] vars(Object first, T[][] x) {
return vars(first, (Object) x);
}
/**
* Returns a 1-dimensional array of variables by collecting them in order from the specified stream.
*
* @param stream
* a stream of variables
* @return a 1-dimensional array of variables
*/
default T[] vars(Stream stream) {
return vars((Object) stream);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified 1-dimensional array of variables, by discarding {@code null} values.
*
* @param vars
* a 1-dimensional array of variables
* @return a 1-dimensional array of variables after discarding all occurrences of {@code null}
*/
default T[] clean(T[] vars) {
return imp().clean(vars);
}
// ************************************************************************
// ***** Methods variablesIn() and variablesFrom()
// ************************************************************************
/**
* Builds and returns a 1-dimensional array of variables from the specified sequence of parameters. All variables encountered in the parameters,
* extracting them from arrays (of any dimension), collections and streams, are recursively collected in order, and concatenated to form a
* 1-dimensional array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param object
* a first object that may involve one or several variables (possibly in arrays, collections and streams)
* @param otherObjects
* other objects that may involve one or several variables (possibly in arrays, collections and streams)
* @return a 1-dimensional array of variables
*/
default T[] variablesIn(Object object, Object... otherObjects) {
return vars(object, otherObjects);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified stream. Each object of the stream is mapped to another object by the
* specified function. Then, all variables 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 variables (occurrences of {@code null} being discarded}
*/
default T[] variablesFrom(Stream stream, Function f) {
return variablesIn(stream.filter(o -> o != null).map(o -> f.apply(o)));
}
/**
* Builds and returns a 1-dimensional array of variables from the specified stream. Each integer of the stream is mapped to another object by the
* specified function. Then, all variables 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 variables (occurrences of {@code null} being discarded}
*/
default T[] variablesFrom(IntStream stream, Function f) {
return variablesFrom(stream.boxed(), f);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified array. Each object of the array is mapped to another object by the
* specified function. Then, all variables are collected and concatenated to form a 1-dimensional array. {@code null} values are discarded.
*
* @param t
* an array of objects
* @param f
* a function mapping objects of the array into other objects
* @return a 1-dimensional array formed of collected variables (occurrences of {@code null} being discarded}
*/
default T[] variablesFrom(U[] t, Function f) {
return variablesFrom(Stream.of(t), f);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified collection. Each object of the collection is mapped to another object
* by the specified function. Then, all variables 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 variables (occurrences of {@code null} being discarded}
*/
default T[] variablesFrom(Collection c, Function f) {
return variablesFrom(c.stream(), f);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified array. Each integer of the array is mapped to another object by the
* specified function. Then, all variables 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 variables (occurrences of {@code null} being discarded}
*/
default T[] variablesFrom(int[] t, Function f) {
return variablesFrom(IntStream.of(t).boxed(), f);
}
/**
* Returns a 1-dimensional array of variables, obtained after collecting the variables returned by the specified function when executed on all
* values in this range. Note that {@code null} values are simply discarded, if ever generated. Be careful: in case, no variable is obtained,
* {@code null} is returned.
*
* @param r
* a range of integers
* @param f
* a function to convert integer values into objects (typically, variables, but can also be structures containing variables)
* @return a non-empty 1-dimensional array of variables or {@code null}
*/
default T[] variablesFrom(Range r, Function f) {
return variablesFrom(r.stream(), f);
}
/**
* Builds and returns a 1-dimensional array of variables from the specified sequence of parameters. All variables encountered in the parameters,
* extracting them from arrays (of any dimension), collections and streams, are recursively collected in order, sorted, made distinct, so as to
* form a 1-dimensional array. Note that {@code null} values, as well as any simple object not implementing {@code IVar}, are simply discarded.
*
* @param objects
* a sequence of objects that may involve one or several variables (possibly in arrays, collections and streams)
* @return a 1-dimensional array of variables
*/
default T[] singleVariablesIn(Object... objects) {
return vars(Stream.of((Object[]) variablesIn(objects)).sorted().distinct());
}
/**
* Builds and returns a 1-dimensional array of variables from the specified stream. Each object of the stream is mapped to another object by the
* specified function. Then, all variables are collected, sorted and made distinct so as 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 variables (occurrences of {@code null} being discarded}
*/
default T[] singleVariablesFrom(Stream stream, Function f) {
return singleVariablesIn(stream.filter(o -> o != null).map(o -> f.apply(o)));
}
/**
* Builds and returns a 1-dimensional array of variables from the specified collection. Each object of the collection is mapped to another object
* by the specified function. Then, all variables are collected, sorted and made distinct so as 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 stream into other objects
* @return a 1-dimensional array formed of collected variables (occurrences of {@code null} being discarded}
*/
default T[] singleVariablesFrom(Collection c, Function f) {
return singleVariablesFrom(c.stream(), f);
}
// default Var[] variablesFrom(Rangesx2 r2, BiFunction f) {
// List