Class BaseMutableItem

java.lang.Object
io.github.mmm.code.base.item.BaseItem
io.github.mmm.code.base.item.BaseMutableItem
All Implemented Interfaces:
io.github.mmm.code.api.item.CodeItem, io.github.mmm.code.api.item.CodeMutableItem, io.github.mmm.code.api.object.CodeMutable
Direct Known Subclasses:
BaseNodeItem

public abstract class BaseMutableItem extends BaseItem implements io.github.mmm.code.api.item.CodeMutableItem
Base implementation of CodeMutableItem.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Constructor Details

    • BaseMutableItem

      public BaseMutableItem()
      The constructor.
    • BaseMutableItem

      public BaseMutableItem(BaseMutableItem template)
      The copy-constructor.
      Parameters:
      template - the BaseMutableItem to copy.
  • Method Details

    • initialize

      protected final void initialize()
      Initializes this node item.
    • isInitializing

      protected final boolean isInitializing()
      Returns:
      true if the initialization of this item has started but is not yet complete, false otherwise.
    • isInitialized

      protected final boolean isInitialized()
      Returns:
      true if the initialization of this item has been completed, false otherwise.
    • doInitialize

      protected void doInitialize()
      Called from initialize() on first invocation. May be overridden but never be called from anywhere else.
    • doneInitialize

      protected void doneInitialize()
      Called from initialize() on first invocation after doInitialize() is complete. May be overridden but never be called from anywhere else.
    • initialize

      protected final void initialize(boolean init)
      Parameters:
      init - true to call initialize(), false to do nothing.
    • isImmutable

      public boolean isImmutable()
      Specified by:
      isImmutable in interface io.github.mmm.code.api.object.CodeMutable
    • getReflectiveObject

      public Object getReflectiveObject()
      Specified by:
      getReflectiveObject in interface io.github.mmm.code.api.item.CodeMutableItem
    • getSourceCodeObject

      public io.github.mmm.code.api.item.CodeItem getSourceCodeObject()
      Returns:
      the optional internal CodeItem representing the source-code (to merge). Otherwise null. This is an internal API. Do not use or rely on it from outside.
    • isSystemImmutable

      protected boolean isSystemImmutable()
      Returns:
      true if this is a system internal node item that is considered to be immutable but is technically set to immutable during (lazy) initialization. Otherwise false.
    • isSystemImmutable

      protected static boolean isSystemImmutable(BaseMutableItem item)
      Parameters:
      item - the BaseMutableItem.
      Returns:
      the result of isSystemImmutable().
    • setImmutableIfNotSystemImmutable

      public void setImmutableIfNotSystemImmutable()
      Calls setImmutable() but only if not system immutable. Use this method for implementations of doSetImmutable() to propagate immutable-flag to children in order to prevent eager initialization.
    • setImmutable

      public void setImmutable()
      Makes this item immutable.
      Specified by:
      setImmutable in interface io.github.mmm.code.api.item.CodeMutableItem
    • doSetImmutable

      protected void doSetImmutable()
      Called on the first call of setImmutable(). Has to be overridden to update Collections, make child items immutable, etc.
    • verifyMutalbe

      protected void verifyMutalbe()
      Verifies that this item is not immutable. Call this method from any edit-method (setter, etc.).
      Throws:
      io.github.mmm.base.exception.ReadOnlyException - if this item is immutable.
    • makeImmutable

      protected <T extends io.github.mmm.code.api.item.CodeItem> List<T> makeImmutable(List<T> list)
      Type Parameters:
      T - the type of the List elements.
      Parameters:
      list - the List to make immutable.
      Returns:
      an immutable copy of the List.
    • makeImmutable

      protected <T extends io.github.mmm.code.api.item.CodeItem> List<T> makeImmutable(List<T> list, boolean disconnect)
      Type Parameters:
      T - the type of the List elements.
      Parameters:
      list - the List to make immutable.
      disconnect - - true to disconnect the returned, immutable List from the given List, false otherwise (to make it an immutable view on it).
      Returns:
      an immutable copy of the List.
    • getDefaultCopyMapper

      protected io.github.mmm.code.api.copy.CodeCopyMapper getDefaultCopyMapper()
      Returns:
      the default implementation of CodeCopyMapper.
    • doMapList

      protected <N extends io.github.mmm.code.api.node.CodeNode> List<N> doMapList(List<N> list, io.github.mmm.code.api.copy.CodeCopyMapper mapper, io.github.mmm.code.api.copy.CodeCopyType type)
      Type Parameters:
      N - type of the CodeNodeItemCopyable.
      Parameters:
      list - the List to copy.
      mapper - the CodeCopyMapper.
      type - the CodeCopyType.
      Returns:
      an mutable deep-copy of the List.
    • doCopyNodeUnsafe

      protected <N extends io.github.mmm.code.api.node.CodeNodeItem> N doCopyNodeUnsafe(N node, io.github.mmm.code.api.node.CodeNodeItem parent)
      Type Parameters:
      N - type of the CodeNodeItem to copy.
      Parameters:
      node - the CodeNodeItem to copy.
      parent - the new parent.
      Returns:
      the copy.
    • doCopyNode

      protected <P extends io.github.mmm.code.api.node.CodeNodeItem, N extends io.github.mmm.code.api.copy.CodeNodeItemCopyable<P,N>> N doCopyNode(N node, P parent)
      Type Parameters:
      P - type of the parent.
      N - type of the CodeNodeItem to copy.
      Parameters:
      node - the CodeNodeItem to copy.
      parent - the new parent.
      Returns:
      the copy.
    • writeItem

      protected void writeItem(io.github.mmm.code.api.item.CodeItem item, Path targetFolder, String filename, Charset encoding)
      Parameters:
      item - the CodeItem to write to a new or existing file.
      targetFolder - the Path pointing to the existing folder where to write to.
      filename - the name of the file to write.
      encoding - the Charset to use (typically UTF-8).
      See Also:
      • CodeNodeWithFileWriting.write(Path)
    • getDefaultEncoding

      protected static Charset getDefaultEncoding()
      Returns:
      the default Charset used by CodeNodeWithFileWriting.write(Path)