Class VersionedModelInfos<M extends IModel>

java.lang.Object
net.ssehub.easy.basics.modelManagement.VersionedModelInfos<M>
Type Parameters:
M - the specific type of model

public class VersionedModelInfos<M extends IModel> extends Object
Stores model information objects of the same version.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • VersionedModelInfos

      public VersionedModelInfos(Version version)
      Creates a new versioned model information container.
      Parameters:
      version - the version of this container (may be null)
  • Method Details

    • add

      public void add(ModelInfo<M> info)
      Adds a model information object.
      Parameters:
      info - the object to be added
      Throws:
      IllegalArgumentException - if the version of info does not match version or the name of info does not match the name of the first stored model information object (if there is any)
    • isSame

      public static final boolean isSame(URI uri1, URI uri2)
      Checks two URIs for equality.
      Parameters:
      uri1 - the first URI (may be null)
      uri2 - the second URI (may be null)
      Returns:
      true if both are the same, false else
    • get

      public ModelInfo<M> get(int index)
      Returns the specified model information object.
      Parameters:
      index - the index of the object to be returned
      Returns:
      the specified object
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=size()
    • get

      public ModelInfo<M> get(M model)
      Returns the model information objects with model as resolved model.
      Parameters:
      model - the (resolved) model to search for
      Returns:
      the model information object or null if there is none
    • get

      public ModelInfo<M> get(URI uri)
      Returns the model information objects with uri as location.
      Parameters:
      uri - the URI to search for
      Returns:
      the model information object or null if there is none
    • size

      public int size()
      Returns the number of contained version information objects.
      Returns:
      the number of version information objects
    • remove

      public ModelInfo<M> remove(int index)
      Removes the specified model information object.
      Parameters:
      index - the index of the object to be returned
      Returns:
      the removed object
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=size()
    • clear

      public void clear()
      Removes all stored model information objects.
    • remove

      public boolean remove(ModelInfo<M> info)
      Removes the specified model information object.
      Parameters:
      info - the information object to be removed
      Returns:
      true if successful false else
    • getVersion

      public Version getVersion()
      Returns the version all information objects in this instance are assigned to.
      Returns:
      the version
    • getByEqualUri

      public List<ModelInfo<M>> getByEqualUri(URI uri)
      Returns the model information with the exact match to uri.
      Parameters:
      uri - the URI to match with (may be null then the first information object is returned)
      Returns:
      the matching model information (or null if none matches)
    • getByClosestUri

      public ModelInfo<M> getByClosestUri(URI uri, List<String> modelPath)
      Returns the model information with the closest match to uri, i.e. in closest in the same hierarchy path.
      Parameters:
      uri - the URI to match with (may be null then the first information object is returned)
      modelPath - additional URIs prefixes which shall be considered for importing, similar to the Java classpath, may be null
      Returns:
      the matching model information (or null if none matches)
    • getByClosestUri

      public static <M extends IModel> ModelInfo<M> getByClosestUri(List<ModelInfo<M>> infos, URI uri, List<String> modelPath)
      Returns the model information from infos with the closest match to uri, i.e. in closest in the same hierarchy path.
      Type Parameters:
      M - the model type
      Parameters:
      infos - the information objects to be considered
      uri - the URI to match with (may be null then the first information object is returned)
      modelPath - additional URIs prefixes which shall be considered for importing, similar to the Java classpath, may be null
      Returns:
      the matching model information (or null if none matches)
    • search

      private static <M extends IModel> ModelInfo<M> search(List<ModelInfo<M>> infos, String searchUriText, List<String> modelPath)
      Searches for the best match according to the IVML search conventions, first down along the given URI, then up along the hierarchy.
      Type Parameters:
      M - the model type
      Parameters:
      infos - the information objects to be considered
      searchUriText - the search folder URI as text
      modelPath - additional URIs prefixes which shall be considered for importing, similar to the Java classpath, may be null
      Returns:
      the matching model information (or null if none matches)
    • searchOnParentLevel

      private static <M extends IModel> ModelInfo<M> searchOnParentLevel(List<ModelInfo<M>> infos, URI uri, List<String> modelPath)
      Searches for the best match within the parent-parent folders of uri if that folder starts with ".". This enables cross-links among parent models according to the convention EASy places imported IVML files.
      Type Parameters:
      M - the model type
      Parameters:
      infos - the information objects to be considered
      uri - the URI to start searching
      modelPath - additional URIs prefixes which shall be considered for importing, similar to the Java classpath, may be null
      Returns:
      the matching model information (or null if none matches)
    • searchOnSameFolderLevel

      private static <M extends IModel> ModelInfo<M> searchOnSameFolderLevel(List<ModelInfo<M>> infos, URI uri, List<String> modelPath)
      Search in folders on the level of the parent folder of uri.
      Type Parameters:
      M - the model type
      Parameters:
      infos - the information objects to be considered
      uri - the URI to start searching
      modelPath - additional URIs prefixes which shall be considered for importing, similar to the Java classpath, may be null
      Returns:
      the matching model information but only if this is unique
    • isFileScheme

      public static boolean isFileScheme(URI uri)
      Returns whether the given URI is a file (file scheme).
      Parameters:
      uri - the URI to test for
      Returns:
      true if it is a file, false else
    • isMatching

      private static boolean isMatching(String searchUriText, List<String> modelPath, String importUriText, boolean contained)
      Checks whether the searchUriText (with precedence) ore one of the modelPath URI paths match importUri, i.e. whether importUri is an appropriate URI for import.
      Parameters:
      searchUriText - the textual URI of the model stating the import
      modelPath - additional URI paths, may be null
      importUriText - the URI path of the model being considered for import
      contained - prefer contained or containing URIs
      Returns:
      true if the specified data match, false if not
    • isMatching

      private static boolean isMatching(String searchUriText, String importUriText, boolean contained)
      Checks whether the searchUriText and importUri match.
      Parameters:
      searchUriText - the textual URI of the model stating the import
      importUriText - the URI path of the model being considered for import
      contained - prefer contained or containing URIs
      Returns:
      true if the specified data match, false if not
    • pathWithoutLastFragment

      public static String pathWithoutLastFragment(URI uri)
      Returns the prefix path of the given uri without the last fragment.
      Parameters:
      uri - the URI to be considered
      Returns:
      the prefix path if possible, the uri else
    • toList

      public List<ModelInfo<M>> toList(List<ModelInfo<M>> list)
      Adds all model information objects to the given list.
      Parameters:
      list - the list to be modified as a side effect (may be null then a list is created)
      Returns:
      list or the created list
    • toString

      public String toString()
      Returns the textual representation of this instance.
      Overrides:
      toString in class Object
      Returns:
      the textual representation
    • find

      public ModelInfo<M> find(URI uri)
      Finds a model information object based on a give URI.
      Parameters:
      uri - the URI to find the information object
      Returns:
      the information object or null if not found
    • find

      public static <M extends IModel> VersionedModelInfos<M> find(List<VersionedModelInfos<M>> infos, Version version)
      Retrieves the version model information container with the specified version.
      Type Parameters:
      M - the specific type of model
      Parameters:
      infos - a list of model information containers (may be null)
      version - the version to retrieve
      Returns:
      the first matching container
    • maxVersion

      public static <M extends IModel> ModelInfo<M> maxVersion(List<ModelInfo<M>> list)
      Returns the model information object with highest version number from list. Unspecified versions are treated as implicit minimum.
      Type Parameters:
      M - the actual model type
      Parameters:
      list - the list of model information objects to determine the maximum from (may be null)
      Returns:
      the maximum version