Class EnumParser<E extends Enum<E>>

All Implemented Interfaces:
Converter<String,E>

public class EnumParser<E extends Enum<E>> extends PatternedParser<E> implements Converter<String,E>
A Parser used for parsing and handling values representing an Enum
  • Constructor Details

    • EnumParser

      public EnumParser(Class<E> enumClass, String languageNode)
      Parameters:
      enumClass - The Enum Class to be accessed.
      languageNode - The String representing the languageNode for the Enum
  • Method Details

    • parse

      @Nullable public E parse(String string, ParseContext context)
      Description copied from class: Parser
      Parses the input. This method may print an error prior to returning null if the input couldn't be parsed.

      Remember to override Parser.canParse(ParseContext) if this parser doesn't parse at all (i.e. you only use it's toString methods) or only parses for certain contexts.

      Note that this method will be called very frequently during script parsing, so try to avoid computationally expensive operations in this method when possible.

      Overrides:
      parse in class Parser<E extends Enum<E>>
      Parameters:
      string - The String to parse. This string is already trim()med.
      context - Context of parsing, may not be null
      Returns:
      The parsed input or null if the input is invalid for this parser.
    • convert

      @Nullable public E convert(String string)
      Description copied from interface: Converter
      Converts an object using this Converter.
      Specified by:
      convert in interface Converter<String,E extends Enum<E>>
      Parameters:
      string - The object to convert.
      Returns:
      The converted object.
    • toVariableNameString

      public String toVariableNameString(E object)
      Description copied from class: Parser
      Returns an object's string representation in a variable name.
      Specified by:
      toVariableNameString in class Parser<E extends Enum<E>>
      Parameters:
      object -
      Returns:
      The given object's representation in a variable name.
    • getPatterns

      public String[] getPatterns()
      Description copied from class: PatternedParser
      Get all literal patterns.
      Specified by:
      getPatterns in class PatternedParser<E extends Enum<E>>
    • toString

      public String toString(E object, int flags)
      Description copied from class: Parser
      Returns a string representation of the given object to be used in messages.
      Specified by:
      toString in class Parser<E extends Enum<E>>
      Parameters:
      object - The object. This will never be null.
      Returns:
      The String representation of the object.
      See Also: