Class CodeTarget

java.lang.Object
de.spraener.nxtgen.target.CodeTarget

public class CodeTarget extends Object
Responsibility

A CodeTarget is an ordered collection of CodeSections. It can take each CodeSection with a key. Each CodeSection can be retrieved by this key for later modifications. A CodeTarget can only hold one CodeSection per key. Replacing is not possible and will rise a IllegalArgumentException.

It also delivers a collection of all added section in the order of insertion.

  • Constructor Details

    • CodeTarget

      public CodeTarget()
  • Method Details

    • addCodeSection

      public void addCodeSection(Object key, CodeSection aSection)
      Add a CodeSection under the given Key to the CodeTarget. A former added CodeSection under that key will be replaced.
      Parameters:
      key - A key to reference a CodeSection for later modification
      aSection - the CodeSection to be inserted.
    • withCodeSection

      public CodeTarget withCodeSection(Object key, CodeSection section)
      A wither for the addCodeSection-method to provide a fluent api.
      Parameters:
      key - A key to reference a CodeSection for later modification.
      section - The CodeSection to be inserted.
      Returns:
      The CodeTarget itself.
    • getSection

      public CodeSection getSection(Object key)
      Retrieve the CodeSection that was added with the specified key or null.
      Parameters:
      key - The key for the CodeSection requested
      Returns:
      an Optional of the CodeSection. This can be empty if no CodeSection with that key is present.
    • getSectionsOrdered

      public Collection<CodeSection> getSectionsOrdered()
      Delivers all added CodeSections in the order of Insertion.
      Returns:
    • inContext

      public CodeTarget inContext(Object aspect, ModelElement me, Consumer<CodeTarget>... consumers)
      Opens a new CodeTargetContext and calls all consumers on this CodeTarget, so they are working in that given CodeTargetContext.
      Parameters:
      aspect - An aspect the consumer working on or null.
      me - A ModelElement the consumers wokring on or null.
      consumers - a list of consumers to do some work on this CodeTarget.
      Returns:
      CodeTarget itself for queuing.