Package 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".
-
-
Constructor Summary
Constructors Constructor Description Perspectives(Cloner cloner)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,E extends T>
EviewAs(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>>
EviewCollectionAs(E newCollection, Class<NI> perspectiveCollectionItemClass, T currentCollection)
Sample: if o is a [ Products extends LinkedList of Product ] then the returned instance is a [ OrderedProducts extends LinkedList of OrderedProduct ].
-
-
-
Constructor Detail
-
Perspectives
public Perspectives(Cloner cloner)
-
-
Method Detail
-
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 of Product ] then the returned instance is a [ OrderedProducts extends LinkedList of 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 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
-
-