Class 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:
    1. Insertion of elements using put(EObject, Comment, ContainableModelElement).
    2. Defining the sequence by assigning index positions to the EObjects using setIndex(EObject, int).
    3. Reordering a sequence of comments and containable model elements using the Comparator property of this class.
    Note: This approach is suboptimal
    Author:
    Holger Eichelberger
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the data in this object.
      int compare​(net.ssehub.easy.varModel.model.ContainableModelElement element1, net.ssehub.easy.varModel.model.ContainableModelElement element2)
      Compares its two arguments for order.
      private long determineIndex​(net.ssehub.easy.varModel.model.ContainableModelElement element)
      Determines the actual (virtual) index of the given element.
      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 from key to comment (optional) and element.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • ContainableElementsMapAndComparator

        public ContainableElementsMapAndComparator()
        Creates an instance of this class.
    • 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 from key to comment (optional) and element. (phase 1)
        Parameters:
        key - the key object as parsed by xText from the input file
        comment - 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 that key is not accessible after execution of this method. (phase 2)
        Parameters:
        key - the key object
        index - the index of key in 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:
        compare in interface java.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 given element.
        Parameters:
        element - the element
        Returns:
        the (virtual) target index for sorting
      • clear

        public void clear()
        Clears the data in this object.