Expressive is a java library designed to enable simple and easily read usage
of the Java Collections API.See: Description
| Interface | Description |
|---|---|
| EList<T> | |
| ETransformer<From,To> |
ETransformer defines a consistent pattern for converting an object of
one type to an object of another. |
| Class | Description |
|---|---|
| Cast |
Utility class which provides casting operations.
|
| EListImpl<T> |
Implementation of the
EList interface. |
| Expressive |
Expressive is designed to allow coders to write more expressive code, focusing on what they want to do with collections of objects, rather than the mechanics of the manipulation of the Java
Collections API. |
| Expressive.Comparators |
Provides common implementations of comparators.
|
| Expressive.Filter |
Filter operations return views on an Iterable or Collection by applying a given
EPredicate to them. |
| Expressive.Predicate |
Provides common implementations of
EPredicate. |
| Expressive.Transformers |
Provides convenience access to
ETransformers that are of common use. |
| IteratorTransformer<In,Out> |
IteratorTransformer can be used to effectively iterate over an
Iterator and convert the items to another type. |
| MapKeys<K> |
MapKeys is used to construct maps in a fluid manner. |
| ReflectUtil |
This exists to remove the dependency Expressive had on cglib, it is not recommended to use this class, it is likely to change/disappear in the future.
|
Expressive is a java library designed to enable simple and easily read usage
of the Java Collections API.
Java provides a collections API which is effective and powerful, but can be cumbersome for simple usages. This can often result in a lack of clarity of the intention of code.
Expressive provides methods to allow for simple but powerful interactions with java collections so that the focus of your code can be its function, rather than the mechanics of java collections.
As an example, consider a method which takes a collection as a parameter, for example a list. While in all likelihood your application code will only invoke the method from a few places, you will more than likely be invoking the same method tens of times from unit tests.
In this situation the collections you wish to pass in are well defined and understood. As such a creating collections in a way that is easily readable has more value than a more formal collection creation strategy.
List Example - the stock standard way:
public void standardLookingTest() {
PhoneNumber ph1 = new PhoneNumber("1234-5555");
PhoneNumber ph2 = new PhoneNumber("1234-6666");
PhoneNumber ph3 = new PhoneNumber("1234-7777");
List<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
phoneNumbers.add(ph1);
phoneNumbers.add(ph2);
phoneNumbers.add(ph3);
String result = concatenatePhoneNumbers(phoneNumbers);
}
List example - the Expressive.list(Object...) method:
public void succinctTest() {
PhoneNumber ph1 = new PhoneNumber("1234-5555");
PhoneNumber ph2 = new PhoneNumber("1234-6666");
PhoneNumber ph3 = new PhoneNumber("1234-7777");
List<PhoneNumber> phoneNumbers = list(ph1, ph2, ph3);
String result = concatenatePhoneNumbers(phoneNumbers);
}
While convenience methods for lists are useful, the above usage would have been equally met by Arrays.asList . In this example, we will see the way Expressive can create maps, which has no analogy. In particular, maps are useful for static reference data and lookups, but creation of these lookups is usually cumbersome.
Reference map creation - the standard way:
public static Map<String, String> testMapData;
Copyright © 2013 Atomic Leopard. All Rights Reserved.