Class MultiOccupancyCellAccessor<T>

  • All Implemented Interfaces:
    CellAccessor<T,​Map<GridPoint,​Object>>

    public class MultiOccupancyCellAccessor<T>
    extends Object
    implements CellAccessor<T,​Map<GridPoint,​Object>>
    Coordinate accessor where a location can hold multiple individual objects. This uses a list to store the objects in each cell.
    Author:
    Nick Collier
    • Constructor Detail

      • MultiOccupancyCellAccessor

        public MultiOccupancyCellAccessor()
    • Method Detail

      • get

        public T get​(Map<GridPoint,​Object> locationMap,
                     GridPoint location)
        Gets the item at the specified location in the map.
        Specified by:
        get in interface CellAccessor<T,​Map<GridPoint,​Object>>
        Parameters:
        locationMap - the location map to put the object in
        location - the location in the map
        Returns:
        the item at the specified location
      • getAll

        public Iterable<T> getAll​(Map<GridPoint,​Object> locationMap,
                                  GridPoint location)
        Gets all the items at the specified location in the map.
        Specified by:
        getAll in interface CellAccessor<T,​Map<GridPoint,​Object>>
        Parameters:
        locationMap - the location map to retrieve from
        location - the location in the map
        Returns:
        an iterator over all the items at the specified location
      • getRandom

        public T getRandom​(Map<GridPoint,​Object> locationMap,
                           GridPoint location)
        Gets a random item from those at the specified location in the map.
        Specified by:
        getRandom in interface CellAccessor<T,​Map<GridPoint,​Object>>
        Parameters:
        locationMap - the location map to retrieve from
        location - the location in the map
        Returns:
        a random item at the specified location
      • put

        public boolean put​(T obj,
                           Map<GridPoint,​Object> locationMap,
                           GridPoint location)
        Attempts to put the specified object at the specified location. Returns true if the put was successful. The semantics of the result will be determined by implementing classes.
        Specified by:
        put in interface CellAccessor<T,​Map<GridPoint,​Object>>
        Parameters:
        obj - the object to put at the location
        locationMap - the location map to put the object in
        location - the location in the map
        Returns:
        true if the put was successful, otherwise false.
      • remove

        public void remove​(T obj,
                           Map<GridPoint,​Object> locationMap,
                           GridPoint location)
        Removes the specified object from the location in the map.
        Specified by:
        remove in interface CellAccessor<T,​Map<GridPoint,​Object>>
        Parameters:
        obj - the object to remove
        locationMap - the location map to remove the object from
        location - the location in the map