Class BasePathElements

All Implemented Interfaces:
io.github.mmm.code.api.CodePathElements, io.github.mmm.code.api.CodeWithContext, io.github.mmm.code.api.copy.CodeNodeItemCopyable<io.github.mmm.code.api.CodePackage, io.github.mmm.code.api.CodePathElements>, io.github.mmm.code.api.item.CodeItem, io.github.mmm.code.api.item.CodeMutableItem, io.github.mmm.code.api.node.CodeNode, io.github.mmm.code.api.node.CodeNodeContainer<io.github.mmm.code.api.CodePathElement>, io.github.mmm.code.api.node.CodeNodeItem, io.github.mmm.code.api.node.CodeNodeItemContainer<io.github.mmm.code.api.CodePathElement>, io.github.mmm.code.api.node.CodeNodeItemContainerFlat<io.github.mmm.code.api.CodePathElement>, io.github.mmm.code.api.object.CodeMutable, Iterable<io.github.mmm.code.api.CodePathElement>

public class BasePathElements extends BaseNodeItemContainerFlat<io.github.mmm.code.api.CodePathElement> implements io.github.mmm.code.api.CodePathElements
Base implementation of CodePathElements.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Constructor Details

    • BasePathElements

      public BasePathElements(BasePackage parent)
      The constructor.
      Parameters:
      parent - the parent.
    • BasePathElements

      public BasePathElements(BasePathElements template, io.github.mmm.code.api.copy.CodeCopyMapper mapper)
      The copy-constructor.
      Parameters:
      template - the BasePathElements to copy.
      mapper - the CodeCopyMapper.
  • Method Details

    • isKeepListView

      protected boolean isKeepListView()
      Overrides:
      isKeepListView in class BaseNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Returns:
      true if the List should turn into an immutable view on the original mutable List, false otherwise.
      See Also:
    • isNamed

      protected boolean isNamed()
      Overrides:
      isNamed in class BaseNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Returns:
      true if this is a named container that requires a map, false otherwise.
    • getParent

      public BasePackage getParent()
      Specified by:
      getParent in interface io.github.mmm.code.api.node.CodeNode
      Specified by:
      getParent in interface io.github.mmm.code.api.node.CodeNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Specified by:
      getParent in interface io.github.mmm.code.api.copy.CodeNodeItemCopyable<io.github.mmm.code.api.CodePackage, io.github.mmm.code.api.CodePathElements>
      Specified by:
      getParent in interface io.github.mmm.code.api.CodePathElements
    • get

      public io.github.mmm.code.api.CodePathElement get(String simpleName)
      Specified by:
      get in interface io.github.mmm.code.api.CodePathElements
    • getFile

      public BaseFile getFile(String simpleName)
      Specified by:
      getFile in interface io.github.mmm.code.api.CodePathElements
    • getFile

      public BaseFile getFile(String simpleName, boolean init)
      Parameters:
      simpleName - the simple name of the requested CodeFile.
      init - - true to initialize, false otherwise.
      Returns:
      the CodeFile with the given name or null if not found.
    • getFile

      public BaseFile getFile(io.github.mmm.code.api.CodeName path)
      Specified by:
      getFile in interface io.github.mmm.code.api.CodePathElements
    • add

      public void add(io.github.mmm.code.api.CodePathElement item)
      Specified by:
      add in interface io.github.mmm.code.api.CodePathElements
      Overrides:
      add in class BaseNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Parameters:
      item - the item to add.
    • addInternal

      protected void addInternal(io.github.mmm.code.api.CodePathElement item)
      Overrides:
      addInternal in class BaseNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Parameters:
      item - the item to add.
    • ensureParent

      protected io.github.mmm.code.api.CodePathElement ensureParent(io.github.mmm.code.api.CodePathElement item)
      Overrides:
      ensureParent in class BaseNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Parameters:
      item - the item to add.
      Returns:
      the item itself or a copy with this container as parent.
    • getPackage

      public BasePackage getPackage(String simpleName)
      Specified by:
      getPackage in interface io.github.mmm.code.api.CodePathElements
    • getPackage

      public BasePackage getPackage(String simpleName, boolean init)
      Parameters:
      simpleName - the simple name of the requested CodePackage.
      init - - true to initialize, false otherwise.
      Returns:
      the BasePackage with the given name or null if not found.
    • getPackage

      public BasePackage getPackage(io.github.mmm.code.api.CodeName path)
      Specified by:
      getPackage in interface io.github.mmm.code.api.CodePathElements
    • getPackage

      public BasePackage getPackage(io.github.mmm.code.api.CodeName path, boolean init)
      Parameters:
      path - the CodeName leading to the requested child. See getPackage(CodeName, boolean).
      init - - true to initialize, false otherwise.
      Returns:
      the traversed BasePackage or null if not found.
    • getPackage

      public BasePackage getPackage(io.github.mmm.code.api.CodeName path, boolean init, BiFunction<BasePackage, String, BasePackage> factory, boolean add)
      Parameters:
      path - the CodeName leading to the requested child. See getPackage(CodeName, boolean).
      init - - true to initialize, false otherwise.
      factory - the BiFunction used as factory to create missing packages.
      add - - true to add new packages created by the given factory, false otherwise.
      Returns:
      the traversed BasePackage. Has been created if it did not already exist and was produced by the given factory.
    • getPackage

      protected BasePackage getPackage(io.github.mmm.code.api.CodeName path, boolean init, BiFunction<BasePackage, String, BasePackage> factory, boolean add, boolean forceAdd)
      Attention: This is an internal API that should not be used from outside. Use getPackage(CodeName, boolean, BiFunction, boolean) instead.
      Parameters:
      path - the CodeName to traverse.
      init - - true to initialize, false otherwise.
      factory - the BiFunction used as factory to create missing packages.
      add - - true to add new packages created by the given factory, false otherwise.
      forceAdd - - true to force adding (if add is true but is immutable), false otherwise.
      Returns:
      the traversed BasePackage. Has been created if it did not already exist and was produced by the given factory.
    • getOrCreatePackage

      public BasePackage getOrCreatePackage(io.github.mmm.code.api.CodeName path, boolean add)
      Specified by:
      getOrCreatePackage in interface io.github.mmm.code.api.CodePathElements
    • getOrCreatePackage

      public BasePackage getOrCreatePackage(io.github.mmm.code.api.CodeName path, boolean add, boolean init)
      Parameters:
      path - the CodeName leading to the requested child. See getOrCreatePackage(CodeName, boolean).
      add - - true to add newly created packages, false otherwise.
      init - - true to initialize, false otherwise.
      Returns:
      the traversed BasePackage. Has been created if it did not already exist.
    • getOrCreatePackage

      protected BasePackage getOrCreatePackage(io.github.mmm.code.api.CodeName path, boolean add, boolean init, boolean forceAdd)
      Parameters:
      path - the CodeName leading to the requested child. See getOrCreatePackage(CodeName, boolean).
      add - - true to add newly created packages, false otherwise.
      init - - true to initialize, false otherwise.
      forceAdd - - true to force adding (if add is true but is immutable), false otherwise.
      Returns:
      the traversed BasePackage. Has been created if it did not already exist.
    • createPackage

      public BasePackage createPackage(String simpleName)
      Specified by:
      createPackage in interface io.github.mmm.code.api.CodePathElements
    • getOrCreateFile

      public BaseFile getOrCreateFile(io.github.mmm.code.api.CodeName path, boolean add)
      Specified by:
      getOrCreateFile in interface io.github.mmm.code.api.CodePathElements
    • getOrCreateFile

      public BaseFile getOrCreateFile(io.github.mmm.code.api.CodeName path, boolean add, boolean init)
      Parameters:
      path - the CodeName leading to the requested child. See getOrCreateFile(CodeName, boolean).
      add - - true to add a newly created CodeFile, false otherwise.
      init - - true to initialize, false otherwise.
      Returns:
      the existing or newly created CodeFile.
    • getOrCreateFile

      protected BaseFile getOrCreateFile(io.github.mmm.code.api.CodeName path, boolean add, boolean init, boolean forceAdd)
      Parameters:
      path - the CodeName leading to the requested child. See getOrCreateFile(CodeName, boolean).
      add - - true to add a newly created CodeFile, false otherwise.
      init - - true to initialize, false otherwise.
      forceAdd - - true to force adding (if add is true but is immutable), false otherwise.
      Returns:
      the existing or newly created CodeFile.
    • createFile

      public BaseFile createFile(String simpleName)
      Specified by:
      createFile in interface io.github.mmm.code.api.CodePathElements
    • getType

      public io.github.mmm.code.api.type.CodeType getType(String simpleName)
      Specified by:
      getType in interface io.github.mmm.code.api.CodePathElements
    • getType

      public io.github.mmm.code.api.type.CodeType getType(String simpleName, boolean init)
      Parameters:
      simpleName - the simple name of the requested CodeType.
      init - - true to initialize, false otherwise.
      Returns:
      the CodeType with the given name or null if not found.
    • createType

      public BaseType createType(String simpleName)
      Specified by:
      createType in interface io.github.mmm.code.api.CodePathElements
    • containsPackage

      public boolean containsPackage(io.github.mmm.code.api.CodePackage child)
      Specified by:
      containsPackage in interface io.github.mmm.code.api.CodePathElements
    • containsSubPackage

      public boolean containsSubPackage(io.github.mmm.code.api.CodePackage child)
      Specified by:
      containsSubPackage in interface io.github.mmm.code.api.CodePathElements
    • copy

      public BasePathElements copy()
      Specified by:
      copy in interface io.github.mmm.code.api.item.CodeMutableItem
      Specified by:
      copy in interface io.github.mmm.code.api.node.CodeNodeItem
      Specified by:
      copy in interface io.github.mmm.code.api.node.CodeNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Specified by:
      copy in interface io.github.mmm.code.api.node.CodeNodeItemContainerFlat<io.github.mmm.code.api.CodePathElement>
      Specified by:
      copy in interface io.github.mmm.code.api.copy.CodeNodeItemCopyable<io.github.mmm.code.api.CodePackage, io.github.mmm.code.api.CodePathElements>
      Specified by:
      copy in interface io.github.mmm.code.api.CodePathElements
    • copy

      public BasePathElements copy(io.github.mmm.code.api.copy.CodeCopyMapper mapper)
      Specified by:
      copy in interface io.github.mmm.code.api.item.CodeMutableItem
      Specified by:
      copy in interface io.github.mmm.code.api.node.CodeNodeItem
      Specified by:
      copy in interface io.github.mmm.code.api.node.CodeNodeItemContainer<io.github.mmm.code.api.CodePathElement>
      Specified by:
      copy in interface io.github.mmm.code.api.copy.CodeNodeItemCopyable<io.github.mmm.code.api.CodePackage, io.github.mmm.code.api.CodePathElements>
      Specified by:
      copy in interface io.github.mmm.code.api.CodePathElements
    • doWrite

      protected void doWrite(Appendable sink, String newline, String defaultIndent, String currentIndent, io.github.mmm.code.api.language.CodeLanguage language) throws IOException
      Specified by:
      doWrite in class BaseItem
      Parameters:
      sink - the Appendable where to append the code from this CodeItem.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      language - the CodeLanguage to use.
      Throws:
      IOException - if thrown by Appendable.
      See Also:
      • CodeItem.write(Appendable, String, String)
    • toString

      public String toString()
      Overrides:
      toString in class BaseItem