Class AbstractOrderCompleter

  • All Implemented Interfaces:
    Completer
    Direct Known Subclasses:
    AtlantisOrderCompleter, EresseaOrderCompleter

    public abstract class AbstractOrderCompleter
    extends java.lang.Object
    implements Completer
    A class for offering possible completions on incomplete orders. This class relies on the OrderParser for reading input which calls the cmpltX methods of this class when it encounters an incomplete order and has a OrderCompleter object registered. A OrderCompleter wraps itself around a OrderParser so you do not get involved with any of the cmpltX methods. They are solely called by the internal OrderParser.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addCompletion​(Completion completion)
      Add a completion to the list of completions.
      void addDirection​(java.lang.String postfix, int dir)
      Adds a completion for the direction specified.
      void addDirections​(java.lang.String postfix)
      Adds completions for all directions.
      void addEnemyUnits​(java.lang.String postfix)
      adds all units in this region whose faction has a trustlevel not greater than zero (TL_DEFAULT)
      void addFactionItems​(int amount, java.lang.String postfix)
      Adds completions for all faction items of the current unit's faction.
      void addFactionItems​(java.lang.String postfix)
      Adds completions for all faction items of the current unit's faction.
      void addFactions​(java.lang.String postfix)
      Adds all known factions to the completions with comment
      void addFamilarSpells​(Unit mage, Unit familar, java.lang.String opening, java.lang.String closing)
      Adds completions for a familiar of the mage, enclosed in opening and closing quotes
      void addFilteredSpells​(Unit u, boolean far, boolean ocean, boolean combat, java.lang.String opening, java.lang.String closing)
      adds the given spells if combat, only adds combat-spells and so on
      void addItem​(ItemType iType, java.lang.String postfix)
      Adds an item by type
      void addNamed​(Named named, java.lang.String postfix, int offset, boolean addComment)
      Adds a thing to the completions, optionally with comments.
      void addNamed​(Named named, java.lang.String postfix, int prio, int offset, boolean addComment)
      Adds a thing to the completions, optionally with comments.
      void addNotAlliedUnits​(Alliance alliance, java.lang.String postfix)
      adds all units in this region, whose faction does not fit all of the alliances in the given Alliance-Object.
      void addOtherFactions​(java.lang.String postfix, int cursorOffset, boolean addComment)
      Adds all factions except the current unit's.
      void addRegionBuildingOwners​(java.lang.String postfix)
      Adds completion for all building owners in the current region.
      void addRegionBuildingOwners​(java.lang.String postfix, int cursorOffset)
      Adds completion for all building owners in the current region.
      void addRegionBuildings​(java.lang.String prefix, java.lang.String postfix, Building exclude, boolean comment)
      Add all the buildings in the current region except exclude (which may be null).
      void addRegionItemsFaction​(java.lang.String postfix, int minAmount)
      Adds all items of which the units of the current faction in the region have at least minAmount.
      void addRegionShipCommanders​(java.lang.String postfix)
      Adds completions for all owners of ships in the region.
      void addRegionShipCommanders​(java.lang.String postfix, int cursorOffset)
      Adds completions for all owners of ships in the region.
      void addRegionShips​(java.lang.String prefix, java.lang.String postfix, Ship exclude, boolean comment)
      Add all the ships in the current region except exclude (which may be null).
      void addRegionUnits​(java.lang.String postfix, boolean omitTemp)
      Adds all units in the region to the completions.
      void addRegionUnits​(java.lang.String postfix, int cursorOffset, boolean omitTemp)
      Adds all units in the region to the completions.
      void addShiptypes()
      Adds completions for all ship types in the rules.
      protected void addSkills()  
      void addSurroundingRegions​(int radius, java.lang.String postfix)
      Adds completions for all regions surrounding the current region, completing to the appropriate direction.
      void addUnit​(Unit u, java.lang.String postfix)
      Adds a unit to the completion in a standard manner without comment.
      void addUnit​(Unit u, java.lang.String postfix, int cursorOffset)
      Adds a unit to the completion in a standard manner without comment.
      void addUnit​(Unit u, java.lang.String postfix, int cursorOffset, boolean omitTemp)
      Adds a unit to the completions in a standard manner without comments.
      void addUnitContainerOwner​(UnitContainer uc, Unit u, java.lang.String postfix, int cursorOffset)
      Adds completions for the owner u of UnitContainer c.
      void addUnitItems​(int amount, java.lang.String postfix, StringID... exclude)
      Adds completions for all items of the unit, excluding item types in exclude.
      void addUnitItems​(java.lang.String postfix, StringID... exclude)
      Adds completions for all items of the unit, excluding item types in exclude.
      void addUnitLuxuries​(java.lang.String postfix)
      Adds completions for all the unit's luxury items.
      protected boolean checkForMaterial​(Item ingredient, int amount)  
      protected boolean checkForMaterials​(java.util.Iterator<Item> iter)
      Check for the necessary materials to produce an item considering all privileged factions in the current region
      protected boolean checkForMaterials​(java.util.Iterator<Item> iter, int amount)
      Check for the necessary materials to produce an item considering all privileged factions in the current region
      void clear()
      Deletes all completions.
      protected void cmplt()
      Called to produce the basic completions when token has been read.
      void cmpltDescription()
      Add completions for command Description.
      void cmpltFactions​(java.lang.String postfix)
      Add completions for command Factions.
      java.util.List<Completion> crop​(java.util.List<Completion> list, java.util.List<OrderToken> tokens)
      Filters all Completion objects from list, that do not match the last word in txt, usually the order entered so far.
      protected java.lang.String fixQuotes​(OrderTokenizer innerTokenizer, OrderToken openingToken, OrderToken contentToken, OrderToken closingToken, boolean preferQuotes, boolean forceQuotes, boolean doClose, char preferredQuote)
      TODO DOCUMENT-ME
      void fixQuotes​(OrderToken openingToken, OrderToken contentToken, OrderToken closingToken, boolean preferQuotes, boolean forceQuotes, boolean doClose, char preferredQuote)
      TODO DOCUMENT-ME
      protected void fixWhitespace()
      Replaces " " by "~" in all completions.
      protected CompleterSettingsProvider getCompleterSettingsProvider()
      Returns the value of completerSettingsProvider.
      java.util.List<Completion> getCompletions()
      Returns the value of completions.
      java.util.List<Completion> getCompletions​(Unit u, java.lang.String cmd)
      Parses the String cmd with Unit u as context and returns possible completions if the cmd is an incomplete order.
      java.util.List<Completion> getCompletions​(Unit u, java.lang.String line, java.util.List<Completion> old)
      GameData getData()
      Returns the value of data.
      protected GameSpecificStuff getGameSpecificStuff()  
      protected java.util.Locale getLocale()  
      protected java.lang.String getOrderTranslation​(SkillType skill)  
      protected java.lang.String getOrderTranslation​(StringID orderKey)  
      OrderParser getParser()  
      java.util.List<OrderToken> getParserTokens()
      If this completer has an OrderParser and it has been used to find completions, this method returns the tokens read by the parser.
      Region getRegion()
      Returns the value of region.
      protected java.lang.String getRuleItemTranslation​(java.lang.String orderKey)  
      protected int getSkillCost​(SkillType skillType, Unit aUnit)  
      static java.lang.String getStub​(java.lang.String txt)
      Returns the last word immediately at the end of the String txt.
      static java.lang.String getStub​(java.util.List<OrderToken> tokens)
      Returns the last word in the list of tokens.
      protected abstract java.lang.String getTemp()
      Returns the localized temp unit token.
      protected java.lang.String getTranslation​(java.lang.String key)  
      Unit getUnit()
      Returns the value of unit.
      protected boolean hasSkill​(Unit u, StringID id)
      Determines whether the specified unit has a skill.
      protected boolean hasSkill​(Unit u, StringID id, int level)
      Determines whether the specified unit has a skill at a minimum level.
      protected boolean hasSkills​(Unit u, int level)
      Determines whether the unit has any skill of at least the given level Used i.e. for determining if someone can teach
      void setData​(GameData data)  
      void setParser​(OrderParser parser)  
      protected void setQuote​(char quote)  
      • Methods inherited from class java.lang.Object

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

      • completions

        protected java.util.List<Completion> completions
      • region

        protected Region region
      • unit

        protected Unit unit
      • oneQuote

        protected java.lang.String oneQuote
      • twoQuotes

        protected java.lang.String twoQuotes
      • spaceQuotes

        protected java.lang.String spaceQuotes
    • Constructor Detail

      • AbstractOrderCompleter

        public AbstractOrderCompleter​(GameData gd,
                                      CompleterSettingsProvider ac)
        Creates a new EresseaOrderCompleter taking context information from the specified GameData object.
        Parameters:
        gd - The GameData this completer uses as context.
    • Method Detail

      • getCompleterSettingsProvider

        protected CompleterSettingsProvider getCompleterSettingsProvider()
        Returns the value of completerSettingsProvider.
        Returns:
        Returns completerSettingsProvider.
      • getCompletions

        public java.util.List<Completion> getCompletions​(Unit u,
                                                         java.lang.String cmd)
        Parses the String cmd with Unit u as context and returns possible completions if the cmd is an incomplete order.
        Parameters:
        u - a Unit object taken as context information for the completion decisions.
        cmd - a String containing the (possibly incomplete) order to parse.
        Returns:
        a List with possible completions of the given order. If there are no proposed completions this list is empty.
      • setParser

        public void setParser​(OrderParser parser)
      • setQuote

        protected void setQuote​(char quote)
      • crop

        public java.util.List<Completion> crop​(java.util.List<Completion> list,
                                               java.util.List<OrderToken> tokens)
        Filters all Completion objects from list, that do not match the last word in txt, usually the order entered so far.
      • addCompletion

        public void addCompletion​(Completion completion)
        Add a completion to the list of completions.
      • clear

        public void clear()
        Deletes all completions.
      • addFilteredSpells

        public void addFilteredSpells​(Unit u,
                                      boolean far,
                                      boolean ocean,
                                      boolean combat,
                                      java.lang.String opening,
                                      java.lang.String closing)
        adds the given spells if combat, only adds combat-spells and so on
        Parameters:
        closing -
        opening -
      • addFamilarSpells

        public void addFamilarSpells​(Unit mage,
                                     Unit familar,
                                     java.lang.String opening,
                                     java.lang.String closing)
        Adds completions for a familiar of the mage, enclosed in opening and closing quotes
      • cmpltFactions

        public void cmpltFactions​(java.lang.String postfix)
        Add completions for command Factions.
      • addEnemyUnits

        public void addEnemyUnits​(java.lang.String postfix)
        adds all units in this region whose faction has a trustlevel not greater than zero (TL_DEFAULT)
      • addNotAlliedUnits

        public void addNotAlliedUnits​(Alliance alliance,
                                      java.lang.String postfix)
        adds all units in this region, whose faction does not fit all of the alliances in the given Alliance-Object. Example: Given Alliance contains help and give: units are added if they are not allied both: help AND give. The reference-object is the faction of the current unit
      • addRegionUnits

        public void addRegionUnits​(java.lang.String postfix,
                                   boolean omitTemp)
        Adds all units in the region to the completions.
      • addRegionUnits

        public void addRegionUnits​(java.lang.String postfix,
                                   int cursorOffset,
                                   boolean omitTemp)
        Adds all units in the region to the completions.
      • addRegionShips

        public void addRegionShips​(java.lang.String prefix,
                                   java.lang.String postfix,
                                   Ship exclude,
                                   boolean comment)
        Add all the ships in the current region except exclude (which may be null). Prefix them with prefix.
      • addRegionBuildings

        public void addRegionBuildings​(java.lang.String prefix,
                                       java.lang.String postfix,
                                       Building exclude,
                                       boolean comment)
        Add all the buildings in the current region except exclude (which may be null). Prefix them with prefix.
        Parameters:
        postfix -
      • addRegionItemsFaction

        public void addRegionItemsFaction​(java.lang.String postfix,
                                          int minAmount)
        Adds all items of which the units of the current faction in the region have at least minAmount.
      • addRegionShipCommanders

        public void addRegionShipCommanders​(java.lang.String postfix)
        Adds completions for all owners of ships in the region.
      • addRegionShipCommanders

        public void addRegionShipCommanders​(java.lang.String postfix,
                                            int cursorOffset)
        Adds completions for all owners of ships in the region.
      • addUnitContainerOwner

        public void addUnitContainerOwner​(UnitContainer uc,
                                          Unit u,
                                          java.lang.String postfix,
                                          int cursorOffset)
        Adds completions for the owner u of UnitContainer c.
      • addRegionBuildingOwners

        public void addRegionBuildingOwners​(java.lang.String postfix)
        Adds completion for all building owners in the current region.
      • addRegionBuildingOwners

        public void addRegionBuildingOwners​(java.lang.String postfix,
                                            int cursorOffset)
        Adds completion for all building owners in the current region.
      • addUnitItems

        public void addUnitItems​(java.lang.String postfix,
                                 StringID... exclude)
        Adds completions for all items of the unit, excluding item types in exclude.
      • addUnitItems

        public void addUnitItems​(int amount,
                                 java.lang.String postfix,
                                 StringID... exclude)
        Adds completions for all items of the unit, excluding item types in exclude.
      • addFactionItems

        public void addFactionItems​(java.lang.String postfix)
        Adds completions for all faction items of the current unit's faction.
      • addFactionItems

        public void addFactionItems​(int amount,
                                    java.lang.String postfix)
        Adds completions for all faction items of the current unit's faction.
      • addFactions

        public void addFactions​(java.lang.String postfix)
        Adds all known factions to the completions with comment
        Parameters:
        postfix -
      • addOtherFactions

        public void addOtherFactions​(java.lang.String postfix,
                                     int cursorOffset,
                                     boolean addComment)
        Adds all factions except the current unit's.
        Parameters:
        postfix - appended to Completion
        cursorOffset - used for Completion
        addComment - if true, the faction name is appended as a comment. Does not mix well with cursorOffset!=0.
      • addSurroundingRegions

        public void addSurroundingRegions​(int radius,
                                          java.lang.String postfix)
        Adds completions for all regions surrounding the current region, completing to the appropriate direction.
      • addDirections

        public void addDirections​(java.lang.String postfix)
        Adds completions for all directions.
      • addDirection

        public void addDirection​(java.lang.String postfix,
                                 int dir)
        Adds a completion for the direction specified.
        Parameters:
        dir - This corresponds to the index of the direction in the Direction enum.
      • addUnitLuxuries

        public void addUnitLuxuries​(java.lang.String postfix)
        Adds completions for all the unit's luxury items.
      • addSkills

        protected void addSkills()
      • getSkillCost

        protected int getSkillCost​(SkillType skillType,
                                   Unit aUnit)
      • addUnit

        public void addUnit​(Unit u,
                            java.lang.String postfix)
        Adds a unit to the completion in a standard manner without comment.
      • addUnit

        public void addUnit​(Unit u,
                            java.lang.String postfix,
                            int cursorOffset)
        Adds a unit to the completion in a standard manner without comment.
      • addUnit

        public void addUnit​(Unit u,
                            java.lang.String postfix,
                            int cursorOffset,
                            boolean omitTemp)
        Adds a unit to the completions in a standard manner without comments.
      • getTemp

        protected abstract java.lang.String getTemp()
        Returns the localized temp unit token.
      • addNamed

        public void addNamed​(Named named,
                             java.lang.String postfix,
                             int offset,
                             boolean addComment)
        Adds a thing to the completions, optionally with comments.
        Parameters:
        named - This object's name and ID are displayed
        postfix - Completion postfix
        offset - Completion offset (probably doesn't make sense with comment)
        addComment - If this is true, the name is inserted as a comment after the id
      • addNamed

        public void addNamed​(Named named,
                             java.lang.String postfix,
                             int prio,
                             int offset,
                             boolean addComment)
        Adds a thing to the completions, optionally with comments.
        Parameters:
        named - This object's name and ID are displayed
        postfix - Completion postfix
        prio - This prio and prio-1 are used
        offset - Completion offset (probably doesn't make sense with comment)
        addComment - If this is true, the name is inserted as a comment after the id
      • checkForMaterials

        protected boolean checkForMaterials​(java.util.Iterator<Item> iter)
        Check for the necessary materials to produce an item considering all privileged factions in the current region
        Parameters:
        iter - An Iterator over the necessary materials (Items)
        Returns:
        true, if the necessary materials are available, false otherwise
      • checkForMaterials

        protected boolean checkForMaterials​(java.util.Iterator<Item> iter,
                                            int amount)
        Check for the necessary materials to produce an item considering all privileged factions in the current region
        Parameters:
        iter - An Iterator over the necessary materials (Items)
        amount - A multiplicator
        Returns:
        true, if the necessary materials are available, false otherwise
      • checkForMaterial

        protected boolean checkForMaterial​(Item ingredient,
                                           int amount)
      • getStub

        public static java.lang.String getStub​(java.util.List<OrderToken> tokens)
        Returns the last word in the list of tokens.
      • getStub

        public static java.lang.String getStub​(java.lang.String txt)
        Returns the last word immediately at the end of the String txt. It is preferable to use getStub(List).
        FIXME (stm) this is identical to magellan.client.completion.AutoCompletion.getStub(String) but we don't want to reference src-client here...
      • hasSkills

        protected boolean hasSkills​(Unit u,
                                    int level)
        Determines whether the unit has any skill of at least the given level Used i.e. for determining if someone can teach
      • hasSkill

        protected boolean hasSkill​(Unit u,
                                   StringID id)
        Determines whether the specified unit has a skill.
      • hasSkill

        protected boolean hasSkill​(Unit u,
                                   StringID id,
                                   int level)
        Determines whether the specified unit has a skill at a minimum level. Returns also true, if the specified skill is unknown. FF: changed to reflect modified skill
      • addItem

        public void addItem​(ItemType iType,
                            java.lang.String postfix)
        Adds an item by type
      • addShiptypes

        public void addShiptypes()
        Adds completions for all ship types in the rules.
      • getData

        public GameData getData()
        Returns the value of data.
        Returns:
        Returns data.
      • setData

        public void setData​(GameData data)
      • getLocale

        protected java.util.Locale getLocale()
      • getOrderTranslation

        protected java.lang.String getOrderTranslation​(StringID orderKey)
      • getOrderTranslation

        protected java.lang.String getOrderTranslation​(SkillType skill)
      • getRuleItemTranslation

        protected java.lang.String getRuleItemTranslation​(java.lang.String orderKey)
      • getTranslation

        protected java.lang.String getTranslation​(java.lang.String key)
      • getCompletions

        public java.util.List<Completion> getCompletions()
        Returns the value of completions.
        Returns:
        Returns completions.
      • getRegion

        public Region getRegion()
        Returns the value of region.
        Returns:
        Returns region.
      • getUnit

        public Unit getUnit()
        Returns the value of unit.
        Returns:
        Returns unit.
      • getParserTokens

        public java.util.List<OrderToken> getParserTokens()
        Description copied from interface: Completer
        If this completer has an OrderParser and it has been used to find completions, this method returns the tokens read by the parser.
        Specified by:
        getParserTokens in interface Completer
        Returns:
        The list of tokens of this Completer's OrderParser, or null.
      • cmplt

        protected void cmplt()
        Called to produce the basic completions when token has been read. Adds completions for user-defined commands.
      • cmpltDescription

        public void cmpltDescription()
        Add completions for command Description.
      • fixWhitespace

        protected void fixWhitespace()
        Replaces " " by "~" in all completions.
      • fixQuotes

        public void fixQuotes​(OrderToken openingToken,
                              OrderToken contentToken,
                              OrderToken closingToken,
                              boolean preferQuotes,
                              boolean forceQuotes,
                              boolean doClose,
                              char preferredQuote)
        TODO DOCUMENT-ME
        Parameters:
        openingToken -
        contentToken -
        closingToken -
        preferQuotes -
        forceQuotes -
        doClose -
        preferredQuote -
      • fixQuotes

        protected java.lang.String fixQuotes​(OrderTokenizer innerTokenizer,
                                             OrderToken openingToken,
                                             OrderToken contentToken,
                                             OrderToken closingToken,
                                             boolean preferQuotes,
                                             boolean forceQuotes,
                                             boolean doClose,
                                             char preferredQuote)
        TODO DOCUMENT-ME
        Parameters:
        innerTokenizer -
        openingToken -
        contentToken -
        closingToken -
        preferQuotes -
        forceQuotes -
        doClose -
        preferredQuote -