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
Stores high-level information about an available (possibly unresolved) model.
- Author:
- Holger Eichelberger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInternal constructor for marking pseudo instances.ModelInfo(String name, Version version, IModelLoader<M> loader, URI location, List<ModelImport<M>> imp) Creates a model information object.Creates a model information object.ModelInfo(M model, URI location, IModelLoader<M> loader) Creates a model information object. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdjusts the timestamp according to the currently resolved instance.private URIcomposeCommentsURI(Locale locale, boolean base) Composes an URI for the comments locale.private StringcomposeLocaleCommentsName(String name, Locale locale) Composes a comments file name based on a given locale.static <M extends IModel>
booleanReturns whetheri1and the explicit given information are equal, i.e., point to the same model.static <M extends IModel>
booleanReturns whetheri1andi2are equal, i.e., point to the same model.Returns the URI to the actual base comments text resource.Returns the URI to the actual comments text resource.Returns the URI to the actual base default comments text resource.Returns the URI to the default comments text resource.getImport(int index) Returns the model import specified byindex.intReturns the number of imports.Stores the responsible loader.Returns the locale used for resolving the related model.Returns the physical location of the model.getName()Returns the name of the model.Returns the resolved model.longReturns the timestamp of the resolution.Returns the version of the model.booleanisContainedIn(String path) Returns whether the location of this information object is contained inpath.booleanisContainedIn(URI uri) Returns whether the location of this information object is contained inuri.booleanReturns whether the represented model is outdated.booleanReturns whether the related model was already resolved.Returns name and version as a string for output.selectContained(List<ModelInfo<M>> info, URI uri) Selects those information objects out ofinfowhich are contained inuri.selectOutdated(List<ModelInfo<M>> info, boolean requireResolved, URI uri) Returns the outdated model information objects (due to file change).(package private) voidStores the locale used while resolving the related model.(package private) voidsetResolved(M resolved) Changes the resolved model.static StringtoComparablePath(URI uri) Turns the givenuriinto a comparable path.toString()Returns a textual representation of this instance.(package private) voidupdateModelLoader(IModelLoader<M> loader) Updates the model loader (only if unset).
-
Field Details
-
name
-
version
-
loader
-
location
-
resolved
-
timestamp
private long timestamp -
imports
-
locale
-
-
Constructor Details
-
ModelInfo
ModelInfo()Internal constructor for marking pseudo instances. -
ModelInfo
Creates a model information object.- Parameters:
model- the model to create this object forlocation- the physical location where the model is stored
-
ModelInfo
Creates a model information object.- Parameters:
model- the model to create this object forlocation- the physical location where the model is storedloader- 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 modelversion- the version of the model, null signals that no version was given in the modelloader- the loader being responsible for resolving the related modellocation- the physical location where the model is storedimp- imports and conflicts (may be null)
-
-
Method Details
-
getName
Returns the name of the model.- Specified by:
getNamein interfaceIModelData- Returns:
- the name
-
getVersion
Returns the version of the model.- Specified by:
getVersionin interfaceIModelData- Returns:
- the version, may be null if no version is specified in the model
-
getLocation
Returns the physical location of the model.- Returns:
- the physical location
-
getLoader
Stores the responsible loader.- Returns:
- the loader
-
nameVersionToString
Returns name and version as a string for output.- Returns:
- name and version
-
toString
Returns a textual representation of this instance. -
setResolved
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
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:
trueif it was resolved,falseelse
-
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:
trueif it is outdated and loading the model is recommended, ,falseelse
-
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
Returns the model import specified byindex. 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- ifindex<0 || index>=getImportsCount()
-
isContainedIn
Returns whether the location of this information object is contained inuri.- Parameters:
uri- the URI to be considered as containing URI- Returns:
trueif the location of this information object is contained,falseif 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
Returns whether the location of this information object is contained inpath.- Parameters:
path- the path based ontoComparablePath(URI)- Returns:
trueif the location of this information object is contained,falseif not (or any of both is null). Please note that the opposite must not hold, e.g., if either URL is null.
-
toComparablePath
Turns the givenuriinto 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 returninfoifmodifyis enabled.- Type Parameters:
M- the specific type of model- Parameters:
info- the model information objects to be consideredrequireResolved-trueif the information objects to be returned need to be resolved (isResolved()),falseif just all outdated objects shall be returneduri- 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 ofinfowhich are contained inuri.- Type Parameters:
M- the specific type of model- Parameters:
info- the information objects to filteruri- the URI to filter for (may be null)- Returns:
- the contained models
-
setLocale
Stores the locale used while resolving the related model.- Parameters:
locale- the locale used for resolving
-
getLocale
Returns the locale used for resolving the related model.- Returns:
- the locale used for resolving
-
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
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
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
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
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
Composes a comments file name based on a given locale.- Parameters:
name- the namelocale- the locale (may be null)- Returns:
- the composed name with default extension
-
updateModelLoader
Updates the model loader (only if unset).- Parameters:
loader- the new loader
-
equals
Returns whetheri1andi2are equal, i.e., point to the same model.- Type Parameters:
M- the model type- Parameters:
i1- the first model information to be comparedi2- the second model information- Returns:
trueifi1is equal toi2,falseelse
-
equals
public static <M extends IModel> boolean equals(ModelInfo<M> info, String name, Version version, URI location) Returns whetheri1and 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 comparedname- the name of the model to be comparedversion- the version of the model to be comparedlocation- the location to be compared- Returns:
trueifi1is equal toi2,falseelse
-