Package ptolemy.math
Class Precision.PrecisionFormat
- java.lang.Object
-
- ptolemy.math.Precision.PrecisionFormat
-
- Direct Known Subclasses:
Precision.IntegerFractionPrecisionFormat,Precision.LengthExponentPrecisionFormat,Precision.LengthIntegerPrecisionFormat,Precision.VHDLPrecisionFormat
- Enclosing class:
- Precision
public abstract static class Precision.PrecisionFormat extends java.lang.ObjectDefines a String format for specifying a Precision object. This abstract class defines a method for parsing the string format and a method for creating a valid String representation of a Precision object. The printing and parsing methods should be consistent (i.e. the parsing method should successfully parse the result of the printing method).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCOMMA_OR_FORWARDSLASHRegular expression definition for a comma "," or a forward slash "/".static java.lang.StringOPTIONAL_L_PARANRegular expression definition for an optional left parenthesis.static java.lang.StringOPTIONAL_L_PARANBRACKETRegular expression definition for an optional left parenthesis or left bracket.static java.lang.StringOPTIONAL_R_PARANRegular expression definition for an optional right parenthesis.static java.lang.StringOPTIONAL_R_PARANBRACKETRegular expression definition for an optional right parenthesis or left bracket.static java.lang.StringOPTIONAL_U_OR_S_GROUPRegular expression for an optional 'S' or 'U' "group".static java.lang.StringOPTIONAL_WHITE_SPACERegular expression for optional white space.static java.lang.StringPERIODRegular expression definition for a Period ".".static java.lang.StringSIGNED_INTEGER_GROUPRegular expression for a grouped signed integer (positive or negative).static java.lang.StringUNSIGNED_INTEGER_GROUPRegular expression for a grouped unsigned integer.
-
Constructor Summary
Constructors Constructor Description PrecisionFormat()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static intparseInteger(java.lang.String str)Parse a String as an integer.static intparseSignString(java.lang.String str)Parse the 'U' or 'S' sign specifier.abstract PrecisionparseString(java.lang.String str)Parse the given String argument using the rules of the specific PrecisionFormat that is defined.abstract java.lang.StringprintPrecisionFormat(Precision p)Creates a valid String representation of the Precision object based on the rules of the given string format.
-
-
-
Field Detail
-
COMMA_OR_FORWARDSLASH
public static final java.lang.String COMMA_OR_FORWARDSLASH
Regular expression definition for a comma "," or a forward slash "/".- See Also:
- Constant Field Values
-
OPTIONAL_L_PARAN
public static final java.lang.String OPTIONAL_L_PARAN
Regular expression definition for an optional left parenthesis.- See Also:
- Constant Field Values
-
OPTIONAL_L_PARANBRACKET
public static final java.lang.String OPTIONAL_L_PARANBRACKET
Regular expression definition for an optional left parenthesis or left bracket.- See Also:
- Constant Field Values
-
OPTIONAL_R_PARAN
public static final java.lang.String OPTIONAL_R_PARAN
Regular expression definition for an optional right parenthesis.- See Also:
- Constant Field Values
-
OPTIONAL_R_PARANBRACKET
public static final java.lang.String OPTIONAL_R_PARANBRACKET
Regular expression definition for an optional right parenthesis or left bracket.- See Also:
- Constant Field Values
-
PERIOD
public static final java.lang.String PERIOD
Regular expression definition for a Period ".".- See Also:
- Constant Field Values
-
SIGNED_INTEGER_GROUP
public static final java.lang.String SIGNED_INTEGER_GROUP
Regular expression for a grouped signed integer (positive or negative).- See Also:
- Constant Field Values
-
OPTIONAL_U_OR_S_GROUP
public static final java.lang.String OPTIONAL_U_OR_S_GROUP
Regular expression for an optional 'S' or 'U' "group".- See Also:
- Constant Field Values
-
UNSIGNED_INTEGER_GROUP
public static final java.lang.String UNSIGNED_INTEGER_GROUP
Regular expression for a grouped unsigned integer.- See Also:
- Constant Field Values
-
OPTIONAL_WHITE_SPACE
public static final java.lang.String OPTIONAL_WHITE_SPACE
Regular expression for optional white space.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseString
public abstract Precision parseString(java.lang.String str) throws java.lang.IllegalArgumentException
Parse the given String argument using the rules of the specific PrecisionFormat that is defined. This method will return a valid Precision object from the String. If the String parsing does not produce a valid match, this method will return a null. If the String match is successful but there is a problem in the interpretation of the match, this method will throw a IllegalArgumentException.- Parameters:
str- String to parse- Returns:
- A Precision object. Returns a null if the String does not match the particular string format.
- Throws:
java.lang.IllegalArgumentException- If there is a problem parsing the String (i.e. an illegal string).
-
printPrecisionFormat
public abstract java.lang.String printPrecisionFormat(Precision p)
Creates a valid String representation of the Precision object based on the rules of the given string format. The format of this String should be consistent with the format used in the parseString method.- Parameters:
p- Precision object to represent as a String.- Returns:
- String representing the Precision object
-
parseInteger
public static int parseInteger(java.lang.String str) throws java.lang.IllegalArgumentExceptionParse a String as an integer. This method calls the Integer.parseInt method but throws the IllegalArgumentException instead of the NumberFormatException when there is a problem.- Parameters:
str- The integer string to parse- Returns:
- The integer value of the string.
- Throws:
java.lang.IllegalArgumentException- If the parsing of the Integer value fails (i.e. NumberFormatException).
-
parseSignString
public static int parseSignString(java.lang.String str) throws java.lang.IllegalArgumentExceptionParse the 'U' or 'S' sign specifier.- Parameters:
str- String to parse for a sign indicator.- Returns:
- Return a 0 for unsigned and a 1 for signed.
- Throws:
java.lang.IllegalArgumentException- If the string does not match the 'U' or 'S' characters.
-
-