Class Utils


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

      Constructors 
      Modifier Constructor Description
      private Utils()
      Prevents this class from being instantiated.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static java.lang.StringBuilder appendErrors​(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 all IModels used in imports.
      private static <M extends IModel>
      void
      arrangeImportedModels​(M model, java.util.Set<M> alreadyVisited, java.util.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.
      (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 model infos by their depending models, i.e.
      (package private) 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.
      static <M extends IModel>
      java.util.List<M>
      discoverImports​(M mainModel)
      List all imported IModels for the given model including the model itself.
      (package private) static <M extends IModel>
      void
      enumerateImported​(M model, java.util.Set<M> result, java.util.Set<M> deleteFrom)
      Enumerate all imported (and resolved) models of model (including model).
      private static <M extends IModel>
      void
      findImportedModels​(M model, java.util.List<M> allModels, java.util.Set<M> done)
      Fills the stack of imported IModels recursively.
      static boolean matches​(IModelData data1, IModelData data2)
      Returns whether two model data object match.
      (package private) static boolean sameVersion​(Version version1, Version version2)
      Returns whether the given versions are equal.
      static java.io.File toExistingFile​(java.net.URI uri)
      Returns a file object for uri which points to an existing file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utils

        private Utils()
        Prevents this class from being instantiated.
    • 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 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 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 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​(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 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> 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 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 java.io.File toExistingFile​(java.net.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,
                                                         java.util.Set<M> result,
                                                         java.util.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> java.util.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,
                                                                  java.util.List<M> allModels,
                                                                  java.util.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> java.util.List<M> arrangeImportedModels​(java.util.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,
                                                                     java.util.Set<M> alreadyVisited,
                                                                     java.util.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.