Class Units


  • public class Units
    extends java.lang.Object
    A class providing various utility functions regarding units.
    • Constructor Summary

      Constructors 
      Constructor Description
      Units​(Rules rules)
      Creates a new Units object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Collection<javax.swing.tree.TreeNode> addCategorizedUnitItems​(java.util.Collection<Unit> units, javax.swing.tree.DefaultMutableTreeNode parentNode, java.util.Comparator<Units.StatItem> itemComparator, java.util.Comparator<Unit> unitComparator, boolean showUnits, NodeWrapperFactory factory, ContextFactory reserveContextFactory)
      This method takes all items carried by units in the units Collection and sorts them by their category.
      java.util.Collection<javax.swing.tree.TreeNode> addCategorizedUnitItems​(java.util.Collection<Unit> units, javax.swing.tree.DefaultMutableTreeNode parentNode, java.util.Comparator<Units.StatItem> itemComparator, java.util.Comparator<Unit> unitComparator, boolean showUnits, NodeWrapperFactory factory, ContextFactory reserveContextFactory, boolean createCategoryNodes)
      This method takes all items carried by units in the units Collection and sorts them by their category.
      int addItemNode​(ItemType item, javax.swing.tree.DefaultMutableTreeNode categoryNode, Unit u, java.util.Collection<Unit> units, java.util.Comparator<Unit> unitComparator, boolean showUnits, NodeWrapperFactory factory, ContextFactory reserveContextFactory)  
      static void addOrders​(Unit u, java.lang.String[] s)
      Modifies u's orders as specified in s.
      static void addOrders​(Unit u, java.lang.String[] s, boolean refreshRelations)
      Modifies u's orders as specified in s.
      java.util.Collection<magellan.client.utils.Units.StatItemContainer> categorizeUnitItems​(java.util.Collection<Unit> units)
      Calculates the amounts of all items of all units and records the amount in the itemCategoriesMap.
      static void removeOrders​(Unit u, java.lang.String[] s)
      Modifies u's orders as specified in s.
      void setRules​(Rules rules)
      Changes the game rules.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Units

        public Units​(Rules rules)
        Creates a new Units object.
    • Method Detail

      • setRules

        public void setRules​(Rules rules)
        Changes the game rules.
      • categorizeUnitItems

        public java.util.Collection<magellan.client.utils.Units.StatItemContainer> categorizeUnitItems​(java.util.Collection<Unit> units)
        Calculates the amounts of all items of all units and records the amount in the itemCategoriesMap.
        Parameters:
        units - All items of all units in this Collection are accounted for.
        Returns:
        The sorted list of categories.
      • addCategorizedUnitItems

        public java.util.Collection<javax.swing.tree.TreeNode> addCategorizedUnitItems​(java.util.Collection<Unit> units,
                                                                                       javax.swing.tree.DefaultMutableTreeNode parentNode,
                                                                                       java.util.Comparator<Units.StatItem> itemComparator,
                                                                                       java.util.Comparator<Unit> unitComparator,
                                                                                       boolean showUnits,
                                                                                       NodeWrapperFactory factory,
                                                                                       ContextFactory reserveContextFactory)
        This method takes all items carried by units in the units Collection and sorts them by their category. Then it adds the non-empty categories to the specified parent node and puts the corresponding items in each category node. Optionally, the units carrying an item are listed as child nodes of the respective item nodes.
        Parameters:
        units - a collection of Unit objects carrying items.
        parentNode - a tree node to add the new nodes to.
        itemComparator - a comparator to sort the items with. If itemComparator is null the items are sorted by name.
        unitComparator - a comparator to sort the units with. If unitComparator is null the units are sorted by the amount of the item carried underneath which they appear.
        showUnits - if true each item node gets child nodes containing the unit(s) carrying that item.
        Returns:
        a collection of DefaultMutableTreeNode objects with user objects of class ItemCategory or null if the categorization of the items failed.
      • addCategorizedUnitItems

        public java.util.Collection<javax.swing.tree.TreeNode> addCategorizedUnitItems​(java.util.Collection<Unit> units,
                                                                                       javax.swing.tree.DefaultMutableTreeNode parentNode,
                                                                                       java.util.Comparator<Units.StatItem> itemComparator,
                                                                                       java.util.Comparator<Unit> unitComparator,
                                                                                       boolean showUnits,
                                                                                       NodeWrapperFactory factory,
                                                                                       ContextFactory reserveContextFactory,
                                                                                       boolean createCategoryNodes)
        This method takes all items carried by units in the units Collection and sorts them by their category. Then it adds the non-empty categories to the specified parent node and puts the corresponding items in each category node. Optionally, the units carrying an item are listed as child nodes of the respective item nodes.
        Parameters:
        units - a collection of Unit objects carrying items.
        parentNode - a tree node to add the new nodes to.
        itemComparator - a comparator to sort the items with. If itemComparator is null the items are sorted by name.
        unitComparator - a comparator to sort the units with. If unitComparator is null the units are sorted by the amount of the item carried underneath which they appear.
        showUnits - if true each item node gets child nodes containing the unit(s) carrying that item.
        Returns:
        a collection of DefaultMutableTreeNode objects with user objects of class ItemCategory or null if the categorization of the items failed.
      • addItemNode

        public int addItemNode​(ItemType item,
                               javax.swing.tree.DefaultMutableTreeNode categoryNode,
                               Unit u,
                               java.util.Collection<Unit> units,
                               java.util.Comparator<Unit> unitComparator,
                               boolean showUnits,
                               NodeWrapperFactory factory,
                               ContextFactory reserveContextFactory)
      • addOrders

        public static void addOrders​(Unit u,
                                     java.lang.String[] s)
        Modifies u's orders as specified in s.
        Parameters:
        s - A string array with the following values:
        [0] : The order that was given
        [1] : A String representative of the boolean value for "Replace orders"
        [2] : A String representative of the boolean value for "Keep comments"
        [3] : One of GiveOrderDialog.FIRST_POS, GiveOrderDialog.LAST_POS
        See Also:
        GiveOrderDialog.showGiveOrderDialog()
      • addOrders

        public static void addOrders​(Unit u,
                                     java.lang.String[] s,
                                     boolean refreshRelations)
        Modifies u's orders as specified in s.
        Parameters:
        s - A string array with the following values:
        [0] : The order that was given
        [1] : A String representative of the boolean value for "Replace orders"
        [2] : A String representative of the boolean value for "Keep comments"
        [3] : One of GiveOrderDialog.FIRST_POS, GiveOrderDialog.LAST_POS
        See Also:
        GiveOrderDialog.showGiveOrderDialog()