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 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 voidadjustTimestamp()Adjusts the timestamp according to the currently resolved instance.private java.net.URIcomposeCommentsURI(java.util.Locale locale, boolean base)Composes an URI for the comments locale.private java.lang.StringcomposeLocaleCommentsName(java.lang.String name, java.util.Locale locale)Composes a comments file name based on a given locale.static <M extends IModel>
booleanequals(ModelInfo<M> info, java.lang.String name, Version version, java.net.URI location)Returns whetheri1and the explicit given information are equal, i.e., point to the same model.static <M extends IModel>
booleanequals(ModelInfo<M> i1, ModelInfo<M> i2)Returns whetheri1andi2are equal, i.e., point to the same model.java.net.URIgetBaseCommentsResource()Returns the URI to the actual base comments text resource.java.net.URIgetCommentsResource()Returns the URI to the actual comments text resource.java.net.URIgetDefaultBaseCommentsResource()Returns the URI to the actual base default comments text resource.java.net.URIgetDefaultCommentsResource()Returns the URI to the default comments text resource.ModelImport<M>getImport(int index)Returns the model import specified byindex.intgetImportsCount()Returns the number of imports.IModelLoader<M>getLoader()Stores the responsible loader.java.util.LocalegetLocale()Returns the locale used for resolving the related model.java.net.URIgetLocation()Returns the physical location of the model.java.lang.StringgetName()Returns the name of the model.MgetResolved()Returns the resolved model.longgetTimestamp()Returns the timestamp of the resolution.VersiongetVersion()Returns the version of the model.booleanisContainedIn(java.lang.String path)Returns whether the location of this information object is contained inpath.booleanisContainedIn(java.net.URI uri)Returns whether the location of this information object is contained inuri.booleanisOutdated()Returns whether the represented model is outdated.booleanisResolved()Returns whether the related model was already resolved.java.lang.StringnameVersionToString()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 ofinfowhich are contained inuri.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) voidsetLocale(java.util.Locale locale)Stores the locale used while resolving the related model.(package private) voidsetResolved(M resolved)Changes the resolved model.static java.lang.StringtoComparablePath(java.net.URI uri)Turns the givenuriinto a comparable path.java.lang.StringtoString()Returns a textual representation of this instance.(package private) voidupdateModelLoader(IModelLoader<M> loader)Updates the model loader (only if unset).
-
-
-
Field Detail
-
name
private java.lang.String name
-
version
private Version version
-
loader
private IModelLoader<M extends IModel> loader
-
location
private java.net.URI location
-
timestamp
private long timestamp
-
imports
private java.util.List<ModelImport<M extends IModel>> imports
-
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 forlocation- 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 forlocation- the physical location where the model is storedloader- 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 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 Detail
-
getName
public java.lang.String getName()
Returns the name of the model.- Specified by:
getNamein interfaceIModelData- Returns:
- the name
-
getVersion
public Version 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
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:
toStringin classjava.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:
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
public ModelImport<M> getImport(int index)
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:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getImportsCount()
-
isContainedIn
public boolean isContainedIn(java.net.URI uri)
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(String),toComparablePath(URI)
-
isContainedIn
public boolean isContainedIn(java.lang.String path)
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
public static java.lang.String toComparablePath(java.net.URI uri)
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> 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 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> java.util.List<ModelInfo<M>> selectContained(java.util.List<ModelInfo<M>> info, java.net.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
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 namelocale- 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 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, java.lang.String name, Version version, java.net.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
-
-