Package com.cognite.client.util
Class ParseValue
java.lang.Object
com.cognite.client.util.ParseValue
This class hosts methods for parsing
Value objects to various target types (String, double, etc.).
This can be helpful in particular when working with CDF.Raw and Json (parsed to Struct).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanparseBoolean(com.google.protobuf.Value rawValue) Tries to parse aValueto aBoolean.static doubleparseDouble(com.google.protobuf.Value rawValue) Tries to parse aValueto adouble.static longparseLong(com.google.protobuf.Value rawValue) Tries to parse aValueto along.static StringparseString(com.google.protobuf.Value rawValue) Tries to parse aValueto aStringrepresentation.
-
Constructor Details
-
ParseValue
public ParseValue()
-
-
Method Details
-
parseString
Tries to parse aValueto aStringrepresentation.- Parameters:
rawValue- the value to parse- Returns:
- the string representation
-
parseDouble
Tries to parse aValueto adouble. If the Value has a numeric or string representation the parsing will succeed as long as theValueis within the Double range. Will throw aNumberFormatExceptionif parsing is unsuccessful.- Parameters:
rawValue- the value to parse- Returns:
- the double representation
- Throws:
NumberFormatException
-
parseLong
Tries to parse aValueto along. If the Value has a numeric or string representation the parsing will succeed as long as theValueis within the long range. Will throw aNumberFormatExceptionif parsing is unsuccessful.- Parameters:
rawValue- the value to parse- Returns:
- the long representation
- Throws:
NumberFormatException
-
parseBoolean
Tries to parse aValueto aBoolean. If the Value has a boolean, numeric or string representation the parsing will succeed. A boolValuerepresentation is parsed directly. A StringValuerepresentation returns true if the string argument is not null and equal to, ignoring case, the string "true". A numericValuerepresentation returns true if the number equals "1". Will throw anExceptionif parsing is unsuccessful.- Parameters:
rawValue- the value to parse- Returns:
- the boolean representation
- Throws:
Exception
-