Package com.atomicleopard.expressive

Expressive is a java library designed to enable simple and easily read usage of the Java Collections API.

See: Description

Package com.atomicleopard.expressive Description

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.

Expressive.list(Object...)

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);
 }
 

Expressive.map(Object...)

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.