Class VersionedModelInfos<M extends IModel>

  • Type Parameters:
    M - the specific type of model

    public class VersionedModelInfos<M extends IModel>
    extends java.lang.Object
    Stores model information objects of the same version.
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Constructor Description
      VersionedModelInfos​(Version version)
      Creates a new versioned model information container.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(ModelInfo<M> info)
      Adds a model information object.
      void clear()
      Removes all stored model information objects.
      ModelInfo<M> find​(java.net.URI uri)
      Finds a model information object based on a give URI.
      static <M extends IModel>
      VersionedModelInfos<M>
      find​(java.util.List<VersionedModelInfos<M>> infos, Version version)
      Retrieves the version model information container with the specified version.
      ModelInfo<M> get​(int index)
      Returns the specified model information object.
      ModelInfo<M> get​(java.net.URI uri)
      Returns the model information objects with uri as location.
      ModelInfo<M> get​(M model)
      Returns the model information objects with model as resolved model.
      ModelInfo<M> getByClosestUri​(java.net.URI uri, java.util.List<java.lang.String> modelPath)
      Returns the model information with the closest match to uri, i.e.
      static <M extends IModel>
      ModelInfo<M>
      getByClosestUri​(java.util.List<ModelInfo<M>> infos, java.net.URI uri, java.util.List<java.lang.String> modelPath)
      Returns the model information from infos with the closest match to uri, i.e.
      java.util.List<ModelInfo<M>> getByEqualUri​(java.net.URI uri)
      Returns the model information with the exact match to uri.
      Version getVersion()
      Returns the version all information objects in this instance are assigned to.
      static boolean isFileScheme​(java.net.URI uri)
      Returns whether the given URI is a file (file scheme).
      private static boolean isMatching​(java.lang.String searchUriText, java.lang.String importUriText, boolean contained)
      Checks whether the searchUriText and importUri match.
      private static boolean isMatching​(java.lang.String searchUriText, java.util.List<java.lang.String> modelPath, java.lang.String importUriText, boolean contained)
      Checks whether the searchUriText (with precedence) ore one of the modelPath URI paths match importUri, i.e.
      static boolean isSame​(java.net.URI uri1, java.net.URI uri2)
      Checks two URIs for equality.
      static <M extends IModel>
      ModelInfo<M>
      maxVersion​(java.util.List<ModelInfo<M>> list)
      Returns the model information object with highest version number from list.
      static java.lang.String pathWithoutLastFragment​(java.net.URI uri)
      Returns the prefix path of the given uri without the last fragment.
      ModelInfo<M> remove​(int index)
      Removes the specified model information object.
      boolean remove​(ModelInfo<M> info)
      Removes the specified model information object.
      private static <M extends IModel>
      ModelInfo<M>
      search​(java.util.List<ModelInfo<M>> infos, java.lang.String searchUriText, java.util.List<java.lang.String> modelPath)
      Searches for the best match according to the IVML search conventions, first down along the given URI, then up along the hierarchy.
      private static <M extends IModel>
      ModelInfo<M>
      searchOnParentLevel​(java.util.List<ModelInfo<M>> infos, java.net.URI uri, java.util.List<java.lang.String> modelPath)
      Searches for the best match within the parent-parent folders of uri if that folder starts with ".".
      private static <M extends IModel>
      ModelInfo<M>
      searchOnSameFolderLevel​(java.util.List<ModelInfo<M>> infos, java.net.URI uri, java.util.List<java.lang.String> modelPath)
      Search in folders on the level of the parent folder of uri.
      int size()
      Returns the number of contained version information objects.
      java.util.List<ModelInfo<M>> toList​(java.util.List<ModelInfo<M>> list)
      Adds all model information objects to the given list.
      java.lang.String toString()
      Returns the textual representation of this instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • VersionedModelInfos

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

      • add

        public void add​(ModelInfo<M> info)
        Adds a model information object.
        Parameters:
        info - the object to be added
        Throws:
        java.lang.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​(java.net.URI uri1,
                                           java.net.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:
        java.lang.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​(java.net.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:
        java.lang.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 java.util.List<ModelInfo<M>> getByEqualUri​(java.net.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​(java.net.URI uri,
                                            java.util.List<java.lang.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 IModelModelInfo<M> getByClosestUri​(java.util.List<ModelInfo<M>> infos,
                                                                      java.net.URI uri,
                                                                      java.util.List<java.lang.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 IModelModelInfo<M> search​(java.util.List<ModelInfo<M>> infos,
                                                              java.lang.String searchUriText,
                                                              java.util.List<java.lang.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 IModelModelInfo<M> searchOnParentLevel​(java.util.List<ModelInfo<M>> infos,
                                                                           java.net.URI uri,
                                                                           java.util.List<java.lang.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 IModelModelInfo<M> searchOnSameFolderLevel​(java.util.List<ModelInfo<M>> infos,
                                                                               java.net.URI uri,
                                                                               java.util.List<java.lang.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​(java.net.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​(java.lang.String searchUriText,
                                          java.util.List<java.lang.String> modelPath,
                                          java.lang.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​(java.lang.String searchUriText,
                                          java.lang.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 java.lang.String pathWithoutLastFragment​(java.net.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 java.util.List<ModelInfo<M>> toList​(java.util.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 java.lang.String toString()
        Returns the textual representation of this instance.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the textual representation
      • find

        public ModelInfo<M> find​(java.net.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 IModelVersionedModelInfos<M> find​(java.util.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 IModelModelInfo<M> maxVersion​(java.util.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