Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Talk to us above model/view/controller, particularly for this.
See the whiteboard for details.
A slight change, to follow common terminology
Note: keys can be any type, rather than just string.
The interface
/**
* A dictionary of values of type V keyed by values of type K.
*/
public interface Dictionary<K,V>
{
/**
* Confirm that a key is valid.
*/
public boolean containsKey(K key);
/**
* Change the entry for a particular key.
*
* @pre key is a valid key for the dictionary
* @post get(key) == value
*/
public void set(K key, V value)
throws NoSuchKeyException;
/**
* Add the entry for a particular key.
*
* @pre key is not a valid key for the dictionary
* @post get(key) == value
*/
public void add(K key, V value)
throws Exception;
/**
* Get the entry for a particular key.
*
* @throws NoSuchElementException
* If the key is not a valid key for the dictionary.
*/
public V get(K key)
throws NoSuchElementException;
/**
* Add a bunch of keys and values.
*
* @pre
* keys.length == values.length
* @pre
* No element of keys is null.
* @pre
* No two elements of keys are equal.
* @pre
* No elements of keys are already valid.
*/
public void addAll(K[] keys, V[] values)
throws SomeRandomException;
/**
* Remove a value based on its key.
*/
public void remove(K key);
/**
* Remove everything.
*/
public void clear();
/**
* Remove all the entries with a given value.
*/
public void removeAll(V val);
/**
* Get all of the keys in the dictionary.
*/
public Iterator<K> keys();
/**
* Get all of the values in the dictionary.
*/
public Iterator<V> values();
/**
* Get all of the key/value pairs in the dictionary.
*/
public Iterator<Pair<K,V>> pairs();
/**
* Update all of the values.
*/
public void map(BinaryFunction<K,V,V> update);
} // interface Dictionary<K,V>
Some design questions, major and minor
set and add?
sort do?values or iterator?remove in the structure or in the iterator (or both)?Deprecated
/**
* Create an array of keys.
*/
public K[] keyArray();
/**
* Create an array of values.
*/
public V[] valuesArray();
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.