Class ControllerMap<C extends Controller,​N extends javafx.scene.Node>

  • Type Parameters:
    C - The Controller type for ever node in this list.
    N - The type of the Node being mapped to a Controller.
    All Implemented Interfaces:
    java.util.Map<C,​N>

    public final class ControllerMap<C extends Controller,​N extends javafx.scene.Node>
    extends java.lang.Object
    implements java.util.Map<C,​N>
    Keeps track of the Nodes in an observable list and provides mapping from a Node to its respective Controller. This makes it easy to keep track of what controller is mapped to what node without having to use a secondary backing list with index comparisons. This utility also provides helpful functionality like sorting the nodes in the list using a comparator.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      ControllerMap​(javafx.collections.ObservableList<N> nodesList)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int index, C controller)
      Adds the Node from this controller to the specified index in the observable list.
      boolean add​(C controller)
      Adds a controller to the map.
      boolean addAll​(int index, java.util.Collection<C> controllers)
      Adds all of the Nodes from this collection of controllers to the observable list at the specified index in the Observable List.
      boolean addAll​(C... controllers)
      Adds multiple controllers to the map at once.
      boolean addAll​(java.util.Collection<C> controllers)
      Adds multiple controllers to the map at once.
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<C,​N>> entrySet()  
      N get​(java.lang.Object key)  
      C getWithNode​(N node)
      Gets the Controller that maps to a specific Node.
      boolean isEmpty()  
      java.util.Set<C> keySet()  
      void moveByDistance​(C controller, int distance)
      Moves the Node that is owned by this controller the specified distance.
      N put​(C key, N value)  
      void putAll​(java.util.Map<? extends C,​? extends N> m)  
      N remove​(java.lang.Object key)  
      N removeWithController​(C controller)
      Remove the Controller and the controllers Node.
      boolean removeWithNode​(N node)
      Remove the Node and the nodes Controller.
      int size()  
      void sort​(java.util.Comparator<? super C> c)
      Allows sorting of the nodes using their respective controllers
      java.util.Collection<N> values()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • ControllerMap

        public ControllerMap​(javafx.collections.ObservableList<N> nodesList)
        Parameters:
        nodesList - The list that that will be managed.
    • Method Detail

      • removeWithController

        public N removeWithController​(C controller)
        Remove the Controller and the controllers Node.
        Parameters:
        controller - The controller to remove
        Returns:
        The Node that was removed from the list
      • removeWithNode

        public boolean removeWithNode​(N node)
        Remove the Node and the nodes Controller.
        Parameters:
        node - The Node to remove
        Returns:
        true if successfully removed.
      • add

        public boolean add​(int index,
                           C controller)
        Adds the Node from this controller to the specified index in the observable list.
        Parameters:
        index - The index to place the Node
        controller - The controller to get the node from
        Returns:
        true if the observable list changed as a result of the call
        See Also:
        List.add(int, Object)
      • add

        public boolean add​(C controller)
        Adds a controller to the map.
        See Also:
        List.add(Object)
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<C> controllers)
        Adds all of the Nodes from this collection of controllers to the observable list at the specified index in the Observable List.
        Parameters:
        index - The index to place the nodes
        controllers - The controllers to get the nodes from
        Returns:
        true if the observable list changed as a result of the call
        See Also:
        List.addAll(int, Collection)
      • addAll

        public boolean addAll​(java.util.Collection<C> controllers)
        Adds multiple controllers to the map at once.
        See Also:
        List.addAll(Collection)
      • addAll

        public boolean addAll​(C... controllers)
        Adds multiple controllers to the map at once.
        See Also:
        List.addAll(Collection)
      • getWithNode

        public C getWithNode​(N node)
        Gets the Controller that maps to a specific Node.
        Parameters:
        node - The node to do the lookup with.
        Returns:
        The Controller that controls this node
      • moveByDistance

        public void moveByDistance​(C controller,
                                   int distance)
        Moves the Node that is owned by this controller the specified distance.
        Parameters:
        controller - The controller to use as a lookup key for the move
        distance - The distance to move the node. 0 means no movement.
      • put

        public N put​(C key,
                     N value)
        Specified by:
        put in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • get

        public N get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • remove

        public N remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • putAll

        public void putAll​(java.util.Map<? extends C,​? extends N> m)
        Specified by:
        putAll in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • keySet

        public java.util.Set<C> keySet()
        Specified by:
        keySet in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
        Returns:
        An unmodifiable set of of keys for this map.
      • values

        public java.util.Collection<N> values()
        Specified by:
        values in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
        Returns:
        An unmodifiable set of of values for this map.
      • entrySet

        public java.util.Set<java.util.Map.Entry<C,​N>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<C extends Controller,​N extends javafx.scene.Node>
      • sort

        public void sort​(java.util.Comparator<? super C> c)
        Allows sorting of the nodes using their respective controllers
        Parameters:
        c - Controller comparator to use.