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

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

    Constructors
    Constructor
    Description
    Create an empty MapVarTable.
  • Method Summary

    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

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

  • Constructor Details

    • MapVarTable

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

    • empty

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

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

      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

      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

      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

      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

      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

      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

      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