Package ball.util
Class CoordinateMap<V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- ball.util.MapView<Coordinate,V>
-
- ball.util.CoordinateMap<V>
-
- Type Parameters:
V
- The value type.
- All Implemented Interfaces:
Serializable
,Map<Coordinate,V>
,SortedMap<Coordinate,V>
,TableModel
public class CoordinateMap<V> extends MapView<Coordinate,V> implements SortedMap<Coordinate,V>, TableModel
Coordinate
Map
implementation.- Author:
- Allen D. Ball
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ball.util.MapView
MapView.EntrySet
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description CoordinateMap()
Constructor to create an emptyCoordinateMap
.CoordinateMap(Number yN, Number xN)
Constructor to specify maximumY
andX
(origin(0, 0)
).CoordinateMap(Number y0, Number x0, Number yN, Number xN)
Constructor to specify minimum and maximumY
andX
.
-
Method Summary
-
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
-
-
-
-
Constructor Detail
-
CoordinateMap
public CoordinateMap()
Constructor to create an emptyCoordinateMap
.
-
CoordinateMap
public CoordinateMap(Number y0, Number x0, Number yN, Number xN)
Constructor to specify minimum and maximumY
andX
.- Parameters:
y0
-MIN(y)
x0
-MIN(x)
yN
-MAX(y) + 1
xN
-MAX(x) + 1
-
CoordinateMap
public CoordinateMap(Number yN, Number xN)
Constructor to specify maximumY
andX
(origin(0, 0)
).- Parameters:
yN
-MAX(y) + 1
xN
-MAX(x) + 1
-
-
Method Detail
-
map
protected SortedMap<Coordinate,V> map()
- Overrides:
map
in classMapView<Coordinate,V>
- Returns:
- The "wrapped"
Map
.
-
getType
protected Type getType()
Method to get the value type ofthis
CoordinateMap
.- Returns:
- The value type
Class
.
-
resize
public CoordinateMap<V> resize(Number y0, Number x0, Number yN, Number xN)
Method to specify new limits for theCoordinateMap
.- Parameters:
y0
-MIN(y)
x0
-MIN(x)
yN
-MAX(y) + 1
xN
-MAX(x) + 1
- Returns:
this
CoordinateMap
.
-
resize
public CoordinateMap<V> resize(Number yN, Number xN)
Method to specify new limits for theCoordinateMap
with[y0, x0] = [0, 0]
.- Parameters:
yN
-MAX(y) + 1
xN
-MAX(x) + 1
- Returns:
this
CoordinateMap
.
-
getMin
public Coordinate getMin()
-
getMax
public Coordinate getMax()
-
getMinY
public int getMinY()
-
getMinX
public int getMinX()
-
getMaxY
public int getMaxY()
-
getMaxX
public int getMaxX()
-
includes
public boolean includes(Coordinate coordinate)
Method to determine if theCoordinate
is included inthis
CoordinateMap
's space. Because the map is sparse, this method may returntrue
whenAbstractMap.containsKey(Object)
returnsfalse
.- Parameters:
coordinate
- TheCoordinate
.- Returns:
true
if within the space;false
otherwise.
-
columns
public List<CoordinateMap<V>> columns()
Method to get aList
of columns (seecolumn(Number)
).- Returns:
- The
List
of columns.
-
rows
public List<CoordinateMap<V>> rows()
Method to get aList
of rows (seerow(Number)
).- Returns:
- The
List
of rows.
-
column
public CoordinateMap<V> column(Number x)
Method to get theList
representing the specified column backed by theCoordinateMap
.- Parameters:
x
- The X-coordinate.- Returns:
- The
CoordinateMap
representing the column.
-
row
public CoordinateMap<V> row(Number y)
Method to get theList
representing the specified row backed by theCoordinateMap
.- Parameters:
y
- The Y-coordinate.- Returns:
- The
CoordinateMap
representing the row.
-
subMap
public CoordinateMap<V> subMap(Number y0, Number x0, Number yN, Number xN)
- Parameters:
y0
-MIN(y)
x0
-MIN(x)
yN
-MAX(y) + 1
xN
-MAX(x) + 1
- Returns:
- The sub-
Map
(CoordinateMap
).
-
asList
public List<V> asList()
Method to getthis
CoordinateMap
values as aList
. Updates made throughList.set(int,Object)
will be made tothis
CoordinateMap
.- Returns:
- The
List
ofCoordinateMap
values.
-
containsKey
public boolean containsKey(Number y, Number x)
- Parameters:
y
- The Y-coordinate.x
- The X-coordinate.- Returns:
true
if theCoordinateMap
contains a key with the specifiedCoordinate
;false
otherwise.
-
get
public V get(Number y, Number x)
SeeMapView.get(Object)
.- Parameters:
y
- The Y-coordinate.x
- The X-coordinate.- Returns:
- The value at the coordinate (may be
null
).
-
put
public V put(Number y, Number x, V value)
- Parameters:
y
- The Y-coordinate.x
- The X-coordinate.value
- The value at the coordinate.- Returns:
- The previous value at the coordinate.
-
put
public V put(Coordinate key, V value)
- Specified by:
put
in interfaceMap<Coordinate,V>
- Overrides:
put
in classMapView<Coordinate,V>
-
remove
public V remove(Object key)
- Specified by:
remove
in interfaceMap<Coordinate,V>
- Overrides:
remove
in classMapView<Coordinate,V>
-
comparator
public Comparator<? super Coordinate> comparator()
- Specified by:
comparator
in interfaceSortedMap<Coordinate,V>
-
subMap
public CoordinateMap<V> subMap(Coordinate from, Coordinate to)
- Specified by:
subMap
in interfaceSortedMap<Coordinate,V>
-
headMap
public CoordinateMap<V> headMap(Coordinate key)
- Specified by:
headMap
in interfaceSortedMap<Coordinate,V>
-
tailMap
public CoordinateMap<V> tailMap(Coordinate key)
- Specified by:
tailMap
in interfaceSortedMap<Coordinate,V>
-
firstKey
public Coordinate firstKey()
- Specified by:
firstKey
in interfaceSortedMap<Coordinate,V>
-
lastKey
public Coordinate lastKey()
- Specified by:
lastKey
in interfaceSortedMap<Coordinate,V>
-
clear
public void clear()
- Specified by:
clear
in interfaceMap<Coordinate,V>
- Overrides:
clear
in classMapView<Coordinate,V>
-
getRowCount
public int getRowCount()
- Specified by:
getRowCount
in interfaceTableModel
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCount
in interfaceTableModel
-
getColumnName
public String getColumnName(int x)
- Specified by:
getColumnName
in interfaceTableModel
-
getColumnClass
public Class<? extends V> getColumnClass(int x)
- Specified by:
getColumnClass
in interfaceTableModel
-
isCellEditable
public boolean isCellEditable(int y, int x)
- Specified by:
isCellEditable
in interfaceTableModel
-
getValueAt
public V getValueAt(int y, int x)
- Specified by:
getValueAt
in interfaceTableModel
-
setValueAt
public void setValueAt(Object value, int y, int x)
- Specified by:
setValueAt
in interfaceTableModel
-
addTableModelListener
public void addTableModelListener(TableModelListener listener)
- Specified by:
addTableModelListener
in interfaceTableModel
-
removeTableModelListener
public void removeTableModelListener(TableModelListener listener)
- Specified by:
removeTableModelListener
in interfaceTableModel
-
getTableModelListeners
protected TableModelListener[] getTableModelListeners()
-
fireTableDataChanged
protected void fireTableDataChanged()
-
fireTableStructureChanged
protected void fireTableStructureChanged()
-
fireTableRowsInserted
protected void fireTableRowsInserted(int start, int end)
-
fireTableRowsUpdated
protected void fireTableRowsUpdated(int start, int end)
-
fireTableRowsDeleted
protected void fireTableRowsDeleted(int start, int end)
-
fireTableCellUpdated
protected void fireTableCellUpdated(int row, int column)
-
fireTableChanged
protected void fireTableChanged(TableModelEvent event)
-
-