Class Update<M>

java.lang.Object
eu.bandm.tools.ramus.ogma.Update<M>
Type Parameters:
M - the type of diagnostic messages attached to stems
All Implemented Interfaces:
Action.Continuation<State,State,M,State>, Function<State,Action<State,M,State>>

public abstract class Update<M> extends Object implements Action.Continuation<State,State,M,State>
Search-tree continuations that make semantic state transitions.

The implementations provided by this class are not only convenient building blocks, but also undergo extensive dynamic optimization via algebraic laws.

  • Method Details

    • withCallerLocation

      public Update<M> withCallerLocation(@Opt Location<String> callerLocation)
      Sets the caller location for the construction context of this update.
      Parameters:
      callerLocation - the caller location for the construction context of this update, or null if not available
      Returns:
      this
    • getCallerLocation

      public @Opt Location<String> getCallerLocation()
      Returns the caller location for the construction context of this update.
      Returns:
      the caller location for the construction context of this update, or null if not available
      See Also:
    • identity

      public static <M> Update<M> identity()
      Returns an update that has no effect.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Returns:
      an update that has no effect
    • andThen

      public Update<M> andThen(Update<M> next)
      Returns an update that performs the effect of this and a given other update in sequence.
      Parameters:
      next - the update to perform after this update
      Returns:
      an update that performs the effect of this followed by the effect of next
      Throws:
      NullPointerException - if next is null
    • setValue

      public static <M> Update<M> setValue(Data value)
      Returns an update that sets the accumulator to the given value.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      value - the new accumulator value
      Returns:
      an update that sets the accumulator to value
      Throws:
      NullPointerException - if value is null
    • setEntry

      public static <M> Update<M> setEntry(Object key, Data value)
      Returns an update that maps the given key to the given value.

      Any previous value associated with the given key is overwritten. Entries are scoped and can be undone with pop().

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key to map
      value - the new value
      Returns:
      an update that maps key to value
      Throws:
      NullPointerException - if key or value is null
    • setEntries

      public static <M> Update<M> setEntries(Map<Object,? extends Data> entries)
      Returns an update that maps the given keys to the given values simultaneously.

      Any previous value associated with a given key is overwritten. Entries are scoped and can be undone with pop().

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      entries - the new key–value entries
      Returns:
      an update that maps each key of entries to the corresponding value
      Throws:
      NullPointerException - if entries is or contains null
    • push

      public static <M> Update<M> push()
      Returns an update that enters a new scope.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Returns:
      an update that enters a new scope
      See Also:
    • pushEntry

      public static <M> Update<M> pushEntry(Object key, Data value)
      Returns an update that enters a new scope and maps the given key to the given value.

      Any previous value associated with the given key is overwritten. Entries can be undone with pop().

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key to map
      value - the new value
      Returns:
      an update that enters a new scope and maps key to value
      Throws:
      NullPointerException - if key or value is null
      See Also:
    • pushEntries

      public static <M> Update<M> pushEntries(Map<?,? extends Data> entries)
      Returns an update that enters a new scope and maps the given keys to the given values simultaneously.

      Any previous value associated with a given key is overwritten. Entries can be undone with pop().

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      entries - the new key–value entries
      Returns:
      an update that enters a new scope and maps each key of entries to the corresponding value
      Throws:
      NullPointerException - if entries is or contains null
      See Also:
    • pop

      public static <M> Update<M> pop()
      Returns an update that leaves and discards the most recent scope.

      All key–value mappings established since the creation of the scope are undone.

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Returns:
      an update that leaves and discards the most recent scope
      See Also:
    • assign

      public static <M> Update<M> assign(Object key)
      Returns an update that assigns the current accumulator value to the given key.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key
      Returns:
      an update that assigns the current accumulator value to key
      Throws:
      NullPointerException - if key is null
      See Also:
    • access

      public static <M> Update<M> access(Object key)
      Returns an update that copies the value currently assigned to the given key to the accumulator.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key
      Returns:
      an update that copies the value currently assigned to key to the accumulator
      Throws:
      NullPointerException - if key is null
      See Also:
    • addTo

      public static <M> Update<M> addTo(Object key)
      Returns an update that adds the current accumulator value as an element to the sequence assigned to the given key.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key
      Returns:
      an update that adds the current accumulator value as an element to the sequence assigned to key
      Throws:
      NullPointerException - if key is null
      UnsupportedOperationException - if the value assigned to key is not a sequence (FIXME: at next stage)
      IllegalArgumentException - if there is no value assigned to key (FIXME: at next stage)
    • remove

      public static <M> Update<M> remove(Object key)
      Returns an update that removes the assignment to the given key.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      key - the key
      Returns:
      an update that removes the assignment to key
      Throws:
      NullPointerException - if key is null
      See Also:
    • removeAll

      public static <M> Update<M> removeAll(Object... keys)
      Returns an update that removes the assignments to the given keys.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      keys - the keys
      Returns:
      an update that removes the assignments to all elements of keys
      Throws:
      NullPointerException - if keys is null
    • removeAll

      public static <M> Update<M> removeAll(Collection<?> keys)
      Returns an update that removes the assignments to the given keys.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      keys - the keys
      Returns:
      an update that removes the assignments to all elements of keys
      Throws:
      NullPointerException - if keys is null
    • choice

      @SafeVarargs public static <M> Update<M> choice(Update<M>... alts)
      Returns an update that tries the given alternatives in order.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      alts - the alternatives
      Returns:
      an update that tries the elements of alts in order
      Throws:
      NullPointerException - if alts is or contains null
    • lift

      public static <M> Update<M> lift(Action.Continuation<? super State,State,M,State> cont)
      Returns an update that performs the given continuation.

      The string description of the update is derived from the continuation.

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      cont - the continuation to perform
      Returns:
      an update that performs the given continuation
      Throws:
      NullPointerException - if cont is null
    • lift

      public static <M> Update<M> lift(Action.Continuation<? super State,State,M,State> cont, @Opt String description)
      Returns an update that performs the given continuation.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      cont - the continuation to perform
      description - a string description for the result
      Returns:
      an update that performs the given continuation
      Throws:
      NullPointerException - if cont is null
    • lift

      public static <M> Update<M> lift(Action.Continuation<? super State,State,M,State> cont, Supplier<@Opt String> description)
      Returns an update that performs the given continuation.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      cont - the continuation to perform
      description - a supplier for a a string description for the result
      Returns:
      an update that performs the given continuation
      Throws:
      NullPointerException - if cont or description is null
    • map

      public static <M> Update<M> map(UnaryOperator<Data> op)
      Returns an update that purely transforms the accumulator value with a given function.

      The resulting update is deterministic and has no side-effects.

      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      op - the function to transform the accumulator value with
      Returns:
      an update that purely transforms the accumulator value with op
      Throws:
      NullPointerException - if op is null
    • merge

      public static <M> Update<M> merge(BinaryOperator<Data> op, Update<M> first, Update<M> second)
      Returns an update that performs a pair of updates, and combines their resulting accumulator values.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      op - the operator for combining the accumulator values
      first - the first update
      second - the second update
      Returns:
      an update that performs first followed by second, and combines their resulting values with op
      Throws:
      NullPointerException - if op, first or second is null
    • merge

      public static <M> Update<M> merge(Action.BiContinuation<Data,Data,Data,M,State> op, Update<M> first, Update<M> second)
      Returns an update that performs a pair of updates, and combines their resulting accumulator values.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      op - the binary continuation for combining the accumulator values
      first - the first update
      second - the second update
      Returns:
      an update that performs first followed by second, and combines their resulting values with op
      Throws:
      NullPointerException - if op, first or second is null
    • ignoringResult

      public Update<M> ignoringResult()
      Returns an update that behaves like this update, but does not change the accumulator value.
      Returns:
      an update that behaves like this update, but does not change the accumulator value
    • diagnose

      @SafeVarargs public static <M> Update<M> diagnose(M... messages)
      Returns an update that attaches the given messages.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Parameters:
      messages - the messages to attach
      Returns:
      an update that attaches all elements of messages
      Throws:
      NullPointerException - if messages is null
    • reject

      public static <M> Update<M> reject()
      Returns an update that fails and refers to the current state as obstruction.
      Type Parameters:
      M - the type of diagnostic messages attached to stems
      Returns:
      an update that fails and refers to the current state as obstruction
      See Also: