?
=?ISO-8859-1?Q?Jan_Thom=E4?=
Hi,
i am trying to write some kind of registry that internally stores values
as strings. I wanted to provide some convenience methods which allow to
retrieve property values as int or float.
<code>
/**
* @see #getPropertyAsString(String)
*/
public double getPropertyAsDouble(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public float getPropertyAsFloat(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public int getPropertyAsInt(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public long getPropertyAsLong(String xPathToProperty);
/**
* Convenience method to read a property as a string.
*
* @param xPathToProperty the xpath to the property.
*
* @return the property value as a string, null if no such property
can be found.
*/
public String getPropertyAsString(String xPathToProperty);
</code>
Now if the value doesnt exist or is not convertible to a
float/double/integer i cannot return null, since i want to return value
types. For the double value type there is a value called Double.NaN
which would be my candidate to return if the value doesnt exist or is
not convertible. However i found no such value in Float, Long, Integer.
Now my question is:
1. could I do something like:
<code>
public int getPropertyAsInt( String xPathToProperty ) {
....
if ( cannotConvertOrDoesntExist ) {
return (int) Double.NaN;
}
}
</code>
2. If i cannot do this, what other approach could be taken?
Thanks in advance for all your help.
Best regards,
Jan Thomä
i am trying to write some kind of registry that internally stores values
as strings. I wanted to provide some convenience methods which allow to
retrieve property values as int or float.
<code>
/**
* @see #getPropertyAsString(String)
*/
public double getPropertyAsDouble(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public float getPropertyAsFloat(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public int getPropertyAsInt(String xPathToProperty);
/**
* @see #getPropertyAsString(String)
*/
public long getPropertyAsLong(String xPathToProperty);
/**
* Convenience method to read a property as a string.
*
* @param xPathToProperty the xpath to the property.
*
* @return the property value as a string, null if no such property
can be found.
*/
public String getPropertyAsString(String xPathToProperty);
</code>
Now if the value doesnt exist or is not convertible to a
float/double/integer i cannot return null, since i want to return value
types. For the double value type there is a value called Double.NaN
which would be my candidate to return if the value doesnt exist or is
not convertible. However i found no such value in Float, Long, Integer.
Now my question is:
1. could I do something like:
<code>
public int getPropertyAsInt( String xPathToProperty ) {
....
if ( cannotConvertOrDoesntExist ) {
return (int) Double.NaN;
}
}
</code>
2. If i cannot do this, what other approach could be taken?
Thanks in advance for all your help.
Best regards,
Jan Thomä