Class ModelInfo<M extends IModel>

java.lang.Object
net.ssehub.easy.basics.modelManagement.ModelInfo<M>
Type Parameters:
M - the specific model type
All Implemented Interfaces:
IModelData

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

  • Constructor Details

    • ModelInfo

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

      public ModelInfo(M model, 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, 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(String name, Version version, IModelLoader<M> loader, URI location, 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 Details

    • getName

      public 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 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 String nameVersionToString()
      Returns name and version as a string for output.
      Returns:
      name and version
    • toString

      public String toString()
      Returns a textual representation of this instance.
      Overrides:
      toString in class 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:
      IndexOutOfBoundsException - if index<0 || index>=getImportsCount()
    • isContainedIn

      public boolean isContainedIn(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

      public boolean isContainedIn(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 String toComparablePath(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> List<ModelInfo<M>> selectOutdated(List<ModelInfo<M>> info, boolean requireResolved, 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> List<ModelInfo<M>> selectContained(List<ModelInfo<M>> info, 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(Locale locale)
      Stores the locale used while resolving the related model.
      Parameters:
      locale - the locale used for resolving
    • getLocale

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

      public 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 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 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 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 URI composeCommentsURI(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 String composeLocaleCommentsName(String name, 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, String name, Version version, 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