Package sim.des

Class Transformer

java.lang.Object
sim.portrayal.SimplePortrayal2D
sim.portrayal.simple.InternalPortrayal2D
All Implemented Interfaces:
Serializable, Named, Parented, ProvidesBarData, Receiver, Resettable, sim.engine.Steppable, sim.portrayal.Portrayal, sim.portrayal.Portrayal2D

public class Transformer extends Filter
A currency converter, so to speak. Transformer takes a RESOURCE and returns a COUNTABLE RESOURCE, normally of a different type, by converting the value of the resource into the value of the new one, and then offering the new resource.

If the original resource was also a countable resource, then it is converted by multiplying it by a conversion factor. For example, if we were converting dollars to euros, and one dollar was worth 1.5 euros, we might set the conversion to 1.5. If the downstream receiver accepts the offer but only partially, then the original resource is modified accordingly according to the conversion factor.

If the original resource was an Entity, then we simply offer the conversion factor. Thus one entity might be worth 1.5 euros. By default, if the original resource type is an Entity, Transformer is automatically set to take-it-or-leave-it offers. Thus if the downstream receiver must accept the offer totally. You can change this by setting take-it-or-leave-it to false; now if the downstream receiver accepts the offer only partially, the Entity is consumed regardless.

See Also:
  • Constructor Details

    • Transformer

      public Transformer(sim.engine.SimState state, CountableResource typicalProvided, Resource typicalReceived, double conversion)
  • Method Details

    • buildDefaultPortrayal

      public sim.portrayal.SimplePortrayal2D buildDefaultPortrayal(double scale)
      Description copied from class: DESPortrayal
      Builds the "base portrayal" for the object, if the image path and class haven't been set (and thus the portrayal isn't an ImagePortrayal2D). The default sets to a simple gray and black quare.
      Overrides:
      buildDefaultPortrayal in class DESPortrayal
    • provide

      public boolean provide(Receiver receiver, double atMost)
      Description copied from class: Provider
      Asks the Provider to make a unilateral offer of up to the given amount to the given Receiver. If the typical provided resource is an ENTITY, then atMost is ignored. This can be used to implement a simple pull. The Receiver does not need to be registered with the Provider. Returns true if the offer was accepted; though since the Receiver itself likely made this call, it's unlikely that this would ever return anything other than TRUE in a typical simulation.

      atMost must be a positive non-zero, non-NAN number.

      Overrides:
      provide in class Filter
    • getTypicalReceived

      public Resource getTypicalReceived()
      Description copied from interface: Receiver
      Returns the typical kind of resource the receiver can accept. When a Receiver is also a Provider, this is very often implemented simply by calling getTypicalProvided(). If (rarely) the Receiver may receive a variety of types, such as a Composer, then this method should return null.
      Specified by:
      getTypicalReceived in interface Receiver
      Overrides:
      getTypicalReceived in class Middleman
    • accept

      public boolean accept(Provider provider, Resource amount, double atLeast, double atMost)
      Description copied from class: Filter
      Override this as you like. The default version offers to downstream Receivers whatever it is being offered here; and then calls process(...) to process the difference between the two. By default process(...) does nothing, but you could override that too.
      Specified by:
      accept in interface Receiver
      Overrides:
      accept in class Filter
    • toString

      public String toString()
      Overrides:
      toString in class Filter