Class Utils
- java.lang.Object
-
- net.ssehub.easy.basics.modelManagement.Utils
-
public class Utils extends java.lang.ObjectSome model utilities.- Author:
- Holger Eichelberger, El-Sharkawy
-
-
Constructor Summary
Constructors Modifier Constructor Description privateUtils()Prevents this class from being instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.StringBuilderappendErrors(java.lang.StringBuilder builder, java.lang.String errors)Appends a string of error messages to a given builder.private static <M extends IModel>
java.util.List<M>arrangeImportedModels(java.util.List<M> models)Rearranges allIModels used in imports.private static <M extends IModel>
voidarrangeImportedModels(M model, java.util.Set<M> alreadyVisited, java.util.List<M> sequence)Recursive part ofarrangeImportedModels(List)to arrange first the imports before the importing project without running into an endless loop in case of cycling projects.(package private) static <M extends IModel>
java.util.List<ModelInfo<M>>augmentByDepending(java.util.List<ModelInfo<M>> infos, java.util.List<ModelInfo<M>> allInfos, java.util.Map<M,ModelInfo<M>> modelInfoMap)Augments the given modelinfosby their depending models, i.e.(package private) static <M extends IModel>
voidcollectModelInfo(java.util.Collection<java.util.List<VersionedModelInfos<M>>> availableModels, java.util.List<ModelInfo<M>> info, java.util.Map<M,ModelInfo<M>> modelInfoMap)Fills the given list/map as temporary data structures for improved handling of model information objects and related model.static <M extends IModel>
java.util.List<M>discoverImports(M mainModel)List all importedIModels for the given model including the model itself.(package private) static <M extends IModel>
voidenumerateImported(M model, java.util.Set<M> result, java.util.Set<M> deleteFrom)Enumerate all imported (and resolved) models ofmodel(includingmodel).private static <M extends IModel>
voidfindImportedModels(M model, java.util.List<M> allModels, java.util.Set<M> done)Fills the stack of importedIModels recursively.static booleanmatches(IModelData data1, IModelData data2)Returns whether two model data object match.(package private) static booleansameVersion(Version version1, Version version2)Returns whether the given versions are equal.static java.io.FiletoExistingFile(java.net.URI uri)Returns a file object foruriwhich points to an existing file.
-
-
-
Method Detail
-
matches
public static boolean matches(IModelData data1, IModelData data2)
Returns whether two model data object match. This method is preliminary and shall be unified with thematchesFullmethods as soon as full model import and conflicts resolution is available.- Parameters:
data1- the first data object to testdata2- the second data object to test- Returns:
trueif both match,falseelse
-
sameVersion
static boolean sameVersion(Version version1, Version version2)
Returns whether the given versions are equal.- Parameters:
version1- the first version to compareversion2- the second version to compare- Returns:
trueif both versions are equal,falseelse
-
appendErrors
static java.lang.StringBuilder appendErrors(java.lang.StringBuilder builder, java.lang.String errors)Appends a string of error messages to a given builder. Commas are inserted between already stored information inbuilderanderrors(iferrorscontains information)- Parameters:
builder- the builder to append to (modified as a side effect)errors- the error string (may be null)- Returns:
builder
-
collectModelInfo
static <M extends IModel> void collectModelInfo(java.util.Collection<java.util.List<VersionedModelInfos<M>>> availableModels, java.util.List<ModelInfo<M>> info, java.util.Map<M,ModelInfo<M>> modelInfoMap)
Fills the given list/map as temporary data structures for improved handling of model information objects and related model.- Type Parameters:
M- the specific model type- Parameters:
availableModels- all available model infos to be consideredinfo- a list of all available model information objects (modified as a side effect if not null)modelInfoMap- a reverse mapping between models and their related models (modified as a side effect if not null)
-
augmentByDepending
static <M extends IModel> java.util.List<ModelInfo<M>> augmentByDepending(java.util.List<ModelInfo<M>> infos, java.util.List<ModelInfo<M>> allInfos, java.util.Map<M,ModelInfo<M>> modelInfoMap)
Augments the given modelinfosby their depending models, i.e. the models which import the models ininfo. Please note that this method contains only already resolved models!- Type Parameters:
M- the specific model type- Parameters:
infos- the model informations to be augmented by their depending models (modified as a side effect)allInfos- all information objects that are currently availablemodelInfoMap- reverse mapping of models to their information objects- Returns:
- the top-level models which are not imported by any model
-
toExistingFile
public static java.io.File toExistingFile(java.net.URI uri)
Returns a file object foruriwhich points to an existing file.- Parameters:
uri- the URI to turn into a file- Returns:
- the related file or null if either uri is null or the related file does not exist
-
enumerateImported
static <M extends IModel> void enumerateImported(M model, java.util.Set<M> result, java.util.Set<M> deleteFrom)
Enumerate all imported (and resolved) models ofmodel(includingmodel).- Type Parameters:
M- the actual model type- Parameters:
model- the model to enumerate forresult- the imported models (modified as a side effect)deleteFrom- delete models to be added toresultif not null
-
discoverImports
public static <M extends IModel> java.util.List<M> discoverImports(M mainModel)
List all importedIModels for the given model including the model itself. The most inner model will be the first element of the list, the main model the last (helpful for a correct initialization).
Note: This function should not run into an endless loop in case of cycling imports.- Type Parameters:
M- the actual model type- Parameters:
mainModel- The model to start with. May contain any imports and is the starting point.- Returns:
- The list of all associated projects (first most inner imported model, last is the main model itself).
-
findImportedModels
private static <M extends IModel> void findImportedModels(M model, java.util.List<M> allModels, java.util.Set<M> done)
Fills the stack of importedIModels recursively.- Type Parameters:
M- the actual model type- Parameters:
model- the model to be considered (should be the main model for starting the recursion).allModels- the list of all included models (modified as a side effect)done- already considered models
-
arrangeImportedModels
private static <M extends IModel> java.util.List<M> arrangeImportedModels(java.util.List<M> models)
Rearranges allIModels used in imports.- Type Parameters:
M- the actual model type- Parameters:
models-IModels retrieved fromfindImportedModels(IModel, List, Set).- Returns:
- Rearranged list of
IModels.
-
arrangeImportedModels
private static <M extends IModel> void arrangeImportedModels(M model, java.util.Set<M> alreadyVisited, java.util.List<M> sequence)
Recursive part ofarrangeImportedModels(List)to arrange first the imports before the importing project without running into an endless loop in case of cycling projects.- Type Parameters:
M- the actual model type- Parameters:
model- The currentIModelto add/checkalreadyVisited- Already visitedIModels, will not be revisited in case of a cycle. Should be empty when the recursive function is called from outside to start.sequence- The resulting sequence (deepest import should be first, mainIModelshould be last). Should be empty when the recursive function is called from outside to start.
-
-