T - the number type we support as our subjects typepublic abstract class AbstractNumberStringConverter<T extends Number> extends AbstractTypeConverter<String,T> implements TypeConverter<String,T>
Derived classes must only implement convertToNumber(String)
and my override convertToString(Number) if the default behaviour
is not desired.
| Constructor and Description |
|---|
AbstractNumberStringConverter(ValueModel<T> pSubject)
Create a new Number-to-String converter where null is a valid value.
|
AbstractNumberStringConverter(ValueModel<T> pSubject,
boolean pNullIsValid)
Create a new Number-to-String converter.
|
| Modifier and Type | Method and Description |
|---|---|
T |
convertOwnToSubjectValue(String pOwnValue)
Converts from a String to an Number.
|
String |
convertSubjectToOwnValue(T pSubjectValue)
Converts from a Number to a String.
|
protected abstract T |
convertToNumber(String pOwnValue)
convert the own string value to the number.
|
protected String |
convertToString(Number pSubjectValue)
Converts from a Number to the String by calling toString.
|
boolean |
getNullIsValid() |
void |
setNullIsValid(boolean pNullIsValid)
Sets the flag if we should use null as an alternative value if the conversion fails
|
void |
setNullSubstitute(Number pNullSubstitute)
Method to set the Integer null substitute.
|
dispose, getPropagateFailedConversions, getSubject, getSubjectValue, getSyncKey, getSyncMessage, getSyncState, getValue, getValue, isEditable, setPropagateFailedConversions, setSyncKey, setSyncMessage, setValue, stateChangedaddChangeListener, booleanValue, checkDisposed, doubleValue, fireStateChanged, floatValue, getDependents, getName, intValue, isDisposed, isInSetValue, isSetForced, longValue, onChangeSend, removeChangeListener, retractInterestsFor, setInSetValue, setName, setObjectValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueForced, signalExternalUpdate, stringValueclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSyncKey, getSyncMessage, getSyncState, setSyncKey, setSyncMessageaddChangeListener, booleanValue, dispose, doubleValue, floatValue, getDependents, getName, getValue, intValue, isDisposed, isEditable, isSetForced, longValue, onChangeSend, removeChangeListener, retractInterestsFor, setName, setObjectValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueForced, stringValuepublic AbstractNumberStringConverter(ValueModel<T> pSubject)
pSubject - the ValueModel holding the original valuepublic AbstractNumberStringConverter(ValueModel<T> pSubject, boolean pNullIsValid)
pSubject - the ValueModel holding the original valuepNullIsValid - true if we should use null as an
alternative value if the conversion failspublic void setNullIsValid(boolean pNullIsValid)
pNullIsValid - true if we should use null as an
alternative value if the conversion failspublic boolean getNullIsValid()
public void setNullSubstitute(Number pNullSubstitute)
pNullSubstitute - null or any integerIllegalStateException - if null is not validpublic String convertSubjectToOwnValue(T pSubjectValue) throws ConversionException
convertSubjectToOwnValue in interface TypeConverter<String,T extends Number>pSubjectValue - value in the subject's type (Number)ConversionException - if we detected an error during the conversionprotected String convertToString(Number pSubjectValue)
pSubjectValue - the value in the source type (Number), never nullpublic T convertOwnToSubjectValue(String pOwnValue) throws ConversionException
convertOwnToSubjectValue in interface TypeConverter<String,T extends Number>pOwnValue - value in this value model's type (String)ConversionException - if we detected an error during the conversionprotected abstract T convertToNumber(String pOwnValue) throws NumberFormatException
return new Integer( ownValue);
.
If the conversion is not possible, you can throw a NumberFormatException
which will be converted into a ConversionException with the correct
substitute values.pOwnValue - the value as a stringNumberFormatException - if the string value is not parsable into a numberCopyright © 2017 Jürgen Zeller (privat). All rights reserved.