public class x
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Assert |
Assert
Contains an instance of
Assert class object that has useful assertion methods. |
static Function<java.lang.Object,java.lang.Object> |
doNothing
A
Function that takes any object as input and returns the same object. |
static Predicate<java.lang.Object> |
empty
A
Predicate that only true if len(Object) returns 0 for the input value. |
static Function<java.lang.Object,java.lang.String> |
escape
A synonym to
x.String.escape |
static Predicate<java.lang.Object> |
FALSE
A
Predicate that is always false no matter the input. |
static Function<java.lang.Object,java.lang.Integer> |
getHashCode
A
Function that returns the value of the hash code of the input object. |
static Predicate<java.lang.Object> |
isEmpty
A synonym to
empty . |
static Function<java.lang.Object,java.lang.Integer> |
len
A
Function that takes any object as input and returns its "length", e.g. |
static Function<java.lang.Object,java.lang.String> |
lower
A synonym to
|
static java.util.Random |
Random
Static acces to Java's Random object methods
|
static RegexStatic |
Regex
An instance of RegexStatic class.
|
static strStatic |
str
|
static HappyStringStatic |
String
For consistency,
x.String contains an instance of a utility
HappyStringStatic object that implements some static methods
that a usual String class has as well plus some new Function and Predicate
objects that take String as input. |
static Function<java.lang.Object,java.lang.String> |
strip
A synonym to
|
static Time |
Time
An instance of Time class.
|
static ThreadTimer |
timer
Starts the static
ThreadLocal timer of the ThreadTimer class. |
static TokenStatic |
Token
An instance of a
TokenStatic object. |
static Function<java.lang.Object,java.lang.String> |
toLowerCase
A synonym to
|
static Function<java.lang.Object,java.lang.String> |
toUpperCase
A synonym to
|
static Function<java.lang.Object,java.lang.String> |
trim
A synonym to
|
static Predicate<java.lang.Object> |
TRUE
A
Predicate that is always true no matter the input. |
static Function<java.lang.Object,java.lang.String> |
upper
A synonym to
|
Constructor and Description |
---|
x() |
Modifier and Type | Method and Description |
---|---|
static <T extends java.lang.Number> |
add()
A
Function that takes a tuple of arguments an adds them up. |
static boolean |
all(java.lang.Iterable<java.lang.Boolean> iterable) |
static <T> boolean |
all(java.lang.Iterable<T> iterable,
Predicate<java.lang.Object> predicate) |
static boolean |
any(java.lang.Iterable<java.lang.Boolean> iterable) |
static <T> boolean |
any(java.lang.Iterable<T> iterable,
Predicate<java.lang.Object> predicate) |
static <O> Function<java.lang.Object,O> |
asKey(java.lang.Iterable<?> iterable)
Creates and returns a
Function that takes as a parameter an Iterable
and uses the Function's input value as key to get a value from the
Iterable |
static <O> Function<java.lang.Object,O> |
asKey(java.util.Map<?,O> map)
Creates and returns a
Function that takes as a parameter a Map
and uses the Function's input value as key to get a value from the
corresponding Map |
static <T> void |
assertNotEmpty(T expression)
Gets the Assert class object and calls its notEmpty method.
|
static <T> void |
assertNotEmpty(T expression,
java.lang.String message)
Gets the Assert class object and calls its notEmpty method.
|
static <T> void |
assertNotNull(T expression)
Gets the Assert class object object and calls its notNull method.
|
static <T> void |
assertNotNull(T expression,
java.lang.String message)
Gets the Assert class object and calls its notNull method.
|
static void |
assertTrue(boolean expression)
Gets the Assert class object and calls its True method.
|
static void |
assertTrue(boolean expression,
java.lang.String message)
Gets the Assert class object and calls its True method.
|
static <T extends java.lang.Number> |
avg()
A
Function that takes a tuple of arguments an adds them up. |
static <T extends java.lang.Number> |
avg(java.lang.Iterable<T> iterable)
Averages the elements of the input
Iterable and returs the average. |
static Bag<java.lang.Boolean> |
Bag(java.lang.Boolean boolean0,
java.lang.Boolean boolean1,
java.lang.Boolean... otherBooleans)
Factory method that returns an new
Bag obtained by
counting bolleans in the input array. |
static <T> Bag<T> |
Bag(java.lang.Iterable<T> iterable)
Factory method that returns an new
Bag obtained by
counting values in the input iterable. |
static <T> Bag<T> |
Bag(java.util.Map<T,java.lang.Integer> map)
Factory method that returns an new
Bag obtained from the input Map . |
static Bag<java.lang.Number> |
Bag(java.lang.Number number0,
java.lang.Number number1,
java.lang.Number... otherNumbers)
Factory method that returns an new
Bag obtained by
counting numbers in the input array. |
static Bag<java.lang.String> |
Bag(java.lang.String string)
Factory method that returns an new
Bag obtained by
counting characters in the input string. |
static Bag<java.lang.String> |
Bag(java.lang.String string0,
java.lang.String string1,
java.lang.String... otherStrings)
Factory method that returns an new
Bag obtained by
counting strings in the input array. |
static <I,O> Function<I,O> |
chain(Function<java.lang.Object,?>... functions)
Chains functions in the following way:
f2(f1(f0(x))) where x is the input
of the chained function and f0, f1, ... |
static <T> java.lang.Iterable<T> |
chain(java.lang.Iterable<T> iterable0,
java.lang.Iterable<T> iterable1,
java.lang.Iterable<T>... iterables)
Returns an
Iterable that chains input iterables
of the chained function and f0, f1, ... |
static java.lang.Iterable<java.lang.String> |
chain(java.lang.String string0,
java.lang.String string1,
java.lang.String... otherStrings)
Returns an
Iterable that iterates over the characters of
the sequence of input strings, starting from the first character of the string0 |
static <T> Channel<T> |
Channel(java.lang.Class<T> type)
Creates a new unbuffered (synchronous) channel of the given type.
|
static <T> Channel<T> |
Channel(java.lang.Class<T> type,
int bufferSize)
Creates a new buffered (asynchronous) channel.
|
static <T> Function<java.lang.Object,T> |
constant(T obj)
A
Function that always returns the same object no matter the input of the |
static <T> boolean |
contains(java.lang.Iterable<T> iterable,
T value) |
static java.lang.Iterable<java.lang.Integer> |
count(int min,
int max) |
static java.lang.Iterable<java.lang.Integer> |
count(int min,
int max,
int step) |
static <T> java.lang.Iterable<java.lang.Integer> |
count(java.lang.Iterable<T> iterable) |
static <T> java.lang.Iterable<java.lang.Integer> |
count(java.lang.Iterable<T> iterable,
int step) |
static <T> java.lang.Iterable<java.lang.Integer> |
count(T[] array) |
static <T> java.lang.Iterable<java.lang.Integer> |
count(T[] array,
int step) |
static java.lang.Iterable<java.lang.Integer> |
countFrom(int min) |
static java.lang.Iterable<java.lang.Double> |
countReal(double min,
double max,
double step) |
static java.lang.Iterable<java.lang.Integer> |
countTo(int max) |
static CSV |
csv(java.lang.Iterable<?> iterable)
Creates a
CSV object from an iterable. |
static CSV |
csv(java.lang.StringBuilder builder)
Creates a
CSV object from a StringBuilder . |
static CSV |
csv(java.lang.String path,
java.lang.String operation)
Opens a
HappyFile for reading or writing in csv format with the
default encoding "utf-8". |
static CSV |
csv(java.lang.String path,
java.lang.String operation,
java.lang.String encoding)
Opens a
HappyFile for reading or writing in csv format. |
static <T> java.lang.Iterable<T> |
cycle(java.lang.Iterable<T> iterable) |
static <T> java.lang.Iterable<T> |
cycle(java.lang.Iterable<T> iterable,
java.lang.Integer maxCount) |
static java.lang.Iterable<java.lang.String> |
cycle(java.lang.String string) |
static java.lang.Iterable<java.lang.String> |
cycle(java.lang.String string,
int maxCount) |
static <T> DefaultDict<T> |
DefaultDict(java.lang.Class<T> defaultType)
Factory method that returns an new
DefaultDict of type @param defaultType. |
static <T> dict<T> |
dict()
Factory method that returns an new empty
dict . |
static <T> dict<T> |
dict(dict<T> dict)
|
static <T> dict<T> |
dict(java.lang.Iterable<tuple> tuples)
Factory method that returns an new
dict filled using the
values of the input Iterable of tuples. |
static <T> dict<T> |
dict(java.util.Map<java.lang.String,T> map)
|
static <T> dict<T> |
dict(tuple... tuples)
Factory method that returns an new
dict filled using the
values of the input array of tuples. |
static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> |
enumerate(java.lang.Iterable<T> iterable) |
static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> |
enumerate(java.lang.Iterable<T> iterable,
int startCount) |
static java.lang.Iterable<tuple2<java.lang.Integer,java.lang.String>> |
enumerate(java.lang.String string) |
static java.lang.Iterable<tuple2<java.lang.Integer,java.lang.String>> |
enumerate(java.lang.String string,
int startCount) |
static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> |
enumerate(T[] array) |
static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> |
enumerate(T[] array,
int startCount) |
static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> |
enumerate(T value0,
T value1,
T... values) |
static java.lang.String |
escape(java.lang.String string)
A synonym to
x.String.escape(String) |
static <T> java.lang.Iterable<T> |
filter(Predicate<java.lang.Object> predicate,
java.lang.Iterable<T> iterable)
Applies the input
Predicate to each element of the input Iterable |
static <T> T |
first(java.lang.Iterable<T> iterable) |
static <T> Goer<T> |
go(Predicate<Channel<T>> worker,
Channel<T> channel)
Starts a thread with the computation described in worker and the channel for sending computed values to.
|
static <T> Predicate<java.lang.Object> |
in(java.lang.Iterable<T> iterable)
Creates and returns new
Predicate that returns true
only if the input value of the predicate (key) is contained within in the Iterable |
static Predicate<java.lang.Object> |
in(str str)
Creates and returns new
Predicate that returns true
only if the input value of the predicate, |
static Predicate<java.lang.Object> |
in(java.lang.String string)
Creates and returns new
Predicate that returns true
only if the input value of the predicate, |
static <T> Function<java.lang.Object,T> |
invoke(java.lang.String methodName,
java.lang.Object... methodParams)
A
Function that takes an object's method name and method's
parameters values as input, invokes that method with those parameters
and the output of invocation. |
static boolean |
isEmpty(java.lang.Object object)
Checks if the input object is empty (does not contains any element).
|
static boolean |
isFalse(java.lang.Object value)
This static method evaluates an input object as false or true.
|
static boolean |
isNotEmpty(java.lang.Object object)
Checks if the input object is empty (does not contains any element).
|
static boolean |
isTrue(java.lang.Object value)
This static method evaluates an input object as true or false.
|
static Function<java.lang.Object,java.lang.String> |
joinOn(java.lang.String separator)
Creates and returns a
Function that takes as a parameter a String separator
and concatinates the Function's input Iterable using the separator |
static <O> Json<O> |
Json(java.lang.Integer v)
|
static <O> Json<O> |
Json(java.lang.Iterable<?> o)
Factory method that creates a new xpresso
Json object from an Iterable . |
static <O> Json<O> |
Json(java.util.Map<?,?> o)
Factory method that creates a new xpresso
Json object from a Map . |
static <O> Json<O> |
Json(java.lang.String string)
Factory method that creates a new xpresso
Json object from a String . |
static <O> Json<O> |
Json(tuple o)
Factory method that creates a new xpresso
Json object from a Integer . |
static <O> LambdaFunction<O> |
lambdaF(java.lang.String lambdaExpression) |
static <O> LambdaFunction<O> |
lambdaF(java.lang.String lambdaExpression,
Function<java.lang.Object,?>... functions)
Creates and returns new
LambdaFunction for a given String lambda expression
Example 1: |
static LambdaPredicate |
lambdaP(java.lang.String lambdaExpression) |
static LambdaPredicate |
lambdaP(java.lang.String lambdaExpression,
Function<java.lang.Object,?>... functions)
Creates and returns new
LambdaPredicate for a given String lambda expression
Example 1: |
static <T extends java.lang.Comparable<T>> |
largestN(java.lang.Iterable<T> iterable,
int N)
Returns the N largest elements of the input
Iterable . |
static <T> T |
last(java.lang.Iterable<T> iterable) |
static int |
len(java.lang.Object value)
Returns the length of the argument, usually it is the number of elements it contains.
|
static <T> list<T> |
list()
Factory method that creates a new empty
list object. |
static <T> list<T> |
list(java.lang.Iterable<T> iterable)
Factory method that creates a new
list object
from the input Iterable iterable of type T. |
static <T> list<T> |
list(T[] values)
Factory method that creates a new
list object
from the input array of type T. |
static <T> list<T> |
list(T element0,
T element1,
T... elements)
Factory method that creates a new
list object
from the input elements of type T. |
static <T> list<T> |
listOf(T element)
Factory method that creates a new
list containing the input element. |
static <I,O> java.lang.Iterable<O> |
map(Function<java.lang.Object,O> function,
java.lang.Iterable<I> iterable)
Applies the input
Function to each element of the input Iterable |
static <T extends java.lang.Comparable<? super T>> |
max() |
static <T extends java.lang.Comparable<? super T>> |
max(java.lang.Iterable<T> iterable) |
static <T extends java.lang.Comparable<? super T>> |
max(T value0,
T value1,
T... values) |
static <T> T |
memo(T object) |
static <T extends java.lang.Comparable<? super T>> |
min() |
static <T extends java.lang.Comparable<? super T>> |
min(java.lang.Iterable<T> iterable) |
static <T extends java.lang.Comparable<? super T>> |
min(T value0,
T value1,
T... values) |
static HappySQL |
mysql(HappyMySQL sql)
Creates a new instance of a HappyMySQL object with the same parameters as
those of the input HappyMySQL object.
|
static HappySQL |
mysql(java.lang.String dbHost,
java.lang.String userName,
java.lang.String password,
java.lang.String dbName)
Creates an instance of a HappySQL object.
|
static Predicate<java.lang.Object> |
NOT(Predicate<java.lang.Object> predicate)
|
static HappyObject |
Object(java.lang.Object o)
Creates an instance of a HappyObject class.
|
static HappyFile |
open(java.lang.String path,
java.lang.String operation)
Opens a
HappyFile for reading or writing, in binary or text mode. |
static HappyFile |
open(java.lang.String path,
java.lang.String operation,
java.lang.String encoding)
Opens a
HappyFile for reading or writing, in binary or text mode. |
static <T> OrderedDict<T> |
OrderedDict()
Factory method that returns an new empty
OrderedDict . |
static <T> OrderedDict<T> |
OrderedDict(java.lang.Iterable<T> iterable)
Factory method that returns an new
OrderedDict from an input Iterable . |
static <T0> void |
print(T0 object)
A less verbose console print method.
|
static <T0,T1> void |
print(T0 object0,
T1 object1)
A less verbose console print method.
|
static <T0,T1,T2> void |
print(T0 object0,
T1 object1,
T2 object2)
A less verbose console print method.
|
static <T0,T1,T2,T3> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3)
A less verbose console print method.
|
static <T0,T1,T2,T3,T4> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3,
T4 object4)
A less verbose console print method.
|
static <T0,T1,T2,T3,T4,T5> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3,
T4 object4,
T5 object5)
A less verbose console print method.
|
static <T0,T1,T2,T3,T4,T5,T6> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3,
T4 object4,
T5 object5,
T6 object6)
A less verbose console print method.
|
static <T0,T1,T2,T3,T4,T5,T6,T7> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3,
T4 object4,
T5 object5,
T6 object6,
T7 object7)
A less verbose console print method.
|
static <T0,T1,T2,T3,T4,T5,T6,T7,T8> |
print(T0 object0,
T1 object1,
T2 object2,
T3 object3,
T4 object4,
T5 object5,
T6 object6,
T7 object7,
T8 object8)
A less verbose console print method.
|
static java.lang.Iterable<java.lang.Integer> |
range(int min,
int max)
Alias for compatibility with Python.
|
static java.lang.Iterable<java.lang.Integer> |
range(int min,
int max,
int step)
Alias for compatibility with Python.
|
static <I> I |
reduce(Function<tuple2<I,I>,I> function,
java.lang.Iterable<I> iterable)
Applies function of two arguments cumulatively to the items of iterable,
from left to right, so as to reduce the iterable to a single value.
|
static <I> I |
reduce(Function<tuple2<I,I>,I> function,
java.lang.Iterable<I> iterable,
I initializer)
Applies function of two arguments cumulatively to the items of iterable,
from left to right, so as to reduce the iterable to a single value.
|
static Regex |
Regex(dict<java.lang.String> translator) |
static Regex |
Regex(dict<java.lang.String> translator,
int flags) |
static Regex |
Regex(java.lang.String regularExpression)
Factory method that creates a new Regex object from a string
regular expression.
|
static Regex |
Regex(java.lang.String regularExpression,
int flags)
Factory method that creates a new Regex object from a string
regular expression.
|
static Regex |
RegexNoCase(dict<java.lang.String> translator) |
static Regex |
RegexNoCase(java.lang.String regularExpression)
Factory method that creates a new case insensitive
Regex object from a string
regular expression.
|
static <T> java.lang.Iterable<T> |
repeat(T value) |
static <T> java.lang.Iterable<T> |
repeat(T value,
java.lang.Integer maxCount) |
static <T> java.lang.Iterable<T> |
reverse(java.lang.Iterable<T> iterable)
Reverse the order of elements of the input
Iterable |
static str |
reverse(str str)
Reverse the order of charcters in the input
str |
static double |
round(double number)
Return the double value number rounded to ndigits digits after the decimal point.
|
static double |
round(double number,
int nDigits)
Return the double value number rounded to nDigits digits after the decimal point.
|
static <T> set<T> |
set()
Factory method that creates a new empty
set object. |
static <T> set<T> |
set(java.lang.Iterable<T> iterable)
Factory method that creates a new
set object
from the input Iterable iterable of type T. |
static <T> set<T> |
set(T[] elements)
Factory method that creates a new
set object
from the array of input elements of type T. |
static <T> set<T> |
set(T element0,
T element1,
T... elements)
Factory method that creates a new
set object
from all input elements of type T. |
static <T> set<T> |
setOf(T element)
Factory method that creates a new
set object
and puts into the set the input element. |
static <T> java.lang.Iterable<T> |
shuffle(java.lang.Iterable<T> iterable)
Suffles the input iterable and returns the shuffled copy.
|
Slicer |
slice() |
Slicer |
slice(int step) |
Slicer |
slice(int startIndex,
int endIndex) |
Slicer |
slice(int startIndex,
int endIndex,
int step) |
Slicer |
sliceFrom(int startIndex) |
Slicer |
sliceFrom(int startIndex,
int step) |
Slicer |
sliceTo(int endIndex) |
Slicer |
sliceTo(int endIndex,
int step) |
static <T extends java.lang.Comparable<T>> |
smallestN(java.lang.Iterable<T> iterable,
int N)
Returns the N smallest elements of the input
Iterable . |
static <T extends java.lang.Comparable<T>> |
sort(java.lang.Iterable<T> iterable) |
static <T extends java.lang.Comparable<T>> |
sort(java.lang.Iterable<T> iterable,
boolean reverse) |
static <T> java.lang.Iterable<T> |
sort(java.lang.Iterable<T> iterable,
Function<java.lang.Object,? extends java.lang.Comparable<?>> function) |
static <T> java.lang.Iterable<T> |
sort(java.lang.Iterable<T> iterable,
Function<java.lang.Object,? extends java.lang.Comparable<?>> function,
boolean reverse)
Sorts the values of the input
Iterable of type T according to
the evaluation function Function which is applied to each element
of the input Iterable. |
static str |
sort(str str) |
static str |
sort(str str,
boolean reverse) |
static str |
sort(str str,
Function<java.lang.Object,? extends java.lang.Comparable<?>> function) |
static str |
sort(str str,
Function<java.lang.Object,? extends java.lang.Comparable<?>> function,
boolean reverse) |
static str |
str()
Factory method that creates a new empty
str object. |
static str |
str(java.lang.Iterable<java.lang.String> iterable)
|
static str |
str(java.lang.String string)
Factory method that creates a new
str object
from the input String string. |
static HappyString |
String(char character)
Returns a
HappyString object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>) , HappyString.split(java.lang.String, int) , and HappyString.in(java.lang.String...) . |
static HappyString |
String(java.lang.Character character)
Returns a
HappyString object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>) , HappyString.split(java.lang.String, int) , and HappyString.in(java.lang.String...) . |
static HappyString |
String(str str)
Returns a HappyString object that extends the String object
with additional methods, such as
HappyString.join(java.lang.Iterable<?>) , HappyString.split(java.lang.String, int) , and HappyString.in(java.lang.String...) . |
static HappyString |
String(java.lang.String string)
Returns a
HappyString object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>) , HappyString.split(java.lang.String, int) , and HappyString.in(java.lang.String...) . |
static <T extends java.lang.Number> |
sum(java.lang.Iterable<T> iterable)
Sums the elements of the input
Iterable and returs the sum. |
static double |
time()
Returns the time in seconds since the epoch as a floating point number.
|
static Timer |
Timer()
Returns the running
Timer object. |
static Token |
Token(java.lang.String string)
An instance of a
Token object. |
static <T0> tuple |
tuple(T0 value)
Factory method that returns an
tuple of one element. |
static <T0,T1> tuple |
tuple(T0 value0,
T1 value1)
Factory method that returns an
tuple of two elements. |
static <T0,T1,T2> tuple |
tuple(T0 value0,
T1 value1,
T2 value2)
Factory method that returns an
tuple of three elements. |
static <T0,T1,T2,T3> |
tuple(T0 value0,
T1 value1,
T2 value2,
T3 value3)
Factory method that returns an
tuple of three elements. |
static <T> tuple |
tupleOf(list<T> lst)
Factory method that returns a new
tuple from a given list. |
static tuple |
tupleOf(tuple tpl)
Factory method that returns a new
tuple from a given tuple. |
static <T> set<T> |
union(java.lang.Iterable<T>... iterables) |
static <T0> tuple1<list<T0>> |
unzip(java.lang.Iterable<tuple> iterable,
java.lang.Class<T0> class0)
Does the opposite of zip.
|
static <T0,T1> tuple2<list<T0>,list<T1>> |
unzip(java.lang.Iterable<tuple> iterable,
java.lang.Class<T0> class0,
java.lang.Class<T1> class1)
Does the opposite of zip.
|
static <T0,T1,T2> tuple3<list<T0>,list<T1>,list<T2>> |
unzip(java.lang.Iterable<tuple> iterable,
java.lang.Class<T0> class0,
java.lang.Class<T1> class1,
java.lang.Class<T2> class2)
Does the opposite of zip.
|
static <T0,T1,T2,T3> |
unzip(java.lang.Iterable<tuple> iterable,
java.lang.Class<T0> class0,
java.lang.Class<T1> class1,
java.lang.Class<T2> class2,
java.lang.Class<T3> class3)
Does the opposite of zip.
|
static <O> ScalarComprehensionStart<O> |
yield()
Factory method that starts a new scalar comprehension.
|
static Tuple1ComprehensionStart |
yield(java.lang.String fieldName)
Factory method that starts a new tuple comprehension.
|
static Tuple2ComprehensionStart |
yield(java.lang.String fieldName0,
java.lang.String fieldName1)
Factory method that starts a new tuple comprehension.
|
static list<tuple> |
zip() |
static <T0> list<tuple> |
zip(java.lang.Iterable<T0> iterable0) |
static <T0,T1> list<tuple> |
zip(java.lang.Iterable<T0> iterable0,
java.lang.Iterable<T1> iterable1) |
static <T0,T1,T2> list<tuple> |
zip(java.lang.Iterable<T0> iterable0,
java.lang.Iterable<T1> iterable1,
java.lang.Iterable<T2> iterable2) |
static <T0,T1,T2,T3> |
zip(java.lang.Iterable<T0> iterable0,
java.lang.Iterable<T1> iterable1,
java.lang.Iterable<T2> iterable2,
java.lang.Iterable<T3> iterable3) |
public static Assert Assert
Assert
class object that has useful assertion methods.public static HappyStringStatic String
x.String
contains an instance of a utility
HappyStringStatic
object that implements some static methods
that a usual String class has as well plus some new Function and Predicate
objects that take String
as input.
Example 1: String three = x.String.valueOf(3);
x.print(three);
Console: 3
Example 2: Function<Object,String> upperFun = x.String.upper;
public static strStatic str
public static Time Time
public static ThreadTimer timer
ThreadLocal
timer of the ThreadTimer
class.
This timer can be started, stopped and printed.
The difference between x.timer
based on the ThreadTimer
and x.Timer()
based on Timer
it that if you use x.timer
you don't have to
create any instance of any object. You can simply use the static
reference x.timer.start()
and x.timer.stop();
The timer x.timer
is global for the current thread and independent of
any other thread.
Example:
x.timer.start();
//do something
x.print(x.timer.stop());
Console: 0.133s
public static TokenStatic Token
TokenStatic
object.
Example:
String stem = x.Token.stem("Worker");
Example:
String stem = x.Token.stem("Marcher", "french");
public static java.util.Random Random
public static RegexStatic Regex
public static Function<java.lang.Object,java.lang.String> escape
x.String.escape
public static Function<java.lang.Object,java.lang.String> strip
x.String.strip
public static Function<java.lang.Object,java.lang.String> trim
x.String.trim
public static Function<java.lang.Object,java.lang.String> toLowerCase
x.String.toLowerCase
public static Function<java.lang.Object,java.lang.String> lower
x.String.lower
public static Function<java.lang.Object,java.lang.String> toUpperCase
x.String.toUpperCase
public static Function<java.lang.Object,java.lang.String> upper
x.String.upper
public static Function<java.lang.Object,java.lang.Integer> len
Function
that takes any object as input and returns its "length", e.g.
the number of elements in case of Iterable or tuple.public static Function<java.lang.Object,java.lang.Object> doNothing
Function
that takes any object as input and returns the same object.public static Predicate<java.lang.Object> FALSE
Predicate
that is always false no matter the input.public static Predicate<java.lang.Object> TRUE
Predicate
that is always true no matter the input.public static Predicate<java.lang.Object> empty
Predicate
that only true if len(Object)
returns 0 for the input value.public static <T> Goer<T> go(Predicate<Channel<T>> worker, Channel<T> channel)
Predicate<Channel<Integer>> worker = new Predicate<Channel<Integer>>() {
public Boolean apply(Channel<Integer> channel) {
while (some_condition_true) {
Integer value = computeValue(); //compute something in parallel
channel.send(value); //send the computed value to the channel
}
return true; //everything went as expected
}
};
Then, define the channel to where the workers should send the computed values as soon as those values are ready:
Channel<Integer> channel = x.Channel(Integer.class);//this channel only accepts Integer values
Then, start as many concurrent workers as needed:
x.go(worker, channel);
x.go(worker, channel);
x.go(worker, channel);
...
Finally, retrieve the computed values from the channel when those values are needed:
for (Integer value : channel) {
x.print(value);
}
T
- type of values one can send o and retrieve from the channelworker
- a Predicate
object whose apply method describes the computation and uses the channel to send computed values tochannel
- a Channel
to send the computed values to by the workers, and to read them from by the main routine as those values are readypublic static <T> Channel<T> Channel(java.lang.Class<T> type)
Predicate<Channel<Integer>> worker = new Predicate<Channel<Integer>>() {
public Boolean apply(Channel<Integer> channel) {
while (some_condition_true) {
Integer value = computeValue(); //compute something in parallel
channel.send(value); //send the computed value to the channel
}
return true; //everything went as expected
}
};
Then, define the channel to where the workers should send the computed values as soon as those values are ready:
Channel<Integer> channel = x.Channel(Integer.class);//this channel only accepts Integer values
Then, start as many concurrent workers as needed:
x.go(worker, channel);
x.go(worker, channel);
x.go(worker, channel);
...
Finally, retrieve the computed values from the channel when those values are needed:
for (Integer value : channel) {
x.print(value);
}
T
- type of values one can send o and retrieve from the channeltype
- type of values that can be sent to and retrieved from the channel.public static <T> Channel<T> Channel(java.lang.Class<T> type, int bufferSize)
Predicate<Channel<Integer>> worker = new Predicate<Channel<Integer>>() {
public Boolean apply(Channel<Integer> channel) {
while (some_condition_true) {
Integer value = computeValue(); //compute something in parallel
channel.send(value); //send the computed value to the channel
}
return true; //everything went as expected
}
};
Then, define the channel to where the workers should send the computed values as soon as those values are ready:
Channel<Integer> channel = x.Channel(Integer.class, 100);//this channel with buffer size 100 only accepts Integer values
Then, start as many concurrent workers as needed:
x.go(worker, channel);
x.go(worker, channel);
x.go(worker, channel);
...
Finally, retrieve the computed values from the channel when those values are needed:
for (Integer value : channel) {
x.print(value);
}
T
- type of values one can send o and retrieve from the channeltype
- type of values that can be sent to and retrieved from the channel.bufferSize
- the size of bufferpublic static void assertTrue(boolean expression)
expression
- the expression to assert truepublic static void assertTrue(boolean expression, java.lang.String message)
expression
- the expression to assert truemessage
- the message to print in case of falsepublic static <T> void assertNotNull(T expression)
T
- input typeexpression
- the expression to assert not nullpublic static <T> void assertNotNull(T expression, java.lang.String message)
T
- input typeexpression
- the expression to assert not nullmessage
- the message to print in case of nullpublic static <T> void assertNotEmpty(T expression)
T
- input typeexpression
- the expression to assert not emptypublic static <T> void assertNotEmpty(T expression, java.lang.String message)
T
- input typeexpression
- the expression to assert not emptymessage
- the message to print in case of emptypublic static HappySQL mysql(java.lang.String dbHost, java.lang.String userName, java.lang.String password, java.lang.String dbName) throws java.lang.ClassNotFoundException, java.sql.SQLException
dbHost
- db hostuserName
- user namepassword
- passworddbName
- db nameHappySQL.execute(String)
method
that takes the query and params as input;
Example:
try (HappySQL sql = x.mysql("localhost", "user", "password", "db")) {
sql.execute("SELECT * FROM Table WHERE ID BETWEEN ? and ? and UserName LIKE ?", 1000, 2000, "John %");
}
java.lang.ClassNotFoundException
- in case the jdbc driver for mysql is not found on the systemjava.sql.SQLException
- in case of bad SQL requestpublic static HappySQL mysql(HappyMySQL sql) throws java.lang.ClassNotFoundException, java.sql.SQLException
sql
- A HappyMySQL
object to cloneHappySQL.execute(String)
method
that takes the query and params as input;
Example:
try (HappySQL sql2 = x.mysql(sql1)) {
sql2.execute("SELECT * FROM Table WHERE ID BETWEEN ? and ? and UserName LIKE ?", 1000, 2000, "John %");
}
java.lang.ClassNotFoundException
- in case the jdbc driver for mysql is not found on the systemjava.sql.SQLException
- in case of bad SQL requestpublic static HappyObject Object(java.lang.Object o)
\@Override
int hashCode(){
return x.Object(this).hashCode();
}
In the above code, xpresso first finds the members of this (via reflections) and then
dynamically computes the hash code for this based on the values of its members.
\@Override
boolean equals(Object obj){
return x.Object(this).equals(obj);
}
In the above code, xpresso first finds the members of the
two objects (this and obj), and then compares the values of those members.
\@Override
public int compareTo(Object obj){
return x.Object(this).compareTo(obj, fieldName0, fieldName1, ...);
}
In the above code, xpresso first finds the members of the
two objects (this and obj). It then compares the values of those
members between the two objects if those members' names are listed
among the input field names fieldName0, fieldName1, etc.
The order of comparisons between the member's values is the same
as the order of input field names.o
- the Object
whose properties we want to extendHappyObject
object that wraps the input object opublic static HappyFile open(java.lang.String path, java.lang.String operation, java.lang.String encoding) throws java.io.IOException
HappyFile
for reading or writing, in binary or text mode.
Example:
try (HappyFile f = x.open("filename.txt","r","utf-8"){
//do stuff
}
In case of a text file, the HappyFile
object is also an Iterable containing
lines of the file:
for(String line : f){
x.print(line);
}
path
- a String
object containing the path to the fileoperation
- can be "r" (read in text mode), "rb" (read in binary mode),
"w" (write in text mode), "wb" write in binary mode
"a" append in text mode, "ab" append in binary modeencoding
- the String object containing the encoding of the file
(can be "utf-8" or "latin-1")HappyFile
objectjava.io.IOException
- in case there's a problem opening filepublic static HappyFile open(java.lang.String path, java.lang.String operation) throws java.io.IOException
HappyFile
for reading or writing, in binary or text mode.
Example:
HappyFile f = x.open("filename.txt","r","utf-8");
In case of a text file, the HappyFile
object is also an Iterable containing
lines of the file:
for(String line : x.open("filename.txt","r","utf-8")){
x.print(line);
}
path
- a String
object containing the path to the fileoperation
- can be "r" (read in text mode with utf-8 encoding), "rb" (read in binary mode),
"w" (write in text mode), "wb" write in binary mode
"a" append in text mode, "ab" append in binary modeHappyFile
objectjava.io.IOException
- in case there's a problem opening filepublic static CSV csv(java.lang.String path, java.lang.String operation, java.lang.String encoding) throws java.io.IOException
HappyFile
for reading or writing in csv format.
Example 1:
try (csv f = x.csv("filename.txt","r","utf-8"){
for(list<String> line : f){
x.print(line);
}
}
Example 2:
try (csv f = x.csv("filename.txt","w","utf-8"){
for(list<?> line : iterable>){
csv.writerow(line);
}
}
In case of a text file, the CSV
object is also an Iterable containing
list<String>
objects for each line of the file:
for(list<String> line : f){
x.print(line);
}
path
- a String
object containing the path to the fileoperation
- can be "r" (read in text mode), "rb" (read in binary mode),
"w" (write in text mode), "wb" write in binary mode
"a" append in text mode, "ab" append in binary modeencoding
- the String object containing the encoding of the file
(can be "utf-8" or "latin-1")CSV
objectjava.io.IOException
- in case there's a problem opening filepublic static CSV csv(java.lang.String path, java.lang.String operation) throws java.io.IOException
HappyFile
for reading or writing in csv format with the
default encoding "utf-8".
Example:
try (csv f = x.csv("filename.txt","r","utf-8"){
//do stuff
}
In case of a text file, the CSV
object is also an Iterable
containing
list<String>
objects for each line of the file:
for(list<String> line : f){
x.print(line);
}
path
- a String
object containing the path to the fileoperation
- can be "r" (read in text mode), "rb" (read in binary mode),
"w" (write in text mode), "wb" write in binary mode
"a" append in text mode, "ab" append in binary modeCSV
objectjava.io.IOException
- in case there's a problem opening filepublic static CSV csv(java.lang.Iterable<?> iterable)
CSV
object from an iterable.
The Iterable
can be either an instance of HappyFile
or
an Iterable<list<?>>
.
When the input Iterable
is a HappyFile, the csv object reads or writes
from/into the given HappyFile object.
When the input Iterable
is an Iterable<list<?>>
, the csv object can only
be used with the toString() function. It will generate the csv String representation
of the input Iterable
and toString()
will return this csv String representationpublic static CSV csv(java.lang.StringBuilder builder)
CSV
object from a StringBuilder
.
Example:
StringBuilder builder = new StringBuilder();
csv c = x.csv(builder);
for (list<?> line : iterable){
c.writerow(line);
}
String mycsv = c.toString();
builder
- a StringBuffer
object to write csv toCSV
objectpublic static HappyString String(char character)
HappyString
object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>)
, HappyString.split(java.lang.String, int)
, and HappyString.in(java.lang.String...)
.
Example 1:
boolean q = x.String("na").in("banana");
x.print(q);
Console: true
Example 2: String s = x.String("|").join(x.listOf("a","b","c"));
x.print(s);
Console: a|b|ccharacter
- char to wrapHappyString
object that wraps charpublic static HappyString String(java.lang.Character character)
HappyString
object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>)
, HappyString.split(java.lang.String, int)
, and HappyString.in(java.lang.String...)
.
Example 1: boolean q = x.String("na").in("banana");
x.print(q);
Console: true
Example 2: String s = x.String("|").join(x.listOf("a","b","c"));
x.print(s);
Console: a|b|c
character
- char to wrappublic static HappyString String(java.lang.String string)
HappyString
object that extends the String object
with additional methods, such as HappyString.join(java.lang.Iterable<?>)
, HappyString.split(java.lang.String, int)
, and HappyString.in(java.lang.String...)
.
Example 1: boolean q = x.String("na").in("banana");
x.print(q);
Console: true
Example 2: String s = x.String("|").join(x.listOf("a","b","c"));
x.print(s);
Console: a|b|c
string
- to wrappublic static HappyString String(str str)
HappyString.join(java.lang.Iterable<?>)
, HappyString.split(java.lang.String, int)
, and HappyString.in(java.lang.String...)
.
Example 1: boolean q = x.String(x.str("na")).in("banana");
x.print(q);
Console: true
Example 2: String s = x.String("|").join(x.listOf("a","b","c"));
x.print(s);
Console: a|b|c
str
- to wrapHappyString
object that wraps the strpublic static str str()
str
object.
Example 1:
str newStr = x.str();
x.print(newStr);
Console:
str
objectpublic static str str(java.lang.String string)
str
object
from the input String
string.
Example 1:
str newStr = x.str("I like xpresso!");
x.print(newStr.sliceFrom(7));
Console: xpresso!
public static str str(java.lang.Iterable<java.lang.String> iterable)
str
object
from the input Iterable
of type String
.
Example 1:
str newStr = x.str(x.list("hello", " ", "world", "!"));
x.print(newStr);
Console: hello world!
public static <T> set<T> set(java.lang.Iterable<T> iterable)
set
object
from the input Iterable
iterable of type T. The elements
of the input iterable will become the members of the new set object.@SafeVarargs public static <T> set<T> set(T element0, T element1, T... elements)
set
object
from all input elements of type T. The elements
of the input will become the members of the new set object.public static <T> set<T> set(T[] elements)
set
object
from the array of input elements of type T. The elements
of the input array will become the members of the new set object.public static <T> set<T> setOf(T element)
set
object
and puts into the set the input element.public static <T> list<T> listOf(T element)
list
containing the input element.@SafeVarargs public static <T> list<T> list(T element0, T element1, T... elements)
list
object
from the input elements of type T. The input elements
will become the members of the new list object
in the same order.public static <T> list<T> list(T[] values)
list
object
from the input array of type T.
The elements of the input array become the elements of new list.
The order of elements in the input array is preserved in the new list.T
- type of elements of the new list
values
- the input array of elements of type Tpublic static <T> list<T> list(java.lang.Iterable<T> iterable)
list
object
from the input Iterable
iterable of type T.
The elements of the input iterable become the elements of new list.
The order of elements in the input iterable is preserved in the new list.T
- type of elements of the new list
iterable
- the input iterable containing elements to put in the new listpublic static <O> ScalarComprehensionStart<O> yield()
foreign_trips_lower = [element.lower() for element in trips if element not in russian_cities]
xpresso:
list<String> foreignTripsLower = x.list(x.yield().apply(x.lower).forEach(trips).unless(x.in(russianCities)));
O
- the type of elements in the output iterablepublic static Tuple1ComprehensionStart yield(java.lang.String fieldName)
list1 = [a.lower() for a, b, c, d in list0]
xpresso:
list<tuple> list1 = x.list(x.yield("a").apply(x.lower).where("a", "b", "c", "d").in(list0));
fieldName
- the name of the "field" of each element of the input Iterable we want in our output Iterablepublic static Tuple2ComprehensionStart yield(java.lang.String fieldName0, java.lang.String fieldName1)
list1 = [a.lower(), b.upper() for a, b, c, d in list0]
xpresso:
list<tuple> list1 = x.list(x.yield("a", "b").apply(x.lower, x.upper).where("a", "b", "c", "d").in(list0));
Example 2, a list comprehension:
Python:
list1 = [a.lower(), true for a, b, c, d in list0]
xpresso:
list<tuple> list1 = x.list(x.yield("a", "b").apply(x.lower).replace(True).where("a", "b", "c", "d").in(list0));
fieldName0
- andfieldName1
- are the names of the "fields" of each element of the input Iterable
we want in our output Iterablepublic static <O> Function<java.lang.Object,O> asKey(java.lang.Iterable<?> iterable)
Function
that takes as a parameter an Iterable
and uses the Function's input value as key to get a value from the
Iterable
O
- the type of elements in theiterable
- an Iterable
Function
public static <O> Function<java.lang.Object,O> asKey(java.util.Map<?,O> map)
Function
that takes as a parameter a Map
and uses the Function's input value as key to get a value from the
corresponding Map
O
- the type of values in the mapmap
- a Map
Function
public static Function<java.lang.Object,java.lang.String> joinOn(java.lang.String separator)
Function
that takes as a parameter a String
separator
and concatinates the Function's input Iterable
using the separatorseparator
- an String
separatorFunction
public static <T> Predicate<java.lang.Object> in(java.lang.Iterable<T> iterable)
Predicate
that returns true
only if the input value of the predicate (key) is contained within in the Iterable
iterable
parameter.T
- the type of iterable's elementiterable
- an Iterable
of type <T>
Predicate
public static Predicate<java.lang.Object> in(java.lang.String string)
Predicate
that returns true
only if the input value of the predicate, stringOrChar
is contained within in the <pre>string</pre>
parameter.string
- the String
to search inPredicate
public static Predicate<java.lang.Object> in(str str)
Predicate
that returns true
only if the input value of the predicate, stringOrChar
is contained within in the <pre>str</pre>
parameter.@SafeVarargs public static LambdaPredicate lambdaP(java.lang.String lambdaExpression, Function<java.lang.Object,?>... functions)
LambdaPredicate
for a given String
lambda expression
Example 1: Predicate\<Object\> isNonEmptyLongString = x.lambdaP("x : f0(x) > 5 || f1(x) != 0",x.len,x.len);
lambdaExpression
- a String
containing a lambda expressionfunctions
- optional Function
objectspublic static LambdaPredicate lambdaP(java.lang.String lambdaExpression)
@SafeVarargs public static <O> LambdaFunction<O> lambdaF(java.lang.String lambdaExpression, Function<java.lang.Object,?>... functions)
LambdaFunction
for a given String
lambda expression
Example 1: Function<Object,Integer> increment = x.\<Integer\>lambdaF("x : x + 1");
O
- output type of the LambdaFunctionlambdaExpression
- a String
with a lambda expressionfunctions
- functions to use in the lambda expressions (optional)public static <O> LambdaFunction<O> lambdaF(java.lang.String lambdaExpression)
@SafeVarargs public static <I,O> Function<I,O> chain(Function<java.lang.Object,?>... functions)
f2(f1(f0(x)))
where x
is the input
of the chained function and f0, f1, ... are the functions to apply to x in chain.
Example 1: Function<Integer,Integer> incrementAndMultiplyBy5 = x.chain(increment,x.\<Integer\>lambdaF("x : x * 5"));
I
- input type for the final chained functionO
- output type for the final chained functionfunctions
- functions to chain (optional)Function
that chains the input functions@SafeVarargs public static <T> java.lang.Iterable<T> chain(java.lang.Iterable<T> iterable0, java.lang.Iterable<T> iterable1, java.lang.Iterable<T>... iterables)
Iterable
that chains input iterables
of the chained function and f0, f1, ... are the functions to apply to x
in chain.T
- the type of values returned by the input iterablesiterable0
- the first iterableiterable1
- the second iterableiterables
- the remaining iterablesIterable
ot type T
@SafeVarargs public static java.lang.Iterable<java.lang.String> chain(java.lang.String string0, java.lang.String string1, java.lang.String... otherStrings)
Iterable
that iterates over the characters of
the sequence of input strings, starting from the first character of the string0string0
- the first stringstring1
- the second stringotherStrings
- the remaining stringsIterable
or String
public static tuple tupleOf(tuple tpl)
tuple
from a given tuple.tpl
- a tupletuple
that has the same member values as the old tuple value
public static <T> tuple tupleOf(list<T> lst)
tuple
from a given list.T
- type of values in teh listlst
- a listtuple
that has the same member values as the old tuple value
public static <T0> tuple tuple(T0 value)
tuple
of one element.T0
- the type of valuevalue
- a value of any typetuple
that contains @param valuepublic static <T0,T1> tuple tuple(T0 value0, T1 value1)
tuple
of two elements.T0
- the type of value0T1
- the type of value1value0
- a value of any typevalue1
- a value of any type (can be different of the type of value0)tuple
that contains @param value0 as the first dimension
and @param value1 as the second dimensionpublic static <T0,T1,T2> tuple tuple(T0 value0, T1 value1, T2 value2)
tuple
of three elements.T0
- the type of value0T1
- the type of value1T2
- the type of value2value0
- a value of any typevalue1
- a value of any type (can be different of the type of value0)value2
- a value of any type (can be different of the types of value0 and value1)value1
- as the second dimension, and @param value2 as the third dimensiontuple
that contains @param value0 as the first dimension,public static <T0,T1,T2,T3> tuple tuple(T0 value0, T1 value1, T2 value2, T3 value3)
tuple
of three elements.T0
- the type of value0T1
- the type of value1T2
- the type of value2T3
- the type of value2value0
- a value of any typevalue1
- a value of any type (can be different of the type of value0)value2
- a value of any type (can be different of the types of value0 and value1)value3
- a value of any type (can be different of the types of value0, value1, and value3)value1
- as the second dimension, @param value2 as the third dimension,
and @param value3 as the fourth dimensiontuple
that contains @param value0 as the first dimension,public static <T> dict<T> dict()
dict
.T
- the type of values in the dictdict
public static <T> dict<T> dict(java.util.Map<java.lang.String,T> map)
T
- any typemap
- a Map
of type <String,T>
dict
public static <T> DefaultDict<T> DefaultDict(java.lang.Class<T> defaultType)
DefaultDict
of type @param defaultType.
DefaultDict in xpresso works similarly to Python's defaultdict.
See collections.T
- any typedefaultType
- a Class<T>
objectpublic static <T> OrderedDict<T> OrderedDict(java.lang.Iterable<T> iterable)
OrderedDict
from an input Iterable
.
The input iterable object has to be an Iterable<tuple>
or
two dimensions or an Iterable<tuple2<String,T>>
or an OrderedDict
OrderedDict in xpresso works similarly to Python's OrderedDict.
See collections.T
- any typeiterable
- an Iterable
public static <T> OrderedDict<T> OrderedDict()
OrderedDict
.
OrderedDict in xpresso works similarly to Python's OrderedDict.
See collections.T
- the type of elements in the dictpublic static <T> Bag<T> Bag(java.lang.Iterable<T> iterable)
Bag
obtained by
counting values in the input iterable.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.T
- any typeiterable
- an Iterable
of type Tpublic static Bag<java.lang.String> Bag(java.lang.String string)
Bag
obtained by
counting characters in the input string.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.string
- a String
public static Bag<java.lang.String> Bag(java.lang.String string0, java.lang.String string1, java.lang.String... otherStrings)
Bag
obtained by
counting strings in the input array.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.string0
- the first String
to put in the new Bagstring1
- the second String
to put in the new BagotherStrings
- all other String
s to put in the new Bagpublic static Bag<java.lang.Number> Bag(java.lang.Number number0, java.lang.Number number1, java.lang.Number... otherNumbers)
Bag
obtained by
counting numbers in the input array.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.number0
- the first Number
to put in the new Bagnumber1
- the second Number
to put in the new BagotherNumbers
- all other Number
s to put in the new Bagpublic static Bag<java.lang.Boolean> Bag(java.lang.Boolean boolean0, java.lang.Boolean boolean1, java.lang.Boolean... otherBooleans)
Bag
obtained by
counting bolleans in the input array.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.boolean0
- the fist Boolean
to put in the new Bagboolean1
- the second Boolean
to put in the new BagotherBooleans
- all other Boolean
s to put in the new Bagpublic static <T> Bag<T> Bag(java.util.Map<T,java.lang.Integer> map)
Bag
obtained from the input Map
.
The keys in the input map will used as the new Bag's counted elements, while
the Integer values of the input Map will be used as the respective counts
for those counted elements.
Bag
in xpresso works similarly to Python's Counter object.
See the page about Python's collections.T
- the type of elements in the Bagmap
- a map containing elements to put into new Bagpublic static int len(java.lang.Object value)
value
- any Objectpublic static double time()
public static Timer Timer()
Timer
object. This object can be then stopped and printed:
Timer timer = x.Timer();
//do something
x.print(timer.stop());
Console: 0.133sTimer
objectpublic static Token Token(java.lang.String string)
Token
object.
Example:
String stem = x.Token("Worker").stem();
Example:
String stem = x.Token("Marcher").stem("french");
Example:
String stem = x.Token("Java8").shape();
Console: ULLLD
string
- the string that defines the tokenToken
for the given String
public static double round(double number, int nDigits)
number
- the number to roundnDigits
- the number of decimals after the decimal pointpublic static double round(double number)
number
- the number to roundpublic static boolean all(java.lang.Iterable<java.lang.Boolean> iterable)
iterable
- in Iterable
of booleansIterable
are true.public static <T> boolean all(java.lang.Iterable<T> iterable, Predicate<java.lang.Object> predicate)
public static boolean any(java.lang.Iterable<java.lang.Boolean> iterable)
iterable
- an Iterable objectIterable
is true.public static <T> boolean any(java.lang.Iterable<T> iterable, Predicate<java.lang.Object> predicate)
public static <T extends java.lang.Comparable<? super T>> T max(java.lang.Iterable<T> iterable)
T
- any typeiterable
- an Iterable of type <T>
Iterable
.@SafeVarargs public static <T extends java.lang.Comparable<? super T>> T max(T value0, T value1, T... values)
T
- any typevalue0
- value of type <T>
value1
- value of type <T>
values
- values of type <T>
public static <T extends java.lang.Comparable<? super T>> T min(java.lang.Iterable<T> iterable)
T
- any typeiterable
- an Iterable of type <T>
Iterable
.@SafeVarargs public static <T extends java.lang.Comparable<? super T>> T min(T value0, T value1, T... values)
T
- any typevalue0
- value of type <T>
value1
- value of type <T>
values
- values of type <T>
public static <T extends java.lang.Number> T sum(java.lang.Iterable<T> iterable)
Iterable
and returs the sum.T
- a type that extends a Number
iterable
- an Iterable of NumbersIterable
public static <T extends java.lang.Number> T avg(java.lang.Iterable<T> iterable)
Iterable
and returs the average.T
- a type that extends a Number
iterable
- an Iterable of Numberspublic static <T> T first(java.lang.Iterable<T> iterable)
T
- any typeiterable
- an IterableIterable
.public static <T> T last(java.lang.Iterable<T> iterable)
T
- any typeiterable
- an IterableIterable
.public static java.lang.Iterable<java.lang.Integer> count(int min, int max, int step)
min
- start valuemax
- end value (not returned)step
- the incrementIterator
over Integer
elements starting from @param min
with the increment between the values given by @param step.
The last returned value by the Iterator will be the biggest Integer
less than @param max.public static java.lang.Iterable<java.lang.Integer> range(int min, int max, int step)
min
- start valuemax
- end value (not returned)step
- the incrementIterator
over Integer
elements starting from @param min
with the increment between the values given by @param step.
The last returned value by the Iterator will be the biggest Integer
less than @param max.public static java.lang.Iterable<java.lang.Integer> count(int min, int max)
min
- start valuemax
- end value (not returned)Iterable
over Integer
elements starting from @param min
with the increment of 1 between the values.
The last returned value by the Iterator will be the biggest Integer
less than @param max.public static java.lang.Iterable<java.lang.Integer> range(int min, int max)
min
- start valuemax
- end value (not returned)Iterable
over Integer
elements starting from @param min
with the increment of 1 between the values.
The last returned value by the Iterator will be the biggest Integer
less than @param max.public static java.lang.Iterable<java.lang.Integer> countTo(int max)
max
- end value (not returned)Iterable
over Integer
elements starting from 0
with the increment of 1 between the values.
The last returned value by the Iterator will be @param max - 1.public static java.lang.Iterable<java.lang.Integer> countFrom(int min)
min
- start valueIterable
over Integer
elements
starting from @param min with the increment of 1 between the values.public static java.lang.Iterable<java.lang.Double> countReal(double min, double max, double step)
min
- start valuemax
- end value (not returned)step
- the incrementIterable
over Double
elements starting from @param min
with the increment between the values given by @param step.
The last returned value by the Iterator will be the biggest Double
less than @param max.public static <T> java.lang.Iterable<java.lang.Integer> count(java.lang.Iterable<T> iterable, int step)
T
- the type of elements of the input Iterableiterable
- an Iterable of any typestep
- the incrementIterable
over Integer
elements starting from 0
with the increment between the values given by @param step.
The last returned value by the Iterable will be the biggest Integer
less than
the length of the input Iterable
.public static <T> java.lang.Iterable<java.lang.Integer> count(java.lang.Iterable<T> iterable)
T
- the type of elements of the input Iterableiterable
- an Iterable of any typeIterable
over Integer
elements starting from 0
with the increment of 1 between the values.
The last returned value by the Iterator will be the biggest Integer
less than
the length of the input Iterable
.public static <T> java.lang.Iterable<java.lang.Integer> count(T[] array, int step)
T
- type of elements of the arrayarray
- an arraystep
- the incrementIterable
over Integer
elements starting from 0
with the increment of step between the values.
The last returned value by the Iterator will be the biggest Integer
less than
the length of the input array.public static <T> java.lang.Iterable<java.lang.Integer> count(T[] array)
T
- type of elements of the arrayarray
- an arrayIterable
over Integer
elements starting from 0
with the increment of 1 between the values.
The last returned value by the Iterator will be the biggest Integer
less than
the length of the input array.public static <I,O> java.lang.Iterable<O> map(Function<java.lang.Object,O> function, java.lang.Iterable<I> iterable)
Function
to each element of the input Iterable
I
- input element typeO
- output element typeiterable
- an iterable or type Ifunction
- a function to apply to elements of the Iterable
Iterable
containing the Functions' outputs of each element.
Preserves the order of elements.public static <I> I reduce(Function<tuple2<I,I>,I> function, java.lang.Iterable<I> iterable, I initializer)
x.reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1+2)+3)+4)+5).
The left argument, x
, is the accumulated value and the right argument,
y, is the update value from the iterable.
If the optional initializer is present, it is placed before the items of the iterable in the calculation,
and serves as a default when the iterable is empty.
If initializer is not given and iterable contains only one item, the first item is returned.
Roughly equivalent to:
def reduce(function, iterable, initializer):
it = iter(iterable)
accum_value = initializer
for x in it:
accum_value = function(accum_value, x)
return accum_value
Preserves the order of elements.I
- input and output element typesiterable
- an iterable of type Iinitializer
- the initializerfunction
- a function to apply to every pair of subsequent elementspublic static <I> I reduce(Function<tuple2<I,I>,I> function, java.lang.Iterable<I> iterable)
x.reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1+2)+3)+4)+5).
The left argument, x
, is the accumulated value and the right argument,
y, is the update value from the iterable.
Roughly equivalent to:
def reduce(function, iterable):
it = iter(iterable)
try:
initializer = next(it)
except StopIteration:
raise TypeError('reduce() of empty sequence with no initial value')
accum_value = initializer
for x in it:
accum_value = function(accum_value, x)
return accum_value
Preserves the order of elements.I
- input and output element typesiterable
- an iterable of type Ifunction
- a function to apply to every pair of subsequent elementspublic static <T> java.lang.Iterable<T> filter(Predicate<java.lang.Object> predicate, java.lang.Iterable<T> iterable)
Predicate
to each element of the input Iterable
T
- element types of the iterableiterable
- an Iterable
of type Tpredicate
- a Predicate
Iterable
containing those elements of the input Iterable
for which the predicate is true.
Preserves the order of elements.@SafeVarargs public static <T> set<T> union(java.lang.Iterable<T>... iterables)
T
- element type of each input iterableiterables
- an array of Iterable
s of type <T>
Iterable
s.public static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> enumerate(java.lang.Iterable<T> iterable, int startCount)
T
- any typeiterable
- an Iterable
of type TstartCount
- the value of index of the first tupleIterable
of tuple
s (int index, T value) from the input Iterable
of type T.
enumerate in xpresso works similarly to Python's enumerate.
See the page about Python's enumerate
for more details.public static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> enumerate(java.lang.Iterable<T> iterable)
@SafeVarargs public static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> enumerate(T value0, T value1, T... values)
T
- any typevalue0
- the first valuevalue1
- the second valuevalues
- the array of all other valuesIterable
of tuple
s (int index, T value) from the input values.
enumerate in xpresso works similarly to Python's enumerate.
See the page about Python's enumerate
for more details.public static java.lang.Iterable<tuple2<java.lang.Integer,java.lang.String>> enumerate(java.lang.String string, int startCount)
string
- a String
objectstartCount
- the value if the index of the first tuple in the output IterableIterable
of tuple
s (int index, String character) for the input string,
thet iterates over the characters of the string.
enumerate in xpresso works similarly to Python's enumerate.
See the page about Python's enumerate
for more details.public static java.lang.Iterable<tuple2<java.lang.Integer,java.lang.String>> enumerate(java.lang.String string)
public static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> enumerate(T[] array, int startCount)
T
- any typearray
- an array or type TstartCount
- the value if the index of the first tuple in the output IterableIterable
of tuple
s (int index, String character) for the input array,
thet iterates over the elements of the array.
enumerate in xpresso works similarly to Python's enumerate.
See the page about Python's enumerate
for more details.public static <T> java.lang.Iterable<tuple2<java.lang.Integer,T>> enumerate(T[] array)
T
- any typearray
- an array of type TIterable
of tuple
s (int index, String character) for the input array,
thet iterates over the elements of the array.
enumerate in xpresso works similarly to Python's enumerate.
See the page about Python's enumerate
for more details.public static <T> java.lang.Iterable<T> cycle(java.lang.Iterable<T> iterable, java.lang.Integer maxCount)
T
- the type of elements in the input Iterableiterable
- an Iterable
maxCount
- the number of repetitionsIterable
returning elements from the input iterable and saving a copy of each.
When the input iterable is exhausted, return elements from the saved copy. Repeats maxCount times.
Equivalent to: x.cycle(x.listOf("A","B","C","D") --> A B C D A B C D A B C D ...
public static <T> java.lang.Iterable<T> cycle(java.lang.Iterable<T> iterable)
T
- the type of elements in the input Iterableiterable
- an Iterable
Iterable
returning elements from the input iterable and saving a copy of each.
When the input iterable is exhausted, return elements from the saved copy. Repeats indifinitely.
Equivalent to: x.cycle(x.listOf("A","B","C","D") --> A B C D A B C D A B C D ...
public static java.lang.Iterable<java.lang.String> cycle(java.lang.String string)
string
- a string that contains the characters to repeatIterable
returning characters from the input string and saving a copy of these characters.
When the above iterable is exhausted, return elements from the saved copy. Repeats indifinitely.
Equivalent to: x.cycle("ABCD") --> A B C D A B C D A B C D ...
public static java.lang.Iterable<java.lang.String> cycle(java.lang.String string, int maxCount)
string
- a string that contains the characters to repeatmaxCount
- the number of repetitionsIterable
returning characters from the input string and saving a copy of these characters.
When the above iterable is exhausted, return elements from the saved copy. Repeats maxCount times.
Equivalent to: x.cycle("ABCD") --> A B C D A B C D A B C D ...
public static <T> java.lang.Iterable<T> repeat(T value, java.lang.Integer maxCount)
T
- the type of the valuevalue
- the value to repeatmaxCount
- the number of repetitionsIterable
that returns the input value of type T
over and over again for maxCount times.public static <T> java.lang.Iterable<T> repeat(T value)
T
- the type of the valuevalue
- the value to repeatIterable
that returns the input value of type T
over and over again.public static <T> java.lang.Iterable<T> shuffle(java.lang.Iterable<T> iterable)
T
- the type of elements of the input iterableiterable
- The input Iterable
public static <T> java.lang.Iterable<T> sort(java.lang.Iterable<T> iterable, Function<java.lang.Object,? extends java.lang.Comparable<?>> function, boolean reverse)
Iterable
of type T according to
the evaluation function Function
which is applied to each element
of the input Iterable.T
- any typeiterable
- an iterable of type Tfunction
- a function that takes an object and retursn a Comparable
reverse
- if true, then the values are sorted from biggest to smallestIterable
of type Tpublic static <T> java.lang.Iterable<T> sort(java.lang.Iterable<T> iterable, Function<java.lang.Object,? extends java.lang.Comparable<?>> function)
public static <T extends java.lang.Comparable<T>> java.lang.Iterable<T> sort(java.lang.Iterable<T> iterable, boolean reverse)
public static <T extends java.lang.Comparable<T>> java.lang.Iterable<T> sort(java.lang.Iterable<T> iterable)
public static str sort(str str, Function<java.lang.Object,? extends java.lang.Comparable<?>> function, boolean reverse)
public static str sort(str str, Function<java.lang.Object,? extends java.lang.Comparable<?>> function)
public static <T> java.lang.Iterable<T> reverse(java.lang.Iterable<T> iterable)
Iterable
T
- any typeiterable
- Iterable
of type Tpublic static str reverse(str str)
str
str
- a str
objectpublic static <T extends java.lang.Comparable<T>> java.lang.Iterable<T> largestN(java.lang.Iterable<T> iterable, int N)
Iterable
.T
- any typeiterable
- Iterable
of type TN
- the desired number of resultsIterable
that contains the N largest elements of the input Iterable
public static <T extends java.lang.Comparable<T>> java.lang.Iterable<T> smallestN(java.lang.Iterable<T> iterable, int N)
Iterable
.T
- any typeN
- the desired number of resultsiterable
- an Iterable
of type TIterable
that contains the N smallest elements of the input Iterable
public static <T> boolean contains(java.lang.Iterable<T> iterable, T value)
T
- any typeiterable
- Iterable
of type Tvalue
- a value of type TIterable
contains the value.public static list<tuple> zip()
Iterable
s. The returned list is truncated in length
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
Example:
x.print(zip(x.listOf(1,3,5),x.listOf(2,4,6)))
Console:
[(1, 2), (3, 4), (5, 6)]
public static <T0> list<tuple> zip(java.lang.Iterable<T0> iterable0)
T0
- type of Iterable0
Example:
x.print(zip(x.listOf(1,3,5),x.listOf(2,4,6)))
Console:
[(1, 2), (3, 4), (5, 6)]
iterable0
- [, iterable1[, iterable2]...]Iterable
s. The returned list is truncated in length
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.public static <T0,T1> list<tuple> zip(java.lang.Iterable<T0> iterable0, java.lang.Iterable<T1> iterable1)
T0
- type of Iterable0T1
- type of Iterable1
Example:
x.print(zip(x.listOf(1,3,5),x.listOf(2,4,6)))
Console:
[(1, 2), (3, 4), (5, 6)]
iterable0
- [, iterable1[, iterable2]...]iterable1
- [, iterable2[, iterable3]...]Iterable
s. The returned list is truncated in length
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.public static <T0,T1,T2> list<tuple> zip(java.lang.Iterable<T0> iterable0, java.lang.Iterable<T1> iterable1, java.lang.Iterable<T2> iterable2)
T0
- type of Iterable0T1
- type of Iterable1T2
- type of Iterable2
Example:
x.print(zip(x.listOf(1,3,5),x.listOf(2,4,6)))
Console:
[(1, 2), (3, 4), (5, 6)]
iterable0
- [, iterable1[, iterable2]...]iterable1
- [, iterable2[, iterable3]...]iterable2
- [, iterable3...]Iterable
s. The returned list is truncated in length
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.public static <T0,T1,T2,T3> list<tuple> zip(java.lang.Iterable<T0> iterable0, java.lang.Iterable<T1> iterable1, java.lang.Iterable<T2> iterable2, java.lang.Iterable<T3> iterable3)
T0
- type of Iterable0T1
- type of Iterable1T2
- type of Iterable2T3
- type of Iterable3
Example:
x.print(zip(x.listOf(1,3,5),x.listOf(2,4,6)))
Console:
[(1, 2), (3, 4), (5, 6)]
iterable0
- [, iterable1[, iterable2]...]iterable1
- [, iterable2[, iterable3]...]iterable2
- [, iterable3]iterable3
- an Iterable
Iterable
s. The returned list is truncated in length
With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.public static <T0> tuple1<list<T0>> unzip(java.lang.Iterable<tuple> iterable, java.lang.Class<T0> class0)
Example:
l = x.listOf(x.tupleOf(1,2), x.tupleOf(3,4), x.tupleOf(5,6));
x.print(x.unzip(l))
Console:
([1, 3, 5], [2, 4, 6])
T0
- type of value0 in the tupleiterable
- of tuplesclass0
- the class of first element of each tuple in the Iterable
public static <T0,T1> tuple2<list<T0>,list<T1>> unzip(java.lang.Iterable<tuple> iterable, java.lang.Class<T0> class0, java.lang.Class<T1> class1)
Example:
l = x.listOf(x.tupleOf(1,2), x.tupleOf(3,4), x.tupleOf(5,6));
x.print(x.unzip(l))
Console:
([1, 3, 5], [2, 4, 6])
T0
- type of value0 in the tupleT1
- type of value1 in the tupleiterable
- of tuplesclass0
- the class of first element of each tuple in the Iterable
class1
- the class of second element of each tuple in the Iterable
public static <T0,T1,T2> tuple3<list<T0>,list<T1>,list<T2>> unzip(java.lang.Iterable<tuple> iterable, java.lang.Class<T0> class0, java.lang.Class<T1> class1, java.lang.Class<T2> class2)
Example:
l = x.listOf(x.tupleOf(1,2), x.tupleOf(3,4), x.tupleOf(5,6));
x.print(x.unzip(l))
Console:
([1, 3, 5], [2, 4, 6])
T0
- type of value0 in the tupleT1
- type of value1 in the tupleT2
- type of value2 in the tupleiterable
- of tuplesclass0
- the class of first element of each tuple in the Iterable
class1
- the class of second element of each tuple in the Iterable
class2
- the class of third element of each tuple in the Iterable
public static <T0,T1,T2,T3> tuple4<list<T0>,list<T1>,list<T2>,list<T3>> unzip(java.lang.Iterable<tuple> iterable, java.lang.Class<T0> class0, java.lang.Class<T1> class1, java.lang.Class<T2> class2, java.lang.Class<T3> class3)
Example:
l = x.listOf(x.tupleOf(1,2), x.tupleOf(3,4), x.tupleOf(5,6));
x.print(x.unzip(l))
Console:
([1, 3, 5], [2, 4, 6])
T0
- type of value0 in the tupleT1
- type of value1 in the tupleT2
- type of value2 in the tupleT3
- type of value3 in the tupleiterable
- of tuplesclass0
- the class of first element of each tuple in the Iterable
class1
- the class of second element of each tuple in the Iterable
class2
- the class of third element of each tuple in the Iterable
class3
- the class of fourth element of each tuple in the Iterable
public static <O> Json<O> Json(java.lang.String string)
Json
object from a String
.
Example:
String jsonString = x.Json("Hello").toString();
x.print(jsonString);
Console: "Hello"
Compare that with:
x.print("Hello");
Console: Hello
O
- the type of the output objectstring
- a String objectpublic static <O> Json<O> Json(java.util.Map<?,?> o)
Json
object from a Map
.
Example:
Map<String,Integer> map = Helpers.newHashMap();
map.put("a",1);
map.put("b",2);
String jsonString = x.Json(map).toString();
x.print(jsonString);
Console {"a": 1, "b": 2}
O
- the type of the output objecto
- a Map objectpublic static <O> Json<O> Json(java.lang.Iterable<?> o)
Json
object from an Iterable
.
Example 1:
list<String> lst = x.list("a","b","c");
String jsonString = x.Json(lst).toString();
x.print(jsonString);
Console {"a", "b", "c"}
Example 2:
dict<Integer> dic = x.list(x.tuple("a":1),x.tuple("b":2));
String jsonString = x.Json(lst).toString();
x.print(jsonString);
Console {"a": 1, "b": 2}
O
- the type of the output objecto
- an Iterablepublic static <O> Json<O> Json(java.lang.Integer v)
Json
object from a tuple
.
Example:
Map<String,Integer> map = Helpers.newHashMap();
map.put("a",1);
map.put("b",2);
String jsonString = x.Json(map).toString();
x.print(jsonString);
Console {"a": 1, "b": 2}
O
- the type of the output objectv
- an Integer objectpublic static <O> Json<O> Json(tuple o)
Json
object from a Integer
.O
- the type of the output objecto
- a tuple objectpublic static Regex Regex(java.lang.String regularExpression, int flags)
Pattern
's flags).
Example:
Regex mama = x.Regex("\\bmama\\b", Regex.CASE_INSENSITIVE);
regularExpression
- a string with a valid Java regular expressionflags
- flags (standard Pattern
flags values are accepted)public static Regex Regex(java.lang.String regularExpression)
Pattern
's flags).
Example:
Regex mama = x.Regex("\\bmama\\b", Regex.CASE_INSENSITIVE);
regularExpression
- a string with a valid Java regular expressionpublic static Regex RegexNoCase(java.lang.String regularExpression)
Example:
Regex mama = x.RegexNoCase("\\bmama\\b");
regularExpression
- a string with a valid Java regular expressionpublic static Regex Regex(dict<java.lang.String> translator, int flags)
translator
- a dict with string to string mappingflags
- usual flags of Pattern
dict<String>
that contains pairs of the form:
(regular expressions string, replacement string)
When you call the Regex.translate(str)
or the Regex.translate(String)
method of such a Regex object, the algorithms replaces each regular expressions string
from the translator dict by the corresponding replacement string.
Example:
dict\<String\> happyReplacer = x.dict(x.tuple("bad","good"),x.tuple("small","big"),x.tuple("hard","easy"));
text = x.Regex(happyReplacer).sub(text);
public static Regex Regex(dict<java.lang.String> translator)
translator
- a dict with string to string mappingdict<String>
that contains pairs of the form:
(regular expressions string, replacement string)
When you call the Regex.translate(str)
or the Regex.translate(String)
method of such a Regex object, the algorithms replaces each regular expressions string
from the translator dict by the corresponding replacement string.
Example:
dict\<String\> happyReplacer = x.dict(x.tuple("bad","good"),x.tuple("small","big"),x.tuple("hard","easy"));
text = x.Regex(happyReplacer).sub(text);
public static Regex RegexNoCase(dict<java.lang.String> translator)
translator
- a dict with string to string mappingdict<String>
that contains pairs of the form:
(regular expressions string, replacement string)
When you call the Regex.translate(str)
or the Regex.translate(String)
method of such a Regex object, the algorithms replaces each regular expressions string
from the translator dict by the corresponding replacement string.
Example:
dict\<String\> happyReplacer = x.dict(x.tuple("bad","good"),x.tuple("small","big"),x.tuple("hard","easy"));
text = x.Regex(happyReplacer).sub(text);
public Slicer slice(int startIndex, int endIndex)
startIndex
- a start index for slicingendIndex
- an end index for slicinglist
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer slice(int startIndex, int endIndex, int step)
startIndex
- a start index for slicingstep
- a step for slicingendIndex
- an end index for slicinglist
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer slice()
startIndex
= 0 and endIndex=Integer.MAX_VALUE
and step=0
.
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer slice(int step)
step
- the step of slicerstartIndex
= 0 and endIndex=Integer.MAX_VALUE
the given value of step
.
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer sliceTo(int endIndex, int step)
step
- a step for slicingendIndex
- an end index for slicingstartIndex=0
.
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer sliceTo(int endIndex)
endIndex
- an end index for slicingstartIndex=0
and step=1
.
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer sliceFrom(int startIndex, int step)
startIndex
- a start index for slicingstep
- a step for slicingendIndex=Integer.MAX_VALUE
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public Slicer sliceFrom(int startIndex)
startIndex
- a start index for slicingendIndex=Integer.MAX_VALUE
and step=0
Slicer objects can be used as input for the slice method of any Slicable
object (like list
or str
)
Example:
Slice LAST_THREE = x.sliceFrom(-3);
x.print(x.String("tic tac toe").slice(LAST_THREE));
Console: toe
public static <T0> void print(T0 object)
System.out.println
.
x.print
is also more versatile. It can take values of any type as input.
Example:
x.print("Hello World", 1, true, x.list(1, 2, 3), null);
Console: Hello World 1 true [1, 2, 3] NullType
T0
- type of object to printobject
- object to printpublic static <T0,T1> void print(T0 object0, T1 object1)
System.out.println
.
x.print
is also more versatile. It can take values of any type as input.
Example:
x.print("Hello World", 1, true, x.list(1, 2, 3), null);
Console: Hello World 1 true [1, 2, 3] NullType
T0
- type of first object to printT1
- type of second object to printobject0
- first object to printobject1
- second object to printpublic static <T0,T1,T2> void print(T0 object0, T1 object1, T2 object2)
System.out.println
.
x.print
is also more versatile. It can take values of any type as input.
Example:
x.print("Hello World", 1, true, x.list(1, 2, 3), null);
Console: Hello World 1 true [1, 2, 3] NullType
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printpublic static <T0,T1,T2,T3> void print(T0 object0, T1 object1, T2 object2, T3 object3)
System.out.println
.
x.print
is also more versatile. It can take values of any type as input.
Example:
x.print("Hello World", 1, true, x.list(1, 2, 3), null);
Console: Hello World 1 true [1, 2, 3] NullType
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printpublic static <T0,T1,T2,T3,T4> void print(T0 object0, T1 object1, T2 object2, T3 object3, T4 object4)
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printT4
- type of fifth object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printobject4
- fifth object to printpublic static <T0,T1,T2,T3,T4,T5> void print(T0 object0, T1 object1, T2 object2, T3 object3, T4 object4, T5 object5)
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printT4
- type of fourth object to printT5
- type of sixth object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printobject4
- fifth object to printobject5
- sixth object to printpublic static <T0,T1,T2,T3,T4,T5,T6> void print(T0 object0, T1 object1, T2 object2, T3 object3, T4 object4, T5 object5, T6 object6)
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printT4
- type of fourth object to printT5
- type of sixth object to printT6
- type of seventh object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printobject4
- fifth object to printobject5
- sixth object to printobject6
- seventh object to printpublic static <T0,T1,T2,T3,T4,T5,T6,T7> void print(T0 object0, T1 object1, T2 object2, T3 object3, T4 object4, T5 object5, T6 object6, T7 object7)
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printT4
- type of fourth object to printT5
- type of sixth object to printT6
- type of seventh object to printT7
- type of eighth object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printobject4
- fifth object to printobject5
- sixth object to printobject6
- seventh object to printobject7
- eighth object to printpublic static <T0,T1,T2,T3,T4,T5,T6,T7,T8> void print(T0 object0, T1 object1, T2 object2, T3 object3, T4 object4, T5 object5, T6 object6, T7 object7, T8 object8)
T0
- type of first object to printT1
- type of second object to printT2
- type of third object to printT3
- type of fourth object to printT4
- type of fourth object to printT5
- type of sixth object to printT6
- type of seventh object to printT7
- type of eighth object to printT8
- type of ninth object to printobject0
- first object to printobject1
- second object to printobject2
- third object to printobject3
- fourth object to printobject4
- fifth object to printobject5
- sixth object to printobject6
- seventh object to printobject7
- eighth object to printobject8
- ninth object to printpublic static boolean isTrue(java.lang.Object value)
Boolean
that equals to false
2) It's an Double
that equals to 0.0
3) It's an Double
that equals to 0.0
4) It's an Float
that equals to 0.0
5) It's an empty String
6) It's an empty Iterable
7) It's a tuple0
8) It's a null
9) It's a Truthful
whose isTrue() method returns false
value
- the object for which we want to know whther it's true or notpublic static boolean isFalse(java.lang.Object value)
Boolean
that equals to false
2) It's an Double
that equals to 0.0
3) It's an Double
that equals to 0.0
4) It's an Float
that equals to 0.0
5) It's an empty String
6) It's an empty Iterable
7) It's a tuple0
8) It's a null
9) It's a Truthful
whose isTrue() method returns false
value
- the object for which we want to know whther it's false or notpublic static boolean isEmpty(java.lang.Object object)
object
- an object to check for emptyness.public static boolean isNotEmpty(java.lang.Object object)
object
- an object to check for emptyness.public static <T> T memo(T object)
T
- the type of object to memoizeobject
- an object to memoizexeroxbe a
Function
object whose method applycopies the string
"hello"the given number
countof times:
Function<Integer, String> xerox = new Function<Integer, String>() {
public String apply(Integer count) {
return x.String("hello").times(count);
}
};
It's a long to execute function for large values of *count*.
In order to avoid the long computation for the same value of *count*, we first create a cached version of xerox using x.memo:
Function<Integer,String> cachedXerox = x.memo(xerox);
The first call of the function. The computation takes a very long time:
x.timer.start();
String copies = cachedXerox.apply(5000000);
x.print(x.timer.stop());
Console: 18.898s
The second call with the same value of *count*, the result is instantaneous:
x.timer.start();
String moreCopies = cachedXerox.apply(5000000);
x.print(x.timer.stop());
Console: 0.0s
x.memo can be used to cache methods of object of any Java type, not only Function
.public static java.lang.String escape(java.lang.String string)
x.String.escape(String)
string
- a String
to escapepublic static <T> Function<java.lang.Object,T> constant(T obj)
Function
that always returns the same object no matter the input of the applymethod.
T
- the type of returned objectobj
- the object to always returnobjno matter the input of the
applymethod.
public static <T> Function<java.lang.Object,T> invoke(java.lang.String methodName, java.lang.Object... methodParams)
Function
that takes an object's method name and method's
parameters values as input, invokes that method with those parameters
and the output of invocation.T
- the output typemethodName
- method name to invokemethodParams
- parameters for the method to invokepublic static <T extends java.lang.Number> Function<tuple2<T,T>,T> add()
Function
that takes a tuple of arguments an adds them up.T
- the output (and the input element) typeFunction
that sums two numberspublic static <T extends java.lang.Number> Function<tuple2<T,T>,T> avg()
Function
that takes a tuple of arguments an adds them up.T
- the output (and the input element) typeFunction
that averages two numberspublic static <T extends java.lang.Comparable<? super T>> Function<tuple2<T,T>,T> min()
T
- the output (and the input element) typeFunction
that takes a tuple of arguments an adds them up.