zondag 23 januari 2011

Not dead but very much alive!

It's been a while since I updated anything on the SennMagic project, but here it is!

Version 3.5 has some minor changes and additions in existing classes (DFCUtils, GeneralUtils) but most importantly:
The 'chainable' collections api!

Don't you just hate it when you are instantiating objects and you have to pass a Collection instance and you can't do it in one line because the collection needs one or more items in it, like this:

car.setPassengers(new ArrayList<Passenger>()); // you can only add an empty list
//so you have to do:
List<Passenger> passengers = new ArrayList<Passenger>();
passengers.add(new Passenger("Bart"));

That's all in the past with the chainable collections api!

The chainable collections api has extra methods (with very recognizable, straightforward names) to add/remove/replace items in the collections, but instead of the normal return value, it returns the collection itself.  This enables you to 'chain' actions like this:

//same as previous example:
car.setPassengers(new ChainableArrayList<Passenger>().put(new Passenger("Bart")));

I have created implementations for the most commonly used collections (+maps):
  • ChainableList extends List
    • ChainableArrayList extends ArrayList implements ChainableList
    • ChainableLinkedList extends LinkedList implements ChainableList
  • ChainableMap extends Map
    • ChainableHashMap extends HashMap implements ChainableMap
    • ChainableLinkedHashMap extends LinkedHashMap implements ChainableMap
    • ChainableTreeMap extends TreeMap implements ChainableMap
  • ChainableQueue extends Queue
    • ChainablePriorityQueue extends PriorityQueue implements ChainableQueue
  • ChainableSet extends Set
    • ChainableHashSet extends HashSet implements ChainableSet
    • ChainableLinkedHashSet extends LinkedHashSet implements ChainableSet
    • ChainableTreeSet extends TreeSet implements ChainableSet
It's already proven to be quite handy, especially when creating unit tests, in multiple projects, by multiple developers.

Get it while it's still hot! 


Geen opmerkingen:

Een reactie plaatsen