java.lang.Object
net.ssehub.easy.basics.modelManagement.Utils

public class Utils extends Object
Some model utilities.
Author:
Holger Eichelberger, El-Sharkawy
  • Constructor Details

    • Utils

      private Utils()
      Prevents this class from being instantiated.
  • Method Details

    • 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 the matchesFull methods as soon as full model import and conflicts resolution is available.
      Parameters:
      data1 - the first data object to test
      data2 - the second data object to test
      Returns:
      true if both match, false else
    • sameVersion

      static boolean sameVersion(Version version1, Version version2)
      Returns whether the given versions are equal.
      Parameters:
      version1 - the first version to compare
      version2 - the second version to compare
      Returns:
      true if both versions are equal, false else
    • appendErrors

      static StringBuilder appendErrors(StringBuilder builder, String errors)
      Appends a string of error messages to a given builder. Commas are inserted between already stored information in builder and errors (if errors contains 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 considered
      info - 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 model infos by their depending models, i.e. the models which import the models in info. 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 available
      modelInfoMap - reverse mapping of models to their information objects
      Returns:
      the top-level models which are not imported by any model
    • toExistingFile

      public static File toExistingFile(URI uri)
      Returns a file object for uri which 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, Set<M> result, Set<M> deleteFrom)
      Enumerate all imported (and resolved) models of model (including model).
      Type Parameters:
      M - the actual model type
      Parameters:
      model - the model to enumerate for
      result - the imported models (modified as a side effect)
      deleteFrom - delete models to be added to result if not null
    • discoverImports

      public static <M extends IModel> List<M> discoverImports(M mainModel)
      List all imported IModels 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, List<M> allModels, Set<M> done)
      Fills the stack of imported IModels 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> List<M> arrangeImportedModels(List<M> models)
      Rearranges all IModels used in imports.
      Type Parameters:
      M - the actual model type
      Parameters:
      models - IModels retrieved from findImportedModels(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 of arrangeImportedModels(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 current IModel to add/check
      alreadyVisited - Already visited IModels, 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, main IModel should be last). Should be empty when the recursive function is called from outside to start.
    • printResolution

      public static <M extends IModel> void printResolution(M model, ModelManagement<M> mgt)
      Prints the import resolution of the given model to System.out.
      Type Parameters:
      M - the model type
      Parameters:
      model - the model
      mgt - the optional model management if also model locations shall be emitted, may be null
    • printModelInfo

      private static <M extends IModel> void printModelInfo(M model, ModelManagement<M> mgt)
      Prints the resolution information of the given model to System.out.
      Type Parameters:
      M - the model type
      Parameters:
      model - the model
      mgt - 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 given model to System.out.
      Type Parameters:
      M - the model type
      Parameters:
      model - the model
      mgt - the optional model management if also model locations shall be emitted, may be null
      done - already done/visited models
      indent - characters to be emitted before model information