Class ModelInfo<M extends IModel>

  • Type Parameters:
    M - the specific model type
    All Implemented Interfaces:
    IModelData

    public class ModelInfo<M extends IModel>
    extends java.lang.Object
    implements IModelData
    Stores high-level information about an available (possibly unresolved) model.
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Constructor Description
      ModelInfo()
      Internal constructor for marking pseudo instances.
      ModelInfo​(java.lang.String name, Version version, IModelLoader<M> loader, java.net.URI location, java.util.List<ModelImport<M>> imp)
      Creates a model information object.
      ModelInfo​(M model, java.net.URI location)
      Creates a model information object.
      ModelInfo​(M model, java.net.URI location, IModelLoader<M> loader)
      Creates a model information object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void adjustTimestamp()
      Adjusts the timestamp according to the currently resolved instance.
      private java.net.URI composeCommentsURI​(java.util.Locale locale, boolean base)
      Composes an URI for the comments locale.
      private java.lang.String composeLocaleCommentsName​(java.lang.String name, java.util.Locale locale)
      Composes a comments file name based on a given locale.
      static <M extends IModel>
      boolean
      equals​(ModelInfo<M> info, java.lang.String name, Version version, java.net.URI location)
      Returns whether i1 and the explicit given information are equal, i.e., point to the same model.
      static <M extends IModel>
      boolean
      equals​(ModelInfo<M> i1, ModelInfo<M> i2)
      Returns whether i1 and i2 are equal, i.e., point to the same model.
      java.net.URI getBaseCommentsResource()
      Returns the URI to the actual base comments text resource.
      java.net.URI getCommentsResource()
      Returns the URI to the actual comments text resource.
      java.net.URI getDefaultBaseCommentsResource()
      Returns the URI to the actual base default comments text resource.
      java.net.URI getDefaultCommentsResource()
      Returns the URI to the default comments text resource.
      ModelImport<M> getImport​(int index)
      Returns the model import specified by index.
      int getImportsCount()
      Returns the number of imports.
      IModelLoader<M> getLoader()
      Stores the responsible loader.
      java.util.Locale getLocale()
      Returns the locale used for resolving the related model.
      java.net.URI getLocation()
      Returns the physical location of the model.
      java.lang.String getName()
      Returns the name of the model.
      M getResolved()
      Returns the resolved model.
      long getTimestamp()
      Returns the timestamp of the resolution.
      Version getVersion()
      Returns the version of the model.
      boolean isContainedIn​(java.lang.String path)
      Returns whether the location of this information object is contained in path.
      boolean isContainedIn​(java.net.URI uri)
      Returns whether the location of this information object is contained in uri.
      boolean isOutdated()
      Returns whether the represented model is outdated.
      boolean isResolved()
      Returns whether the related model was already resolved.
      java.lang.String nameVersionToString()
      Returns name and version as a string for output.
      static <M extends IModel>
      java.util.List<ModelInfo<M>>
      selectContained​(java.util.List<ModelInfo<M>> info, java.net.URI uri)
      Selects those information objects out of info which are contained in uri.
      static <M extends IModel>
      java.util.List<ModelInfo<M>>
      selectOutdated​(java.util.List<ModelInfo<M>> info, boolean requireResolved, java.net.URI uri)
      Returns the outdated model information objects (due to file change).
      (package private) void setLocale​(java.util.Locale locale)
      Stores the locale used while resolving the related model.
      (package private) void setResolved​(M resolved)
      Changes the resolved model.
      static java.lang.String toComparablePath​(java.net.URI uri)
      Turns the given uri into a comparable path.
      java.lang.String toString()
      Returns a textual representation of this instance.
      (package private) void updateModelLoader​(IModelLoader<M> loader)
      Updates the model loader (only if unset).
      • Methods inherited from class java.lang.Object

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

      • name

        private java.lang.String name
      • location

        private java.net.URI location
      • resolved

        private M extends IModel resolved
      • timestamp

        private long timestamp
      • locale

        private java.util.Locale locale
    • Constructor Detail

      • ModelInfo

        ModelInfo()
        Internal constructor for marking pseudo instances.
      • ModelInfo

        public ModelInfo​(M model,
                         java.net.URI location)
        Creates a model information object.
        Parameters:
        model - the model to create this object for
        location - the physical location where the model is stored
      • ModelInfo

        public ModelInfo​(M model,
                         java.net.URI location,
                         IModelLoader<M> loader)
        Creates a model information object.
        Parameters:
        model - the model to create this object for
        location - the physical location where the model is stored
        loader - the loader being responsible for resolving the related model
      • ModelInfo

        public ModelInfo​(java.lang.String name,
                         Version version,
                         IModelLoader<M> loader,
                         java.net.URI location,
                         java.util.List<ModelImport<M>> imp)
        Creates a model information object.
        Parameters:
        name - the name of the model
        version - the version of the model, null signals that no version was given in the model
        loader - the loader being responsible for resolving the related model
        location - the physical location where the model is stored
        imp - imports and conflicts (may be null)
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name of the model.
        Specified by:
        getName in interface IModelData
        Returns:
        the name
      • getVersion

        public Version getVersion()
        Returns the version of the model.
        Specified by:
        getVersion in interface IModelData
        Returns:
        the version, may be null if no version is specified in the model
      • getLocation

        public java.net.URI getLocation()
        Returns the physical location of the model.
        Returns:
        the physical location
      • getLoader

        public IModelLoader<M> getLoader()
        Stores the responsible loader.
        Returns:
        the loader
      • nameVersionToString

        public java.lang.String nameVersionToString()
        Returns name and version as a string for output.
        Returns:
        name and version
      • toString

        public java.lang.String toString()
        Returns a textual representation of this instance.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a textual representation
      • setResolved

        void setResolved​(M resolved)
        Changes the resolved model.
        Parameters:
        resolved - the model, may be null if inconsistent or not yet loaded
      • adjustTimestamp

        private void adjustTimestamp()
        Adjusts the timestamp according to the currently resolved instance.
      • getResolved

        public M getResolved()
        Returns the resolved model.
        Returns:
        the resolved model, may be null if inconsistent or not yet loaded
      • isResolved

        public boolean isResolved()
        Returns whether the related model was already resolved.
        Returns:
        true if it was resolved, false else
      • getTimestamp

        public long getTimestamp()
        Returns the timestamp of the resolution.
        Returns:
        the timestamp, may be negative if there is currently no resolution
      • isOutdated

        public boolean isOutdated()
        Returns whether the represented model is outdated.
        Returns:
        true if it is outdated and loading the model is recommended, , false else
      • getImportsCount

        public int getImportsCount()
        Returns the number of imports. Please note that this method is primarily intended to support versioned import resolution. The returned information is in sync with the resolved model if there is a resolved model, otherwise information is stored locally (and resolved information there may be incorrect or null).
        Returns:
        the number of imports
      • getImport

        public ModelImport<M> getImport​(int index)
        Returns the model import specified by index. Please note that this method is primarily intended to support versioned import resolution. The returned information is in sync with the resolved model if there is a resolved model, otherwise information is stored locally (and resolved information there may be incorrect or null). Depending on the parser, no import restrictions may be attached (this may only be available in the full model).
        Parameters:
        index - a 0-based index specifying the import to be returned
        Returns:
        the model import
        Throws:
        java.lang.IndexOutOfBoundsException - if index<0 || index>=getImportsCount()
      • isContainedIn

        public boolean isContainedIn​(java.net.URI uri)
        Returns whether the location of this information object is contained in uri.
        Parameters:
        uri - the URI to be considered as containing URI
        Returns:
        true if the location of this information object is contained, false if not (or any of both is null). Please note that the opposite must not hold, e.g., if either URL is null.
        See Also:
        isContainedIn(String), toComparablePath(URI)
      • isContainedIn

        public boolean isContainedIn​(java.lang.String path)
        Returns whether the location of this information object is contained in path.
        Parameters:
        path - the path based on toComparablePath(URI)
        Returns:
        true if the location of this information object is contained, false if not (or any of both is null). Please note that the opposite must not hold, e.g., if either URL is null.
      • toComparablePath

        public static java.lang.String toComparablePath​(java.net.URI uri)
        Turns the given uri into a comparable path.
        Parameters:
        uri - the URI (may be null, shall be normalized)
        Returns:
        the comparable path
      • selectOutdated

        public static <M extends IModel> java.util.List<ModelInfo<M>> selectOutdated​(java.util.List<ModelInfo<M>> info,
                                                                                     boolean requireResolved,
                                                                                     java.net.URI uri)
        Returns the outdated model information objects (due to file change). May modify and return info if modify is enabled.
        Type Parameters:
        M - the specific type of model
        Parameters:
        info - the model information objects to be considered
        requireResolved - true if the information objects to be returned need to be resolved (isResolved()), false if just all outdated objects shall be returned
        uri - an optional URI the results must be contained in (may be null)
        Returns:
        the outdated (and, depending on the parameter resolved) information objects
      • selectContained

        public static <M extends IModel> java.util.List<ModelInfo<M>> selectContained​(java.util.List<ModelInfo<M>> info,
                                                                                      java.net.URI uri)
        Selects those information objects out of info which are contained in uri.
        Type Parameters:
        M - the specific type of model
        Parameters:
        info - the information objects to filter
        uri - the URI to filter for (may be null)
        Returns:
        the contained models
      • setLocale

        void setLocale​(java.util.Locale locale)
        Stores the locale used while resolving the related model.
        Parameters:
        locale - the locale used for resolving
      • getLocale

        public java.util.Locale getLocale()
        Returns the locale used for resolving the related model.
        Returns:
        the locale used for resolving
      • getCommentsResource

        public java.net.URI getCommentsResource()
        Returns the URI to the actual comments text resource. The URI is derived using the location of the model by adding the country of the locale used while loading and changing the extension to ".text".
        Returns:
        the URI of the associated comments text resource (the existence of the related resource is not ensured), null if the resource cannot be composed, e.g., as the location is not known or the location does not point to a file
      • getDefaultCommentsResource

        public java.net.URI getDefaultCommentsResource()
        Returns the URI to the default comments text resource. The URI is derived using the location of the model by changing the extension to ".text".
        Returns:
        the URI of the associated comments text resource (the existence of the related resource is not ensured), null if the resource cannot be composed, e.g., as the location is not known or the location does not point to a file
      • getBaseCommentsResource

        public java.net.URI getBaseCommentsResource()
        Returns the URI to the actual base comments text resource. The URI is derived by adding the country of the locale used while loading and changing the extension to ".text".
        Returns:
        the URI of the base comments text resource (the existence of the related resource is not ensured), null if the resource cannot be composed, e.g., as the location is not known or the location does not point to a file
      • getDefaultBaseCommentsResource

        public java.net.URI getDefaultBaseCommentsResource()
        Returns the URI to the actual base default comments text resource. The URI is derived by adding the extension ".text".
        Returns:
        the URI of the default base comments text resource (the existence of the related resource is not ensured), null if the resource cannot be composed, e.g., as the location is not known or the location does not point to a file
      • composeCommentsURI

        private java.net.URI composeCommentsURI​(java.util.Locale locale,
                                                boolean base)
        Composes an URI for the comments locale.
        Parameters:
        locale - the locale (may be null)
        base - return the base comments URL (with fixed name "easy-base") or use the model name
        Returns:
        the URI or null
      • composeLocaleCommentsName

        private java.lang.String composeLocaleCommentsName​(java.lang.String name,
                                                           java.util.Locale locale)
        Composes a comments file name based on a given locale.
        Parameters:
        name - the name
        locale - the locale (may be null)
        Returns:
        the composed name with default extension
      • updateModelLoader

        void updateModelLoader​(IModelLoader<M> loader)
        Updates the model loader (only if unset).
        Parameters:
        loader - the new loader
      • equals

        public static <M extends IModel> boolean equals​(ModelInfo<M> i1,
                                                        ModelInfo<M> i2)
        Returns whether i1 and i2 are equal, i.e., point to the same model.
        Type Parameters:
        M - the model type
        Parameters:
        i1 - the first model information to be compared
        i2 - the second model information
        Returns:
        true if i1 is equal to i2, false else
      • equals

        public static <M extends IModel> boolean equals​(ModelInfo<M> info,
                                                        java.lang.String name,
                                                        Version version,
                                                        java.net.URI location)
        Returns whether i1 and the explicit given information are equal, i.e., point to the same model.
        Type Parameters:
        M - the model type
        Parameters:
        info - the model information to be compared
        name - the name of the model to be compared
        version - the version of the model to be compared
        location - the location to be compared
        Returns:
        true if i1 is equal to i2, false else