Class VersionedModelInfos<M extends IModel>
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.VersionedModelInfos<M>
-
- Type Parameters:
M- the specific type of model
public class VersionedModelInfos<M extends IModel> extends java.lang.ObjectStores 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 voidadd(ModelInfo<M> info)Adds a model information object.voidclear()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 withurias location.ModelInfo<M>get(M model)Returns the model information objects withmodelas resolved model.ModelInfo<M>getByClosestUri(java.net.URI uri, java.util.List<java.lang.String> modelPath)Returns the model information with the closest match touri, 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 frominfoswith the closest match touri, i.e.java.util.List<ModelInfo<M>>getByEqualUri(java.net.URI uri)Returns the model information with the exact match touri.VersiongetVersion()Returns the version all information objects in this instance are assigned to.static booleanisFileScheme(java.net.URI uri)Returns whether the given URI is a file (file scheme).private static booleanisMatching(java.lang.String searchUriText, java.lang.String importUriText, boolean contained)Checks whether thesearchUriTextandimportUrimatch.private static booleanisMatching(java.lang.String searchUriText, java.util.List<java.lang.String> modelPath, java.lang.String importUriText, boolean contained)Checks whether thesearchUriText(with precedence) ore one of themodelPathURI paths matchimportUri, i.e.static booleanisSame(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 fromlist.static java.lang.StringpathWithoutLastFragment(java.net.URI uri)Returns the prefix path of the givenuriwithout the last fragment.ModelInfo<M>remove(int index)Removes the specified model information object.booleanremove(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 ofuriif 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 ofuri.intsize()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 givenlist.java.lang.StringtoString()Returns the textual representation of this instance.
-
-
-
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 ofinfodoes not matchversionor the name ofinfodoes 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:
trueif both are the same,falseelse
-
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- ifindex<0 || index>=size()
-
get
public ModelInfo<M> get(M model)
Returns the model information objects withmodelas 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 withurias 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- ifindex<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:
trueif successfulfalseelse
-
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 touri.- 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 touri, 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 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 frominfoswith the closest match touri, i.e. in closest in the same hierarchy path.- Type Parameters:
M- the model type- Parameters:
infos- the information objects to be considereduri- 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 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.- Type Parameters:
M- the model type- Parameters:
infos- the information objects to be consideredsearchUriText- the search folder URI as textmodelPath- 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 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 ofuriif 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 considereduri- the URI to start searchingmodelPath- 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 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 ofuri.- Type Parameters:
M- the model type- Parameters:
infos- the information objects to be considereduri- the URI to start searchingmodelPath- 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:
trueif it is a file,falseelse
-
isMatching
private static boolean isMatching(java.lang.String searchUriText, java.util.List<java.lang.String> modelPath, java.lang.String importUriText, boolean contained)Checks whether thesearchUriText(with precedence) ore one of themodelPathURI paths matchimportUri, i.e. whetherimportUriis an appropriate URI for import.- Parameters:
searchUriText- the textual URI of the model stating the importmodelPath- additional URI paths, may be nullimportUriText- the URI path of the model being considered for importcontained- prefer contained or containing URIs- Returns:
trueif the specified data match,falseif not
-
isMatching
private static boolean isMatching(java.lang.String searchUriText, java.lang.String importUriText, boolean contained)Checks whether thesearchUriTextandimportUrimatch.- Parameters:
searchUriText- the textual URI of the model stating the importimportUriText- the URI path of the model being considered for importcontained- prefer contained or containing URIs- Returns:
trueif the specified data match,falseif not
-
pathWithoutLastFragment
public static java.lang.String pathWithoutLastFragment(java.net.URI uri)
Returns the prefix path of the givenuriwithout the last fragment.- Parameters:
uri- the URI to be considered- Returns:
- the prefix path if possible, the
urielse
-
toList
public java.util.List<ModelInfo<M>> toList(java.util.List<ModelInfo<M>> list)
Adds all model information objects to the givenlist.- Parameters:
list- the list to be modified as a side effect (may be null then a list is created)- Returns:
listor the created list
-
toString
public java.lang.String toString()
Returns the textual representation of this instance.- Overrides:
toStringin classjava.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 IModel> VersionedModelInfos<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 IModel> ModelInfo<M> maxVersion(java.util.List<ModelInfo<M>> list)
Returns the model information object with highest version number fromlist. 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
-
-