Package dsa.lab05.exercises
Class SortedArrayMap<Key extends Comparable<Key>,Value> 
java.lang.Object
dsa.lab05.exercises.SortedArrayMap<Key,Value> 
- Type Parameters:
- Key- the key type
- Value- the value type
- All Implemented Interfaces:
- Container<MapItem<Key,,- Value>> - Map<Key,,- Value> - OrderedMap<Key,,- Value> - Iterable<MapItem<Key,- Value>> 
public class SortedArrayMap<Key extends Comparable<Key>,Value> 
extends Object
implements OrderedMap<Key,Value> 
A sorted array map.
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct an empty sorted array map.SortedArrayMap(MapItem<Key, Value>... items) Construct a sorted array map containing the given items.SortedArrayMap(Iterable<MapItem<Key, Value>> items) Construct a sorted array map containing the given items.SortedArrayMap(Iterable<MapItem<Key, Value>> items, int size) Construct a sorted array map containing the given items more efficiently thanSortedArrayMap(Iterable).
- 
Method SummaryModifier and TypeMethodDescriptionFind the item with the given key.voidInsert the given item.items()Get a forward iterable that yields each item once.max()Get the item with the greatest key.min()Get the item with the least key.Get the item that would be the successor of one with the given key.Get the item that would be the predecessor of one with the given key.Remove and return the item with the given key.reversed()Get a reverse iterable that yields each item once.intsize()Get the number of contained items.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliteratorMethods inherited from interface dsa.lab04.base.MapcontainsKey, containsValue, get, insert, valuesMethods inherited from interface dsa.lab05.base.OrderedMapkeys, reversedKeys
- 
Constructor Details- 
SortedArrayMappublic SortedArrayMap()Construct an empty sorted array map.
- 
SortedArrayMapConstruct a sorted array map containing the given items.- Parameters:
- items- the items
 
- 
SortedArrayMapConstruct a sorted array map containing the given items more efficiently thanSortedArrayMap(Iterable).- Parameters:
- items- the items
- size- the number of items
- Throws:
- IllegalArgumentException- if- size!=- n(where- nis- items's size)
 
- 
SortedArrayMapConstruct a sorted array map containing the given items.- Parameters:
- items- the items
 
 
- 
- 
Method Details- 
sizepublic int size()Description copied from interface:ContainerGet the number of contained items.- Specified by:
- sizein interface- Container<Key extends Comparable<Key>>
- Returns:
- the size
 
- 
findDescription copied from interface:MapFind the item with the given key.- Specified by:
- findin interface- Map<Key extends Comparable<Key>,- Value> 
- Parameters:
- key- the item's key
- Returns:
- the item
- Throws:
- NoSuchElementException- if no item has key- key
 
- 
insertDescription copied from interface:MapInsert the given item.If there's already an item with the same key, that item is replaced with this one. This means that if the key was not already contained, the size is incremented, otherwise it isn't. 
- 
removeDescription copied from interface:MapRemove and return the item with the given key.Decrements the size (assuming the item was actually in the map). - Specified by:
- removein interface- Map<Key extends Comparable<Key>,- Value> 
- Parameters:
- key- the item's key
- Returns:
- the item
- Throws:
- NoSuchElementException- if- keyis not contained
 
- 
previousDescription copied from interface:OrderedMapGet the item that would be the predecessor of one with the given key.The map may or may not contain an item with the given key. - Specified by:
- previousin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Parameters:
- key- a key
- Returns:
- the previous item (by key), or nullif there is none
 
- 
nextDescription copied from interface:OrderedMapGet the item that would be the successor of one with the given key.The map may or may not contain an item with the given key. - Specified by:
- nextin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Parameters:
- key- a key
- Returns:
- the next item (by key), or nullif there is none
 
- 
minDescription copied from interface:OrderedMapGet the item with the least key.- Specified by:
- minin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Returns:
- the minimum item (by key), or nullif there is none
 
- 
maxDescription copied from interface:OrderedMapGet the item with the greatest key.- Specified by:
- maxin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Returns:
- the maximum item (by key), or nullif there is none
 
- 
itemsDescription copied from interface:OrderedMapGet a forward iterable that yields each item once.The items are iterated over in least-to-greatest order (by key). - Specified by:
- itemsin interface- Container<Key extends Comparable<Key>>
- Specified by:
- itemsin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Returns:
- an iterable over the items
 
- 
reversedDescription copied from interface:OrderedMapGet a reverse iterable that yields each item once.The items are iterated over in greatest-to-least order (by key). - Specified by:
- reversedin interface- OrderedMap<Key extends Comparable<Key>,- Value> 
- Returns:
- an iterable over the items
 
 
-