Welcome to Right Collections

Right Collections is simple but powerful framework implementing Ruby-style collections and closures with Java 5 features and fine object-oriented design.

Usage:

Key concept of Right Collection Framework is RightList interface. RightList extends List so you can use it as regular java.util.List instead of it. Assume, we need to implement application dealing with RSS-channels and items. We have two entities in relationship one-to-many.

// imports removed for simplicity

class Channel {
   private String title;
   private RightList<Item> items;
   // other fields here.

   //getters and setters here
}

// imports removed for simplicity

class Item implements Comparable<Item> {
    private String title;
    private Date date;
    private String description;
    // getters setters here

    // Defining netural order of items. Sorting items by date.
    public int compareTo(Item other) {
        return this.date.compareTo(other.date);
    }

    // Implementing equals
}

Somewhere in your code:

 ...
   channel.setItems(new RightListImpl());
 ...
   // Get max element from collection
   Item maxItem = channel.getItems().max();
   // do something with max element
 ...
   // remove item title = null
   channel.getItems().filter(new Predicate<Item>() {
      public Boolean apply(Item item) {
        return item.getTitle() != null;
      }
   });

   // print Items to console
   channel.getItems().filter(new Closure<Item>() {
      public Void apply(Item item) {
        System.out.println(item);
        return null;
      }
   });
 ...

You can create number of different predicates and closures and reuse them gracefully in your code. Also you can create own implementations of RightList interface. Also Rigth Collections Framework has implementation of RightSet and RightCollection interfaces.

Future:

  • add more features like sorting etc.
  • add some good transforming features.
  • add some factory for injecting implementations of RightList interface.
  • implement beautiful integration with Spring Framework
  • implement beautiful integration with Hibernate