Class Utils
java.lang.Object
net.ssehub.easy.basics.modelManagement.Utils
Some model utilities.
- Author:
- Holger Eichelberger, El-Sharkawy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static StringBuilderappendErrors(StringBuilder builder, String errors) Appends a string of error messages to a given builder.arrangeImportedModels(List<M> models) Rearranges allIModels used in imports.private static <M extends IModel>
voidarrangeImportedModels(M model, Set<M> alreadyVisited, 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.augmentByDepending(List<ModelInfo<M>> infos, List<ModelInfo<M>> allInfos, Map<M, ModelInfo<M>> modelInfoMap) Augments the given modelinfosby their depending models, i.e.(package private) static <M extends IModel>
voidcollectModelInfo(Collection<List<VersionedModelInfos<M>>> availableModels, List<ModelInfo<M>> info, Map<M, ModelInfo<M>> modelInfoMap) Fills the given list/map as temporary data structures for improved handling of model information objects and related model.discoverImports(M mainModel) List all importedIModels for the given model including the model itself.(package private) static <M extends IModel>
voidenumerateImported(M model, Set<M> result, Set<M> deleteFrom) Enumerate all imported (and resolved) models ofmodel(includingmodel).private static <M extends IModel>
voidfindImportedModels(M model, List<M> allModels, Set<M> done) Fills the stack of importedIModels recursively.static booleanmatches(IModelData data1, IModelData data2) Returns whether two model data object match.private static <M extends IModel>
voidprintModelInfo(M model, ModelManagement<M> mgt) Prints the resolution information of the givenmodeltoSystem.out.static <M extends IModel>
voidprintResolution(M model, ModelManagement<M> mgt) Prints the import resolution of the givenmodeltoSystem.out.private static <M extends IModel>
voidprintResolution(M model, ModelManagement<M> mgt, Set<M> done, String indent) Prints the import resolution of the givenmodeltoSystem.out.(package private) static booleansameVersion(Version version1, Version version2) Returns whether the given versions are equal.static FiletoExistingFile(URI uri) Returns a file object foruriwhich points to an existing file.
-
Constructor Details
-
Utils
private Utils()Prevents this class from being instantiated.
-
-
Method Details
-
matches
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
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
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(Collection<List<VersionedModelInfos<M>>> availableModels, List<ModelInfo<M>> info, 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> List<ModelInfo<M>> augmentByDepending(List<ModelInfo<M>> infos, List<ModelInfo<M>> allInfos, 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
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
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
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
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
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, Set<M> alreadyVisited, 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.
-
printResolution
Prints the import resolution of the givenmodeltoSystem.out.- Type Parameters:
M- the model type- Parameters:
model- the modelmgt- the optional model management if also model locations shall be emitted, may be null
-
printModelInfo
Prints the resolution information of the givenmodeltoSystem.out.- Type Parameters:
M- the model type- Parameters:
model- the modelmgt- the optional model management if also model locations shall be emitted, may be null
-
printResolution
private static <M extends IModel> void printResolution(M model, ModelManagement<M> mgt, Set<M> done, String indent) Prints the import resolution of the givenmodeltoSystem.out.- Type Parameters:
M- the model type- Parameters:
model- the modelmgt- the optional model management if also model locations shall be emitted, may be nulldone- already done/visited modelsindent- characters to be emitted before model information
-