Package cs2110

Class MapVarTable

java.lang.Object
cs2110.MapVarTable
All Implemented Interfaces:
VarTable

public class MapVarTable extends Object implements VarTable
A VarTable implemented using a Map from the Java Collections Framework.
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    (package private) Map<String,Double>
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Create an empty MapVarTable.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    boolean
    Return whether variable `name` is currently associated with a value in this table.
    Create an empty MapVarTable.
    double
    get(String name)
    Return the value associated with the variable `name`.
    Return the names of all variables associated with a value in this table.
    of(String name1, double value1)
    Create a MapVarTable associating `value1` with variable `name1`.
    of(String name1, double value1, String name2, double value2)
    Create a MapVarTable associating `value1` with variable `name1` and `value2` with `name2`.
    void
    set(String name, double value)
    Associate `value` with variable `name` in this table, replacing any previously assigned value.
    int
    Return the number of variables associated with values in this table.
    void
    unset(String name)
    Remove any value associated with variable `name` in this table.

    Methods inherited from class java.lang.Object Link icon

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

  • Constructor Details Link icon

    • MapVarTable Link icon

      public MapVarTable()
      Create an empty MapVarTable.
  • Method Details Link icon

    • empty Link icon

      public static MapVarTable empty()
      Create an empty MapVarTable.
    • of Link icon

      public static MapVarTable of(String name1, double value1)
      Create a MapVarTable associating `value1` with variable `name1`.
    • of Link icon

      public static MapVarTable of(String name1, double value1, String name2, double value2)
      Create a MapVarTable associating `value1` with variable `name1` and `value2` with `name2`.
    • get Link icon

      public double get(String name) throws UnboundVariableException
      Description copied from interface: VarTable
      Return the value associated with the variable `name`. Throws UnboundVariableException if `name` is not associated with a value in this table.
      Specified by:
      get in interface VarTable
      Throws:
      UnboundVariableException
    • set Link icon

      public void set(String name, double value)
      Description copied from interface: VarTable
      Associate `value` with variable `name` in this table, replacing any previously assigned value.
      Specified by:
      set in interface VarTable
    • unset Link icon

      public void unset(String name)
      Description copied from interface: VarTable
      Remove any value associated with variable `name` in this table.
      Specified by:
      unset in interface VarTable
    • contains Link icon

      public boolean contains(String name)
      Description copied from interface: VarTable
      Return whether variable `name` is currently associated with a value in this table.
      Specified by:
      contains in interface VarTable
    • size Link icon

      public int size()
      Description copied from interface: VarTable
      Return the number of variables associated with values in this table.
      Specified by:
      size in interface VarTable
    • names Link icon

      public Set<String> names()
      Description copied from interface: VarTable
      Return the names of all variables associated with a value in this table.
      Specified by:
      names in interface VarTable