Class ContainableElementsMapAndComparator
- java.lang.Object
-
- de.uni_hildesheim.sse.translation.ContainableElementsMapAndComparator
-
- All Implemented Interfaces:
java.util.Comparator<net.ssehub.easy.varModel.model.ContainableModelElement>
class ContainableElementsMapAndComparator extends java.lang.Object implements java.util.Comparator<net.ssehub.easy.varModel.model.ContainableModelElement>A helper class which supports ordering of containable model elements. Basically, the original sequence can be obtained from the grammar. Typically, this sequence can not be used for entirely resolving all types due to dependencies among the individual elements. However, correctly resolving the type dependencies leads to a different insertion sequence in the resulting project. Therefore, this helper class supports reordering the already inserted elements (and keeping the existing implementation). This works in three phases whereby each phase must be completed before entering the next phase as in particular the second phase changes the internal link structure:- Insertion of elements using
put(EObject, Comment, ContainableModelElement). - Defining the sequence by assigning index positions to the
EObjectsusingsetIndex(EObject, int). - Reordering a sequence of comments and containable model elements using the
Comparatorproperty of this class.
- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classContainableElementsMapAndComparator.DataStores internal data to be assigned to a key.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Object,ContainableElementsMapAndComparator.Data>mapStores theEObject-ContainableElementsMapAndComparator.DataorContainableModelElement-ContainableElementsMapAndComparator.Datamappings.
-
Constructor Summary
Constructors Constructor Description ContainableElementsMapAndComparator()Creates an instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the data in this object.intcompare(net.ssehub.easy.varModel.model.ContainableModelElement element1, net.ssehub.easy.varModel.model.ContainableModelElement element2)Compares its two arguments for order.private longdetermineIndex(net.ssehub.easy.varModel.model.ContainableModelElement element)Determines the actual (virtual) index of the givenelement.voidput(org.eclipse.emf.ecore.EObject key, net.ssehub.easy.varModel.model.Comment comment, net.ssehub.easy.varModel.model.ContainableModelElement element)Adds a mapping fromkeytocomment(optional) andelement.voidsetIndex(org.eclipse.emf.ecore.EObject key, int index)Assigns the given index taken from the sequence of key objects to the comment or element in the assigned data.
-
-
-
Field Detail
-
map
private java.util.Map<java.lang.Object,ContainableElementsMapAndComparator.Data> map
Stores theEObject-ContainableElementsMapAndComparator.DataorContainableModelElement-ContainableElementsMapAndComparator.Datamappings.
-
-
Method Detail
-
put
public void put(org.eclipse.emf.ecore.EObject key, net.ssehub.easy.varModel.model.Comment comment, net.ssehub.easy.varModel.model.ContainableModelElement element)Adds a mapping fromkeytocomment(optional) andelement. (phase 1)- Parameters:
key- the key object as parsed by xText from the input filecomment- the comment instance (may be null)element- the element instance
-
setIndex
public void setIndex(org.eclipse.emf.ecore.EObject key, int index)Assigns the given index taken from the sequence of key objects to the comment or element in the assigned data. This method changes the linking so thatkeyis not accessible after execution of this method. (phase 2)- Parameters:
key- the key objectindex- the index ofkeyin its containing data structure
-
compare
public int compare(net.ssehub.easy.varModel.model.ContainableModelElement element1, net.ssehub.easy.varModel.model.ContainableModelElement element2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Unknown elements will be treated as if the smallest possible index has been assigned to them. (phase 3)- Specified by:
comparein interfacejava.util.Comparator<net.ssehub.easy.varModel.model.ContainableModelElement>- Parameters:
element1- the first element to be compared.element2- the second element to be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
determineIndex
private long determineIndex(net.ssehub.easy.varModel.model.ContainableModelElement element)
Determines the actual (virtual) index of the givenelement.- Parameters:
element- the element- Returns:
- the (virtual) target index for sorting
-
clear
public void clear()
Clears the data in this object.
-
-