|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.malai.mapping.MappingRegistry
public final class MappingRegistry
This registry allows to map source objects to target objects using mappings.
When a source object is modified, its corresponding mappings are executed to
update the corresponding target objects.
This file is part of Malai.
Copyright (c) 2009-2012 Arnaud BLOUIN
Malai is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
Malai is distributed without any warranty; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
05/15/2010
Field Summary | |
---|---|
private java.util.Map<java.lang.Object,java.util.List<IMapping>> |
invertedMultiMappings
|
private java.util.Map<java.lang.Object,IMapping> |
invertedUniqueMappings
|
private java.util.Map<java.lang.Object,java.util.List<IMapping>> |
multiMappings
Contains objects and their mappings. |
static IMappingRegistry |
REGISTRY
The singleton of the class. |
private java.util.Map<java.lang.Object,IMapping> |
uniqueMappings
Contains objects and their unique mapping. |
Constructor Summary | |
---|---|
private |
MappingRegistry()
Creates a mapping registry. |
Method Summary | ||
---|---|---|
void |
addMapping(IMapping mapping)
Adds a mapping to the registry. |
|
private static void |
addMappings(IMapping mapping,
java.lang.Object object,
java.util.Map<java.lang.Object,IMapping> uniqueMap,
java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMap)
Is used by method addMapping(mapping). |
|
private static java.util.List<IMapping> |
getMapping(java.lang.Object object,
java.util.Map<java.lang.Object,IMapping> uniqueMap,
java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMap)
|
|
java.util.List<IMapping> |
getMappingFromSource(java.lang.Object source)
|
|
java.util.List<IMapping> |
getMappingFromTarget(java.lang.Object target)
|
|
|
getSourceFromTarget(java.lang.Object target,
java.lang.Class<T> sourceType)
|
|
|
getSrcOrTarFromTarOrSrc(boolean fromSource,
java.lang.Object object,
java.lang.Class<T> type)
Allows to get the source or the target object of a mapping using the target or the source object. |
|
|
getTargetFromSource(java.lang.Object source,
java.lang.Class<T> targetType)
|
|
void |
initMappings()
At start, mappings must be executed one time to initialise the mapping. |
|
void |
onListCleaned(java.lang.Object list)
Executes the mapping when all the elements of the source were removed. |
|
|
onObjectAdded(IActiveList<T> list,
T object,
int index)
Executes mappings related to the given list for the addition of an object. |
|
void |
onObjectModified(java.lang.Object object)
Executes mappings related to the given list for the modification of an object. |
|
|
onObjectMoved(IActiveList<T> list,
T object,
int srcIndex,
int targetIndex)
Executes mappings related to the given list for the move of an object. |
|
void |
onObjectRemoved(IActiveList<?> list,
java.lang.Object object,
int index)
Executes mappings related to the given list for the deletion of an object. |
|
|
onObjectReplaced(IUnary<T> object,
T replacedObject)
Executes the mapping when an object has been replaced by an other one. |
|
private static void |
printMappings(java.lang.StringBuilder buf,
java.util.Map<java.lang.Object,IMapping> uMappings,
java.util.Map<java.lang.Object,java.util.List<IMapping>> mMappings)
This method is used by the toString function to print the register. |
|
protected void |
removeMappings(java.lang.Object object,
java.lang.Class<? extends IMapping> clazz,
java.util.Map<java.lang.Object,IMapping> uniqueMaps,
java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMaps,
boolean removeUsingTarget,
boolean removeOppositeMappings)
Remove the mappings of the given type and using the given object from the hash maps. |
|
void |
removeMappingsUsingSource(java.lang.Object source)
Removes the mappings that use the given object as source. |
|
void |
removeMappingsUsingSource(java.lang.Object source,
java.lang.Class<? extends IMapping> clazz)
Removes the mappings of the given type that use the given object as source. |
|
protected void |
removeMappingsUsingSource(java.lang.Object source,
java.lang.Class<? extends IMapping> clazz,
boolean removeTargetMappings)
Idem than removeMappingsUsingSource. |
|
void |
removeMappingsUsingTarget(java.lang.Object target)
Removes the mappings that use the given object as target. |
|
void |
removeMappingsUsingTarget(java.lang.Object target,
java.lang.Class<? extends IMapping> clazz)
Removes the mappings that use the given object as target. |
|
protected void |
removeMappingsUsingTarget(java.lang.Object target,
java.lang.Class<? extends IMapping> clazz,
boolean removeSourceMappings)
Idem than removeMappingsUsingTarget. |
|
private void |
removeOppositeMapping(IMapping mapping,
boolean removeUsingTarget)
|
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final IMappingRegistry REGISTRY
private java.util.Map<java.lang.Object,IMapping> uniqueMappings
private java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMappings
private java.util.Map<java.lang.Object,IMapping> invertedUniqueMappings
private java.util.Map<java.lang.Object,java.util.List<IMapping>> invertedMultiMappings
Constructor Detail |
---|
private MappingRegistry()
Method Detail |
---|
public void initMappings()
IMappingRegistry
initMappings
in interface IMappingRegistry
public <T> T getTargetFromSource(java.lang.Object source, java.lang.Class<T> targetType)
getTargetFromSource
in interface IMappingRegistry
source
- The source object used to find the target object matching the given class.targetType
- The class of the target object to find.
public <T> T getSourceFromTarget(java.lang.Object target, java.lang.Class<T> sourceType)
getSourceFromTarget
in interface IMappingRegistry
target
- The target object used to find the source object matching the given class.sourceType
- The class of the source object to find.
public <T> T getSrcOrTarFromTarOrSrc(boolean fromSource, java.lang.Object object, java.lang.Class<T> type)
fromSource
- True: the target object while be searched. Otherwise, the source object.object
- The source or target object of the mapping used to get the target or source object.type
- The class of the object to return.
public java.util.List<IMapping> getMappingFromSource(java.lang.Object source)
source
- This object is used to find the mapping that uses is as a source object.
public java.util.List<IMapping> getMappingFromTarget(java.lang.Object target)
target
- This object is used to find the mapping that uses is as a target object.
private static java.util.List<IMapping> getMapping(java.lang.Object object, java.util.Map<java.lang.Object,IMapping> uniqueMap, java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMap)
public void addMapping(IMapping mapping)
IMappingRegistry
addMapping
in interface IMappingRegistry
mapping
- The mapping to add.private static void addMappings(IMapping mapping, java.lang.Object object, java.util.Map<java.lang.Object,IMapping> uniqueMap, java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMap)
mapping
- The mapping to add.object
- The object that will be used as key in the map.uniqueMap
- The map that contains unique mappings.multiMap
- The map that contains multiple mappings.public <T> void onObjectAdded(IActiveList<T> list, T object, int index)
IMappingRegistry
onObjectAdded
in interface IMappingRegistry
list
- The modified source list.object
- The added object.index
- The position where the object has been added.public void onObjectRemoved(IActiveList<?> list, java.lang.Object object, int index)
IMappingRegistry
onObjectRemoved
in interface IMappingRegistry
list
- The modified source list.object
- The deleted object.index
- The position where the object has been deleted.public void onListCleaned(java.lang.Object list)
IMappingRegistry
onListCleaned
in interface IMappingRegistry
list
- The list before the cleaning, i.e. it still contains all the elements in
order to know which elements have been removed.public <T> void onObjectMoved(IActiveList<T> list, T object, int srcIndex, int targetIndex)
IMappingRegistry
onObjectMoved
in interface IMappingRegistry
list
- The modified source list.object
- The move object.srcIndex
- The source position of the object.targetIndex
- The target position of the object.public <T> void onObjectReplaced(IUnary<T> object, T replacedObject)
IMappingRegistry
onObjectReplaced
in interface IMappingRegistry
object
- The singleton that contains the new object.replacedObject
- The old object contained in the singleton that has been replaced.public void onObjectModified(java.lang.Object object)
IMappingRegistry
onObjectModified
in interface IMappingRegistry
object
- The modified object.public void removeMappingsUsingSource(java.lang.Object source, java.lang.Class<? extends IMapping> clazz)
IMappingRegistry
removeMappingsUsingSource
in interface IMappingRegistry
source
- A source object of the mappings to remove.clazz
- The type of the mappings to remove.protected void removeMappingsUsingSource(java.lang.Object source, java.lang.Class<? extends IMapping> clazz, boolean removeTargetMappings)
removeTargetMappings
- True: the inverted hash maps will be cleaned too.public void removeMappingsUsingTarget(java.lang.Object target, java.lang.Class<? extends IMapping> clazz)
IMappingRegistry
removeMappingsUsingTarget
in interface IMappingRegistry
target
- A target object of the mappings to remove.clazz
- The type of the mappings to remove.protected void removeMappingsUsingTarget(java.lang.Object target, java.lang.Class<? extends IMapping> clazz, boolean removeSourceMappings)
removeSourceMappings
- True: the standard hash maps will be cleaned too.protected void removeMappings(java.lang.Object object, java.lang.Class<? extends IMapping> clazz, java.util.Map<java.lang.Object,IMapping> uniqueMaps, java.util.Map<java.lang.Object,java.util.List<IMapping>> multiMaps, boolean removeUsingTarget, boolean removeOppositeMappings)
object
- The source or target object of the mappings to remove.clazz
- The type of the mappings to remove.uniqueMaps
- The hash map that contains the unique mappings.multiMaps
- The hash map that contains the mappings contained into a list.removeUsingTarget
- True: will remove the mappings by considering the given object as a target object of the mappings.removeOppositeMappings
- True: mappings contains is the opposite hash maps will be removed too.public java.lang.String toString()
toString
in class java.lang.Object
private static void printMappings(java.lang.StringBuilder buf, java.util.Map<java.lang.Object,IMapping> uMappings, java.util.Map<java.lang.Object,java.util.List<IMapping>> mMappings)
private void removeOppositeMapping(IMapping mapping, boolean removeUsingTarget)
public void removeMappingsUsingSource(java.lang.Object source)
IMappingRegistry
removeMappingsUsingSource
in interface IMappingRegistry
source
- A source object of the mappings to remove.public void removeMappingsUsingTarget(java.lang.Object target)
IMappingRegistry
removeMappingsUsingTarget
in interface IMappingRegistry
target
- A target object of the mappings to remove.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |