Class FlowElement<T>

java.lang.Object
com.amalgamasimulation.discreterate.FlowElement<T>
Type Parameters:
T - type (class or interface) whose instances represent materials
Direct Known Subclasses:
Bunker, Conveyor, Merge, ReversibleConveyor, Split, Tank, Valve

public abstract class FlowElement<T> extends Object
FlowElement is the base class for all flow elements.

A flow element can accept, store, or export some material or mix of materials.

Material is moved between flow elements through FlowConnections. Flow connections define the direction of material flow among flow elements.

Author:
Alexander Morozov
  • Method Details

    • getInflowConnections

      public List<FlowConnection<T>> getInflowConnections()
      Returns an unmodifiable list of FlowConnection instances that represent incoming connections of this flow element.
      Returns:
      unmodifiable list of inflow connections
      See Also:
    • getOutflowConnections

      public List<FlowConnection<T>> getOutflowConnections()
      Returns the unmodifiable list of FlowConnection instances that represent outgoing connections of this flow element.
      Returns:
      unmodifiable list of outflow connections
      See Also:
    • connectToElement

      public FlowConnection<T> connectToElement(FlowElement<T> dest)
      Connects the output of this flow element to the input of the dest flow element.
      Parameters:
      dest - flow element to connect to
      Returns:
      a new FlowConnection, with this flow element as its source and dest flow element as its destination
      Throws:
      NullPointerException - if the dest flow element is null
      IllegalArgumentException - if the dest flow element belongs to a different FlowEnvironment than this flow element
      See Also:
    • disconnectFrom

      public FlowConnection<T> disconnectFrom(FlowElement<T> destElement)
      Disconnects the current flow element from the destElement flow element, if a connection from this flow element to the destElement flow element exists.
      Parameters:
      destElement - flow element to be disconnected from
      Returns:
      a FlowConnection between this flow element and the destElement that was removed during the method call; null if no connection existed
      Throws:
      IllegalArgumentException - if destElement belongs to a different FlowEnvironment than this flow element
    • getTotalInflowAmount

      public abstract double getTotalInflowAmount()
      Returns the total amount of all materials that have entered this flow element.
      Returns:
      total amount of all arrived materials
    • getTotalInflowAmount

      public abstract double getTotalInflowAmount(T material)
      Returns the total amount of the specified material that has entered this flow element.
      Parameters:
      material - material
      Returns:
      total amount of the specified material that has arrived to this flow element
      See Also:
    • getTotalInflowDescriptor

      public abstract Accumulator<T> getTotalInflowDescriptor()
      Returns an Accumulator instance that contains the total quantity of each material that has entered this flow element.

      The values of each element in the returned Accumulator match the quantities of the respective materials that have entered the flow element. The sum of values in the Accumulator is equal to the value returned by the getTotalInflowAmount() method.

      Returns:
      Accumulator containing total amounts of materials that have entered this flow element
      See Also:
    • getTotalOutflowAmount

      public abstract double getTotalOutflowAmount()
      Returns the total quantity of materials that have left this flow element.
      Returns:
      total quantity of exported materials
      See Also:
    • getTotalOutflowAmount

      public abstract double getTotalOutflowAmount(T material)
      Returns the total quantity of the specified material that has left this flow element.
      Parameters:
      material - material
      Returns:
      total quantity of the specified material that has left this flow element
      See Also:
    • getTotalOutflowDescriptor

      public abstract Accumulator<T> getTotalOutflowDescriptor()
      Returns an Accumulator instance that holds the total amounts of each material that has left this flow element.

      The values of each element in the returned Accumulator match the quantities of the respective materials that have left the flow element. The sum of values in the Accumulator is equal to the value returned by the getTotalOutflowAmount() method.

      Returns:
      Accumulator containing total amounts of materials that have left this flow element
      See Also:
    • getName

      public final String getName()
      Returns the name of this flow element.
      Returns:
      name of this flow element
    • isConnectedWith

      public final boolean isConnectedWith(FlowElement<T> element)
      Checks whether a connection exists between this flow element and the element flow element. The direction of the connection is arbitrary.
      Parameters:
      element - another flow element
      Returns:
      true if a FlowConnection exists that connects the current flow element and the element, false otherwise
      See Also:
    • inflowConnectionExists

      public final boolean inflowConnectionExists()
      Indicates that at least one incoming flow connection exists.
      Returns:
      true if that at least one incoming flow connection exists, false otherwise
    • outflowConnectionExists

      public final boolean outflowConnectionExists()
      Indicates that at least one outgoing flow connection exists.
      Returns:
      true if that at least one outgoing flow connection exists, false otherwise
    • getFlowEnvironment

      public final FlowEnvironment<T> getFlowEnvironment()
      Returns the FlowEnvironment which this flow element belongs to.
      Returns:
      FlowEnvironment which this flow element belongs to
    • getContentsAmount

      public abstract double getContentsAmount()
      Returns the total quantity of all materials inside this flow element.
      Returns:
      current sum of all material quantities inside this flow element
      See Also:
    • getContentsAmount

      public abstract double getContentsAmount(T material)
      Returns the current quantity of the specified material inside this flow element.
      Parameters:
      material - material
      Returns:
      current quantity of the specified material inside this flow element
      See Also:
    • getContentsDescriptor

      public abstract Accumulator<T> getContentsDescriptor()
      Returns all materials contained inside this flow element as an instance of Accumulator.

      Each element of the Accumulator matches the amount of the corresponding material inside this flow element. The sum of amounts of materials in the Accumulator instance is equal to the value returned by the getContentsAmount() method.

      Returns:
      Accumulator containing all materials inside the flow element
      See Also:
    • getInflowRate

      public abstract double getInflowRate()
      Returns the current flow rate of all materials at the input of this flow element.
      Returns:
      current flow rate of all materials at this flow element's input
      See Also:
    • getInflowRateDescriptor

      public abstract Accumulator<T> getInflowRateDescriptor()
      Returns an Accumulator instance that describes the flow rate at the input of this flow element.

      The returned Accumulator instance contains the respective rates of all materials currently entering the flow element. The sum of values in the Accumulator is equal to 1.

      Returns:
      descriptor of the current inflow rate
      See Also:
    • getOutflowRate

      public abstract double getOutflowRate()
      Returns the current flow rate at the output of this flow element.
      Returns:
      current flow rate at the output of this flow element
      See Also:
    • getOutflowRateDescriptor

      public abstract Accumulator<T> getOutflowRateDescriptor()
      Returns an Accumulator instance that describes the flow rate at the output of this flow element.

      The returned Accumulator instance contains the respective rates of all materials currently leaving the flow element. The sum of values in the Accumulator is equal to 1.

      Returns:
      descriptor of the current outflow rate
      See Also:
    • getOutflowRateProportions

      public abstract Accumulator<T> getOutflowRateProportions(FlowConnection<T> outflowConnection)
      Returns an Accumulator instance that contains flow rate proportions of materials exported through the outflowConnection outflow connection.

      Each element of the returned Accumulator corresponds to a material in the current material flow of outflowConnection. The value of each element in the Accumulator is the ratio of the rate of that material's partial flow to the overall flow rate of outflowConnection. The sum of values in the Accumulator is equal to 1.

      Parameters:
      outflowConnection - an outflow connection
      Returns:
      material proportions in the outflow connection
      Throws:
      IllegalArgumentException - if the outflowConnection is not related to this flow element
    • addInflowElementConnectedHandler

      public void addInflowElementConnectedHandler(Consumer<FlowConnection<T>> handler)
      Adds an action that will be executed every time when a new inflow element is connected.
      Parameters:
      handler - action that will be executed every time when a new inflow element is connected
      See Also:
    • removeInflowElementConnectedHandler

      public void removeInflowElementConnectedHandler(Consumer<FlowConnection<T>> handler)
      Removes the previously added inflow element connect handler.
      Parameters:
      handler - previously added inflow element connect handler
      See Also:
    • addOutflowElementConnectedHandler

      public void addOutflowElementConnectedHandler(Consumer<FlowConnection<T>> handler)
      Adds an action that will be executed every time when a new outflow element is connected.
      Parameters:
      handler - action that will be executed every time when a new outflow element is connected
      See Also:
    • removeOutflowElementConnectedHandler

      public void removeOutflowElementConnectedHandler(Consumer<FlowConnection<T>> handler)
      Removes the previously added outflow element connect handler.
      Parameters:
      handler - previously added outflow element connect handler
      See Also:
    • addInflowElementDisconnectedHandler

      public void addInflowElementDisconnectedHandler(Consumer<FlowConnection<T>> handler)
      Adds an action that will be executed every time when a new inflow element is disconnected.
      Parameters:
      handler - action that will be executed every time when a new inflow element is disconnected
      See Also:
    • removeInflowElementDisconnectedHandler

      public void removeInflowElementDisconnectedHandler(Consumer<FlowConnection<T>> handler)
      Removes the previously added inflow element disconnect handler.
      Parameters:
      handler - previously added inflow element disconnect handler
      See Also:
    • addOutflowElementDisconnectedHandler

      public void addOutflowElementDisconnectedHandler(Consumer<FlowConnection<T>> handler)
      Adds an action that will be executed every time when a new outflow element is disconnected.
      Parameters:
      handler - action that will be executed every time when a new outflow element is disconnected
      See Also:
    • removeOutflowElementDisconnectedHandler

      public void removeOutflowElementDisconnectedHandler(Consumer<FlowConnection<T>> handler)
      Removes the previously added outflow element disconnect handler.
      Parameters:
      handler - previously added outflow element disconnect handler
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object