fraunhoferfokus / xtensions Goto Github PK
View Code? Open in Web Editor NEWThis library provides utility extension methods, mostly for JDK 8 classes.
Home Page: https://fraunhoferfokus.github.io/Xtensions/
License: Eclipse Public License 2.0
This library provides utility extension methods, mostly for JDK 8 classes.
Home Page: https://fraunhoferfokus.github.io/Xtensions/
License: Eclipse Public License 2.0
Add package-info.java
files for each package containing classes, giving an overview of the provided features.
concurrent
datetime
function
optional
pair
range
stream
string
Provide factory methods generate and iterate analogous to the ones already provided to IntIterable.
For LongIterable:
For DoubleIterable:
Every now and then it is handy to produce a cartesian product of two iterables and maybe filter them or define how the combination of two elements should be computed in the product.
For Iterables implement the following extension methods:
static def <X,Y> Iterable<Pair<X,Y>> combinations(Iterable<X> iterable, Iterable<Y> other)
static def <X,Y,Z> Iterable<Z> combinations(Iterable<X> iterable, Iterable<Y> other, (X,Y)=>Z merger)
static def <X,Y> Iterable<Pair<X,Y>> combinationsWhere(Iterable<X> iterable, Iterable<Y> other, BiPredicate<X,Y> where)
static def <X,Y> Iterable<Z> combinationsWhere(Iterable<X> iterable ,Iterable<Y> other, BiPredicate<X,Y> where,(X,Y)=>Z merger)
For Iterators implement the following extension methods:
static def <X,Y> Iterator<Pair<X,Y>> combinations(Iterator<X> iterator, Iterable<Y> other)
static def <X,Y,Z> Iterator<Z> combinations(Iterator<X> iterator, Iterable<Y> other,(X,Y)=>Z merger)
static def <X,Y> Iterator<Pair<X,Y>> combinationsWhere(Iterator<X> iterator, Iterable<Y> other, BiPredicate<X,Y> where)
static def <X,Y> Iterator<Z> combinationsWhere(Iterator<X> iterator, Iterable<Y> other, BiPredicate<X,Y> where,(X,Y)=>Z merger)
Add extension methods to Boolean that test it's value for a condition and pass a callback to be executed if condition matches.
static def void ifTrue(Boolean b, ()=>void action)
static def void ifNullOrTrue(Boolean b, ()=>void action)
static def void ifFalse(Boolean b, ()=>void action)
static def void ifNullOrFalse(Boolean b, ()=>void action)
On java.util.Optional the callchain optional.map[...].orElseGet[...] is pretty common, but it is a little long and may perform one unnecessary object allocation during the map call. So instead a mapOrGet method would be beneficial.
Add forEach method to iterate over array elements without wrapping it into an Iterable and creating an Iterator, as done currently with the forEach method built into Xtend. This is analogous to the forEach methods for primitive arrays.
Add extension methods that can be applied to objects in general.
Consider the following methods
asType
to cast to a given type or return null
if not possibleifNotNull
tests an object on null
and if it is not invokes a given consumer with the objectrecoverNull
tests an object on null
and if it is null returns a fallback else the object itself. Provide a Java 9 API forward compatible alias named requireNonNullElse
recoverNull
tests an object on null
and if it is null returns a fallback computed from from a provider else the object itself. Provide a Java 9 API forward compatible alias named requireNonNullElseGet
Provide a class TryIterator which can iterate over possibly failed results.
It may be created as following extension methods from a regular Iterator<T>
:
static def <T,Y> TryIterator<Y> tryMap(Iterator<T> context, (T)=>Y mapper)
static def <T,Y> TryIterator<Y> tryMapNullable(Iterator<T> context, (T)=>Y mapper)
static def <T> TryIterator<T> tryFilter(Iterator<T> context, Predicate<T> predicate)
static def <T> TryIterator<T> tryFilterNullable(Iterator<T> context, Predicate<T> predicate)
The following instance methods are expected to be implemented:
null
) elements, and failures.java.util.stream.Collector
(and specify what happens on failures)Create a partitioning function, to separate elements provided by an Iterator
/Iterable
by classes they are instance of. This is beneficial for model-to-model transformations, especially when traversing a model to find instances of class X that are referenced by instances of class Y.
This could be the API of such a method:
static def <T> ClassGrouping groupBy(Iterable<T> iterable, Class<?>... classes)
public interface ClassGrouping {
def List<Class<?>> getGroupingClasses();
def <T> List<T> get(Class<T> clazz) throws NoSuchElementException;
def Map<Class<?>,List<?>> asMap();
}
Add toUnmodifiableList method for Iterable and Iterator.
static def <T> List<T> toUnmodifiableList(Iterable<T>)
static def <T> List<T> toUnmodifiableList(Iterator<T>)
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
Add the extension methods
IteratorExtensions#withoutAll(Iterator<T> self, Iterable<?> other)
IterableExtensions#withoutAll(Iteratable<T> self, Iterable<?> other)
This method is basically a shortcut for self.filter[el| !other.exists[el == it]]
but being more performant if other is instance of Collection
.
Add a partitionBy extension method to Iterable and Iterator which partitions an input into two groups according to a predicate. This should be similar to the version provided by the Java 8 java.util.stream.Collector
to feel comfortable to Java users.
static def <T> Map<Boolean,List<T>> partitionBy(Iterable<T>, Predicate<T>)
static def <T, A, C> Map<Boolean,C> partitionBy(Iterable<T>, Collector<? super T,A,C>, Predicate<T>)
static def <T> Map<Boolean,List<T>> partitionBy(Iterator<T>, Predicate<T>)
static def <T, A, C> Map<Boolean,C> partitionBy(Iterator<T>, Collector<? super T,A,C>, Predicate<T>)
Think about providing an interface Partitions
to get around boxing booleans:
interface Partitions<C> extends Map<Boolean,C> {
def C getTrue();
def C getFalse();
}
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
Support some basic aggregation methods for primitive iterators:
Add a into extension method adding the references stored in on Iterable/provided by an Iterator to a given collection. This allows for more compact code. The equivalent of collection.into(target)
currently has to be written as collection.forEach[target.add(it)]
which looks a bit more convoluted. If Xtend would support method references this could look something like: this collection.forEach(target#add)
. This would look a bit better.
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
EDIT: It may also be desirable to have a into(Collection...) method.
Tasks:
Hello Xtensions team,
The Xtext team would like to update the Xtext community website listing all the cool projects people are building around Xtext/Xtend.
See also the corresponding GitHub issue and Bugzilla ticket.
If you are interested that the Xtensions project is listed there, please provide the following information as a comment to this issue:
<tr>
<td><a href="project_link">project_name</a></td>
<td>project_description_max_2_sentences</td>
<td>license</td>
<td>category</td>
<td>author(s)</td>
</tr>
We will then update the Xtext community website and get it online as soon as possible.
Thanks!
Tamás
Provide an optional variant for boolean
, similar to how the JDK provides for other primitives like OptionalInt
for the primitive int
.
isPresent
ifPresent
ifPresentOrElse
orElse
orElseGet
orElseGetThrow
empty
static factory methodofNullable
static factory methodofTrue
static factory methodofFalse
static factory methodisTrue
ifTrue
isTrueOrEmpty
ifTrueOrEmpty
isFalse
ifFalse
isFalseOrEmpty
ifFalseOrEmpty
Primitives
provide extension method
optionalBool
to create an OptionalBoolean
mapping to a bool and null
to an empty optionalOptionalExtensions
create extension methods
mapBool
similar how it is already done for other other primitive types test
checking a value wrapped in an optional for a conditionAlso:
OptionalBoolean
Provide a Try
class that represents three states of a computation result:
null
result resulting of a successful computationTry
Users of that type should be able to
isEmpty
, isSuccess
, isFailure
methods to check for Try
variantAnalogous to the JDK method java.lang.Stream#peek(java.util.function.Consumer) introduce a peek extension method for Iterable
and Iterator
. This method just consumes an element and produces an Iterable/Iterator providing the same elements as the source. This method is mainly interesting for debugging purposes.
static def <T> Iterable<T> peek(Iterable<T> iterable, (T)=>void action)
static def <T> Iterator<T> peek(Iterator<T> iterator, (T)=>void action)
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
To allow better conversion between PrimitiveInterator
sub-types and primitive streams, introduce internal interfaces for the primitive types int
, long
and double
providing a stream
method for creation of primitive streams. Let all own implementations of primitive iterators implement these interfaces.
Adjust the streamRemaining
methods in class PrimitiveIteratorExtensions
to check if iterators are instance of these interfaces and create streams from the stream
method when available.
This allows building up a stream pipeline entirely from the iterators, allowing the stream implementation (and JVM's JIT) to do it's magic.
Implement a zip
extension method for Iterable
and Iterator
. This method will produce a list of pairs from both sources by their index. This is known from other languages and frameworks, such as Haskell, Scala, Kotlin, or Eclipse Collections.
static def <T,V> Iterable<Pair<T,V>> zip(Iterable<? extends T>, Iterable<? extends V>)
static def <T,V,Y> Iterable<Y> zip(Iterable<? extends T>, Iterable<? extends V>, (T,V)=>Y merger)
static def <T,V> Iterator<Pair<T,V>> zip(Iterator<? extends T>, Iterator<? extends V>)
static def <T,V,Y> Iterator<Y> zip(Iterator<? extends T>, Iterator<? extends V>, (T,V)=>Y merger)
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
Add sonarcloud.io analysis to travis build.
Maybe add some badges to README with numbers on issues/bugs/vulnerabilities.
Add a new partitionBy
extension method for Iterable and Iterator to partition the elements provided by being instance of a given class or not.
static def <T,Y> Pair<List<Y>,List<T>> partitionBy(Iterable<T>, Class<Y>)
static def <T,Y,AT,AY,DT,DY> Pair<DY,DT> partitionBy(Iterable<T>, Class<Y>, Collector<? super T, AT, DT>, Collector<? super Y, AY, DY>)
static def <T,Y> Pair<List<Y>,List<T>> partitionBy(Iterator<T>, Class<Y>)
static def <T,Y,AT,AY,DT,DY> Pair<DY,DT> partitionBy(Iterator<T>, Class<Y>, Collector<? super T, AT, DT>, Collector<? super Y, AY, DY>)
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
Add a couple of extension combinator methods / terminal Methods to the PrimitiveIterator sub-interfaces.
The following methods seem to be the most interesting:
static def boolean anyMatch(PrimitiveIterator.OfInt intIterator, IntPredicate test)
static def boolean allMatch(PrimitiveIterator.OfInt intIterator, IntPredicate test)
static def boolean noneMatch(PrimitiveIterator.OfInt intIterator, IntPredicate test)
static def OptionalInt findFirst(PrimitiveIterator.OfInt intIterator, IntPredicate test)
static def OptionalInt findFirst(PrimitiveIterator.OfInt intIterator)
static def PrimitiveIterator.OfInt filter(PrimitiveIterator.OfInt intIterator, IntPredicate test)
static def OptionalInt reduce(PrimitiveIterator.OfInt intIterator, IntBinaryOperator op)
static def int reduce(PrimitiveIterator.OfInt intIterator, int identity, IntBinaryOperator op)
static def boolean anyMatch(PrimitiveIterator.OfLong longIterator, LongPredicate test)
static def boolean allMatch(PrimitiveIterator.OfLong longIterator, LongPredicate test)
static def boolean noneMatch(PrimitiveIterator.OfLong longIterator, LongPredicate test)
static def OptionalLong findFirst(PrimitiveIterator.OfLong longIterator, LongPredicate test)
static def OptionalLong findFirst(PrimitiveIterator.OfLong longIterator)
static def PrimitiveIterator.OfLong filter(PrimitiveIterator.OfLong longIterator, LongPredicate test)
static def OptionalLong reduce(PrimitiveIterator.OfLong longIterator, LongBinaryOperator op)
static def long reduce(PrimitiveIterator.OfLong longIterator, long identity, LongBinaryOperator op)
static def boolean anyMatch(PrimitiveIterator.OfDouble doubleIterator, DoublePredicate test)
static def boolean allMatch(PrimitiveIterator.OfDouble doubleIterator, DoublePredicate test)
static def boolean noneMatch(PrimitiveIterator.OfDouble doubleIterator, DoublePredicate test)
static def OptionalLong findFirst(PrimitiveIterator.OfDouble doubleIterator, DoublePredicate test)
static def OptionalLong findFirst(PrimitiveIterator.OfDouble doubleIterator)
static def PrimitiveIterator.OfDouble filter(PrimitiveIterator.OfDouble doubleIterator, DoublePredicate test)
static def OptionalDouble reduce(PrimitiveIterator.OfDouble doubleIterator, DoubleBinaryOperator op)
static def double reduce(PrimitiveIterator.OfDouble doubleIterator, double identity, DoubleBinaryOperator op)
If you want this ticket to be implemented, please give feedback, since it is only implemented on demand.
Add functionality to work with primitive values that are at the end of null-safe navigation chains. This can include the following functionality:
null
reference leads to a null
boxed primitivenull
reference leads to an empty Optionalnull
null
null
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.