Package org.jspace

Class SequentialSpace

java.lang.Object
org.jspace.SequentialSpace
All Implemented Interfaces:
Space
Direct Known Subclasses:
PileSpace, QueueSpace, RandomSpace

public class SequentialSpace
extends java.lang.Object
implements Space
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected int bound  
    protected java.util.LinkedList<Tuple> tuples  
  • Constructor Summary

    Constructors
    Constructor Description
    SequentialSpace()
    Create an unbounded sequential space.
    SequentialSpace​(int bound)
    Create a new sequential space with bound that limits the number of tuples that can be inserted in the space.
  • Method Summary

    Modifier and Type Method Description
    protected void addTuple​(Tuple tuple)  
    protected java.util.LinkedList<java.lang.Object[]> findAllTuples​(Template template, boolean toRemove)  
    protected Tuple findTuple​(Template template, boolean toRemove)  
    java.lang.Object[] get​(TemplateField... fields)
    Retrieves (and remove) a tuple matching the requested template.
    java.util.LinkedList<java.lang.Object[]> getAll​(TemplateField... fields)
    Retrieves (and remove) all the tuples matching a template.
    java.lang.Object[] getp​(TemplateField... fields)
    Retrieves (and remove) a tuple matching the requested template.
    boolean put​(java.lang.Object... fields)
    Adds a tuple in the space.
    java.lang.Object[] query​(TemplateField... fields)
    Reads (without removing) a tuple matching the requested template.
    java.util.LinkedList<java.lang.Object[]> queryAll​(TemplateField... fields)
    Reads (without removing) all the tuples matching the requested template.
    java.lang.Object[] queryp​(TemplateField... fields)
    Reads (without removing) a tuple matching the requested template.
    int size()
    Returns the number of tuples that are stored in the space.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • bound

      protected final int bound
    • tuples

      protected final java.util.LinkedList<Tuple> tuples
  • Constructor Details

    • SequentialSpace

      public SequentialSpace()
      Create an unbounded sequential space.
    • SequentialSpace

      public SequentialSpace​(int bound)
      Create a new sequential space with bound that limits the number of tuples that can be inserted in the space.
      Parameters:
      bound - max number of tuples in the space.
  • Method Details

    • put

      public boolean put​(java.lang.Object... fields) throws java.lang.InterruptedException
      Description copied from interface: Space
      Adds a tuple in the space.
      Specified by:
      put in interface Space
      Parameters:
      fields - fields of inserted tuple
      Returns:
      true if the action has been successfully executed false otherwise.
      Throws:
      java.lang.InterruptedException - if any thread interrupted the current thread before the action is executed.
    • addTuple

      protected void addTuple​(Tuple tuple)
    • get

      public java.lang.Object[] get​(TemplateField... fields) throws java.lang.InterruptedException
      Description copied from interface: Space
      Retrieves (and remove) a tuple matching the requested template. A template is rendered as an array of TemplateField. The returned, say result will satisfy the following properties:
      • result.length==fields.length;
      • for any i, fields[i].match(return[i])==true.
      Current thread is suspended until a tuple matching the requested template is found.
      Specified by:
      get in interface Space
      Parameters:
      fields - an array of template fields representing the requested template
      Returns:
      a tuple matching the requested template
      Throws:
      java.lang.InterruptedException - if any thread interrupted the current thread before the action is executed.
    • findTuple

      protected Tuple findTuple​(Template template, boolean toRemove)
    • findAllTuples

      protected java.util.LinkedList<java.lang.Object[]> findAllTuples​(Template template, boolean toRemove)
    • getp

      public java.lang.Object[] getp​(TemplateField... fields)
      Description copied from interface: Space
      Retrieves (and remove) a tuple matching the requested template. A template is rendered as an array of TemplateField. The returned, say result will satisfy the following properties:
      • result.length==fields.length;
      • for any i, fields[i].match(return[i])==true.
      If a tuple matching the requested tempalte is not found, null is returned.
      Specified by:
      getp in interface Space
      Parameters:
      fields - an array of template fields representing a template
      Returns:
      a tuple matching the template or null if no tuple matches the template
    • getAll

      public java.util.LinkedList<java.lang.Object[]> getAll​(TemplateField... fields)
      Description copied from interface: Space
      Retrieves (and remove) all the tuples matching a template. If no matching tuple is found, the empty list is returned.
      Specified by:
      getAll in interface Space
      Parameters:
      fields - an array of template fields representing a template
      Returns:
      a list containing all the tuples matching the template
    • query

      public java.lang.Object[] query​(TemplateField... fields) throws java.lang.InterruptedException
      Description copied from interface: Space
      Reads (without removing) a tuple matching the requested template. A template is rendered as an array of TemplateField. The returned, say result will satisfy the following properties:
      • result.length==fields.length;
      • for any i, fields[i].match(return[i])==true.
      Current thread is suspended until a tuple matching the requested template is found.
      Specified by:
      query in interface Space
      Parameters:
      fields - an array of template fields representing the requested template
      Returns:
      a tuple matching the requested template
      Throws:
      java.lang.InterruptedException - if any thread interrupted the current thread before the action is executed.
    • queryp

      public java.lang.Object[] queryp​(TemplateField... fields)
      Description copied from interface: Space
      Reads (without removing) a tuple matching the requested template. A template is rendered as an array of TemplateField. The returned, say result will satisfy the following properties:
      • result.length==fields.length;
      • for any i, fields[i].match(return[i])==true.
      Value null is returned if no matching tuple is found.
      Specified by:
      queryp in interface Space
      Parameters:
      fields - an array of template fields representing the requested template
      Returns:
      a list containing all the tuples matching the template
    • queryAll

      public java.util.LinkedList<java.lang.Object[]> queryAll​(TemplateField... fields)
      Description copied from interface: Space
      Reads (without removing) all the tuples matching the requested template. A template is rendered as an array of TemplateField. The returned, say result will satisfy the following properties:
      • result.length==fields.length;
      • for any i, fields[i].match(return[i])==true.
      Specified by:
      queryAll in interface Space
      Parameters:
      fields - an array of template fields representing the requested template
      Returns:
      a list containing all the tuples matching the template
    • size

      public int size()
      Description copied from interface: Space
      Returns the number of tuples that are stored in the space.
      Specified by:
      size in interface Space