Class NumberPiece
java.lang.Object
net.diversionmc.parser.util.Pointable
net.diversionmc.parser.expression.ExpressionPiece
net.diversionmc.parser.expression.NumberPiece
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 doublenumber()Get parsed number value.PieceResultread(char c, FilePointer ptr)Parse a character by this piece.static booleantryBoolean(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.DoubletryNumber(java.lang.String s)Try to decode a double-type number.Methods inherited from class net.diversionmc.parser.expression.ExpressionPiece
replaceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
NumberPiece
Construct a number piece at a position.- Parameters:
ptr- Creation position.
-
-
Method Details
-
read
Description copied from class:ExpressionPieceParse a character by this piece.- Specified by:
readin classExpressionPiece- 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)
-