Class NumberPiece

java.lang.Object

public class NumberPiece
extends ExpressionPiece
Reads until it is no longer able to parse a number.
  • Constructor Summary

    Constructors
    Constructor Description
    NumberPiece​(FilePointer ptr)
    Construct a number piece at a position.
  • Method Summary

    Modifier and Type Method Description
    double number()
    Get parsed number value.
    PieceResult read​(char c, FilePointer ptr)
    Parse a character by this piece.
    static boolean tryBoolean​(java.lang.String s)
    Try to parse string as a number and compare to 0 or compare it to string of value "true".
    static java.lang.Double tryNumber​(java.lang.String s)
    Try to decode a double-type number.

    Methods inherited from class net.diversionmc.parser.expression.ExpressionPiece

    replace

    Methods inherited from class net.diversionmc.parser.util.Pointable

    pointer

    Methods inherited from class java.lang.Object

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

    • NumberPiece

      public NumberPiece​(FilePointer ptr)
      Construct a number piece at a position.
      Parameters:
      ptr - Creation position.
  • Method Details

    • read

      public PieceResult read​(char c, FilePointer ptr)
      Description copied from class: ExpressionPiece
      Parse a character by this piece.
      Specified by:
      read in class ExpressionPiece
      Parameters:
      c - Character to parse.
      ptr - Character position in file.
      Returns:
      PieceResult
    • number

      public double number()
      Get parsed number value.
      Returns:
      Number Piece value.
    • tryNumber

      public static java.lang.Double tryNumber​(java.lang.String s)
      Try to decode a double-type number. Accepts hex inputs, etc.
      Parameters:
      s - String to parse.
      Returns:
      Parsed double or null if the string is not a number.
      See Also:
      Long.decode(String), Double.parseDouble(String)
    • tryBoolean

      public static boolean tryBoolean​(java.lang.String s)
      Try to parse string as a number and compare to 0 or compare it to string of value "true".
      Parameters:
      s - String to parse.
      Returns:
      Parsed boolean. If input is a number, then 0 = false, other = true, else true if string is equal to "true" (case-insensitive).
      See Also:
      tryNumber(String)