UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.collection
Class Map2D

java.lang.Object
  |
  +--edu.berkeley.guir.lib.collection.Map2D

public class Map2D
extends Object

A two-dimensional map whose rows and columns are indexed by arbitrary Java objects (like keys in a Java Map). Adding and removing rows are more efficient than adding and removing columns.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.2-1.0.0, Jun 23 2000, JL
               Created class
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.2
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
James Lin ( jimlin@cs.berkeley.edu )

Constructor Summary
Map2D()
          Constructs a new 2D map.
Map2D(Map2D old)
          Constructs a new 2D map with the contents of the given map.
 
Method Summary
 boolean addCol(Object header)
          Adds a column with the given header to the grid, or does nothing if the header already exists.
 boolean addRow(Object header)
          Adds a row with the given header to the 2D map, or does nothing if the header already exists.
 Object clone()
           
 boolean containsCol(Object header)
          Returns whether there is a column with the given header.
 boolean containsRow(Object header)
          Returns whether there is a row with the given header.
 boolean copyCol(Object fromHeader, Object toHeader)
          Shallow copies the data from one column to another.
 Object get(Object rowHeader, Object colHeader)
          Gets the data at the given row and column, or null if there is not any.
 Set getCols()
          Returns a set of column headers.
 Set getRows()
          Returns a set of row headers.
static void main(String[] args)
          Self-testing main
 Object matchCol(Map colData)
          Returns the header of a column that matches the given collection of data, or null if there is no match.
 Object matchRow(Map rowData)
          Returns the header of a row that matches the given collection of data, or null if there is no match.
 void put(Object rowHeader, Object colHeader, Object data)
          Puts the data at the given row and column.
 boolean removeCol(Object header)
          Removes the column with the given header, if it exists.
 boolean removeRow(Object header)
          Removes the row with the given header, if it exists.
 boolean renameCol(Object oldHeader, Object newHeader)
          Renames the column with the given header to the given new name.
 boolean renameRow(Object oldHeader, Object newHeader)
          Renames the row with the given header to the given new name, if it exists.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Map2D

public Map2D()
Constructs a new 2D map.

Map2D

public Map2D(Map2D old)
Constructs a new 2D map with the contents of the given map.
Method Detail

addRow

public boolean addRow(Object header)
Adds a row with the given header to the 2D map, or does nothing if the header already exists. Returns whether the row was added.

containsRow

public boolean containsRow(Object header)
Returns whether there is a row with the given header.

removeRow

public boolean removeRow(Object header)
Removes the row with the given header, if it exists.
Returns:
whether the grid had a row with the given header

renameRow

public boolean renameRow(Object oldHeader,
                         Object newHeader)
Renames the row with the given header to the given new name, if it exists.
Returns:
whether the grid had a row with the given old header

addCol

public boolean addCol(Object header)
Adds a column with the given header to the grid, or does nothing if the header already exists. Returns whether the column was added.

containsCol

public boolean containsCol(Object header)
Returns whether there is a column with the given header.

removeCol

public boolean removeCol(Object header)
Removes the column with the given header, if it exists.
Returns:
whether the grid had a column with the given header

renameCol

public boolean renameCol(Object oldHeader,
                         Object newHeader)
Renames the column with the given header to the given new name.
Returns:
whether the grid had a row with the given old header

copyCol

public boolean copyCol(Object fromHeader,
                       Object toHeader)
Shallow copies the data from one column to another.
Returns:
whether the data was copied

put

public void put(Object rowHeader,
                Object colHeader,
                Object data)
Puts the data at the given row and column. Creates the row and column if it does not exist.

get

public Object get(Object rowHeader,
                  Object colHeader)
Gets the data at the given row and column, or null if there is not any.

getRows

public Set getRows()
Returns a set of row headers.

getCols

public Set getCols()
Returns a set of column headers.

matchRow

public Object matchRow(Map rowData)
Returns the header of a row that matches the given collection of data, or null if there is no match.

matchCol

public Object matchCol(Map colData)
Returns the header of a column that matches the given collection of data, or null if there is no match.

toString

public String toString()
Overrides:
toString in class Object

clone

public Object clone()
Overrides:
clone in class Object

main

public static void main(String[] args)
Self-testing main

Copyright Information