Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrucz/colleague
Simple, easy-to-use Java API that allows functional interactions with collections.
https://github.com/andrucz/colleague
Last synced: 28 days ago
JSON representation
Simple, easy-to-use Java API that allows functional interactions with collections.
- Host: GitHub
- URL: https://github.com/andrucz/colleague
- Owner: andrucz
- Created: 2013-01-02T17:07:54.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2016-11-05T15:43:41.000Z (about 8 years ago)
- Last Synced: 2024-04-15T00:41:42.229Z (9 months ago)
- Language: Java
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
colleague
=========Simple, easy-to-use Java API that allows functional interactions with collections. Operations can be run over elements of a collection, considering a predicate.
There is a set of predefined predicates and operations and user can implement any others.
Simple predicates can be combined to build complex predicates.
Examples
---------Consider a list of strings.
Get the elements that start with "Foo":
```java
List l = Colleague.list(list, new StartsWithPredicate("Foo"));List l = list(list, startsWith("Foo"));
```Get the second element that does not end with "bar":
```java
String second = Colleague.get(list, 1, new NotPredicate(new EndsWithPredicate("bar"));String second = get(list, 1, not(endsWith("bar")));
```Print all elements that are in upper case:
```java
Colleague.each(list, new UpperCasePredicate(), new PrintOperation(System.out));each(list, isUpper(), new PrintOperation(System.out));
```Execute some custom operation in elements that are in lower case:
```java
Operation myOperation = new Operation() {@Override
public void execute(String element) throws OperationException {
// interesting stuff
}};
Colleague.each(list, new LowerCasePredicate(), myOperation);
each(list, isLower(), myOperation);
```Execute the operation in all elements:
```java
Colleague.each(list, myOperation);each(list, myOperation);
```Remove all null elements from a list:
```java
Colleague.remove(list, new IsNullPredicate());remove(list, isNull());
```Add to a list all elements from another list that are greater than 10:
```java
Colleague.add(list, anotherList, new GreaterThanPredicate(10));add(list, anotherList, greaterThan(10));
```Count the elements that are between 10 and 20:
```java
int c = Colleague.count(list, new BetweenPredicate(10, 20));int c = count(list, between(10, 20));
```Verify if there is a element in the list that are not contained in another list:
```java
boolean b = Colleague.contains(list, new NotPredicate(new ContainedInPredicate(anotherList)));boolean b = contains(list, not(containedIn(anotherList)));
```Convert a list of string to a list with the length of each string:
```java
ElementConverter myConverter = new ElementConverter() {
@Override
public Integer convert(String element) {
return element.length();
}
}List lengths = Colleague.convert(list, myConverter);
```Convert only non null elements:
```java
List lengths = Colleague.convert(list, new NotPredicate(new IsNullPredicate()), myConverter);List lengths = convert(list, not(isNull()), myConverter);
```