Class Perspectives

java.lang.Object
com.rits.perspectives.Perspectives

public class Perspectives extends Object
Perspectives: an object instance of a class behaving differently according to the "view angle".
Author:
kostantinos.kougios

30 Nov 2009

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T, E extends T>
    E
    viewAs(Class<E> c, T o)
    Sample: if o is an instance of Product and c is OrderedProduct.class then this returns and instance of OrderedProduct.class which has equal field values to those of the instance of Product.
    <I, NI extends I, T extends Collection<I>, E extends Collection<NI>>
    E
    viewCollectionAs(E newCollection, Class<NI> perspectiveCollectionItemClass, T currentCollection)
    Sample: if o is a [ Products extends LinkedList<Product> ] then the returned instance is a [ OrderedProducts extends LinkedList<OrderedProduct> ].

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Perspectives

      public Perspectives(Cloner cloner)
  • Method Details

    • viewAs

      public <T, E extends T> E viewAs(Class<E> c, T o)
      Sample: if o is an instance of Product and c is OrderedProduct.class then this returns and instance of OrderedProduct.class which has equal field values to those of the instance of Product. In other words, the returned instance of OrderedProduct.class is the Product instance from the perspective of an OrderedProduct

      View an object o from the perspective of class c. (view o as an instance of c). c must be instanceof o.getClass()

      Type Parameters:
      T - the object
      E - this will be the returned type and it must be instanceof T. All properties of o will be copied to this instance.
      Parameters:
      c - the class of E. This is used to generate new instances of c
      o - the object that must be viewed from a different perspective
      Returns:
      the E perspective of o
    • viewCollectionAs

      public <I, NI extends I, T extends Collection<I>, E extends Collection<NI>> E viewCollectionAs(E newCollection, Class<NI> perspectiveCollectionItemClass, T currentCollection)
      Sample: if o is a [ Products extends LinkedList<Product> ] then the returned instance is a [ OrderedProducts extends LinkedList<OrderedProduct> ].

      View a collection o from the perspective of collection E.

      NOTE: order of the items might not be preserved, depending on the collection type

      Type Parameters:
      T - the type of the collection o
      I - the type of the elements of the collection o
      E - the type of the perspective collection
      NI - the type of the perspective's elements
      Parameters:
      newCollection - the collection to which the adapted instances should be added
      currentCollection - the collection with the instances to be adapted
      perspectiveCollectionItemClass - the class of the NI
      Returns:
      E, the collection from a different perspective or null if currentCollection is null