com.rits.perspectives
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
Method Summary |
|
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. |
|
viewCollectionAs(E newCollection,
Class<NI> perspectiveCollectionItemClass,
T currentCollection)
Sample: if o is a [ Products extends LinkedList ] then the returned instance
is a [ OrderedProducts extends LinkedList ]. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Perspectives
public Perspectives(Cloner cloner)
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 objectE
- 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 co
- 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 ] then the returned instance
is a [ OrderedProducts extends LinkedList ].
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 oI
- the type of the elements of the collection oE
- the type of the perspective collectionNI
- the type of the perspective's elements- Parameters:
newCollection
- the collection to which the adapted instances should be addedcurrentCollection
- the collection with the instances to be adaptedperspectiveCollectionItemClass
- the class of the NI
- Returns:
- E, the collection from a different perspective or null if currentCollection is null
Copyright © 2010. All Rights Reserved.