Package com.nomagic.magicdraw.properties
Class NumberProperty
- java.lang.Object
-
- com.nomagic.magicdraw.properties.Property
-
- com.nomagic.magicdraw.properties.NumberProperty
-
- All Implemented Interfaces:
PropertyVisitorAcceptor,java.lang.Cloneable
@OpenApiAll public class NumberProperty extends Property
The property for storing and editing some number value in Double, Float or Int formats.
-
-
Field Summary
Fields Modifier and Type Field Description static intDOUBLENumber type is double.static intFLOATNumber type is float.static intINTNumber type is integer.static intLONGNumber type is long.static java.lang.StringPATTERNPatters which is used to format the number.-
Fields inherited from class com.nomagic.magicdraw.properties.Property
DEFAULT_PROPERTY_RESOURCE_PROVIDER, EDITABLE, NULL, NULL_ID_PROPERTY_RESOURCE_PROVIDER, UNDEFINED, VALUE
-
-
Constructor Summary
Constructors Constructor Description NumberProperty()Default constructor for INT property.NumberProperty(java.lang.String id, double value, double low, double high)The property constructor.NumberProperty(java.lang.String id, float value, double low, double high)The property constructor.NumberProperty(java.lang.String id, int value, double low, double high)The property constructor.NumberProperty(java.lang.String id, long value, double low, double high)The property constructor.NumberProperty(java.lang.String id, java.lang.Double value, int type, double low, double high)The property constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(PropertyVisitor v)Accepts the given visitor.NumberPropertyclone()Clones the property.java.lang.StringgetClassType()Returns property class type.doublegetDouble()Returns value as double (primitive type).java.lang.DoublegetDoubleObject()Returns value as Double object.floatgetFloat()Returns value as float (primitive type).doublegetHighRange()Returns highest range of the value.intgetInteger()Returns value as int (primitive type).longgetLong()Returns value as long (primitive type).doublegetLowRange()Returns lowest range of the number value.intgetNumberType()Returns type of the number.static java.lang.StringgetPattern(Property property)static java.lang.StringgetStringRepresentation(int type, java.lang.Double value)static java.lang.StringgetStringRepresentation(int type, java.lang.Double value, java.lang.String pattern)java.lang.ObjectgetValue()Returns properties value.java.lang.StringgetValueStringRepresentation()Returns value's string representation.static java.lang.StringhasError(NumberProperty property, java.lang.String newNumber)booleanisSoftRange()protected booleanisValueCompatible(java.lang.Object value)voidsetHighRange(double range)Returns highest range of the value.voidsetLowRange(double range)Returns lowest range of the value.voidsetNumberType(int type)Sets type of the number.voidsetSoftRange(boolean softRange)voidsetValue(double value)Sets value as primitive double type.voidsetValue(float value)Sets value as primitive float type.voidsetValue(int value)Sets value as primitive integer.voidsetValue(java.lang.Object value)Sets new property value.static java.lang.DoubletoDouble(java.lang.Number number)-
Methods inherited from class com.nomagic.magicdraw.properties.Property
_getValue, _isFrozen, _setFrozen, _setValue, addPropertyChangeListener, addSource, addSources, areValuesEqual, checkFrozen, checkFrozen, createCellEditor, createTableCellRenderer, equals, firePropertyChange, generateDefaultDescriptionID, getAdditionalProperties, getAdditionalProperty, getDescription, getDescriptionID, getFirstElementFromSources, getGroup, getID, getIntroductoryVersion, getName, getNonEditableReason, getProjectFromSourcesOrActive, getPureDescription, getResourceProvider, getResourceProviderID, getSourceAsElement, getSources, getSourcesAsStream, getUndefinedString, getUndefinedString, hashCode, isEditable, isUndefinedState, removePropertyChangeListener, setAdditionalProperties, setAdditionalProperty, setDescription, setDescriptionID, setEditable, setGroup, setID, setIntroductoryVersion, setNonEditableReason, setResourceProvider, setResourceProviderID, setSources, setUndefinedState, toString
-
-
-
-
Field Detail
-
PATTERN
public static final java.lang.String PATTERN
Patters which is used to format the number. This pattern should be set to the additional properties of NumberProperty- See Also:
- Constant Field Values
-
INT
public static final int INT
Number type is integer.- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
Number type is double.- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
Number type is float.- See Also:
- Constant Field Values
-
LONG
public static final int LONG
Number type is long.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NumberProperty
public NumberProperty()
Default constructor for INT property. Value of the property will be 0. ID will be empty string.
-
NumberProperty
public NumberProperty(java.lang.String id, @CheckForNull java.lang.Double value, int type, double low, double high)The property constructor.- Parameters:
id- the ID of property.value- the number value of the property.type- the number type (INT, DOUBLE or FLOAT).low- lowest range of the number.high- highest range of the number.
-
NumberProperty
public NumberProperty(java.lang.String id, int value, double low, double high)The property constructor. Type of number will be INT.- Parameters:
id- the ID of property.value- the value of the property.low- lowest range of the number.high- highest range of the number.
-
NumberProperty
public NumberProperty(java.lang.String id, float value, double low, double high)The property constructor. Type of number will be FLOAT.- Parameters:
id- the ID of property.value- the value of the property.low- lowest range of the number.high- highest range of the number.
-
NumberProperty
public NumberProperty(java.lang.String id, double value, double low, double high)The property constructor. Type of number will be DOUBLE.- Parameters:
id- the ID of property.value- the value of the property.low- lowest range of the number.high- highest range of the number.
-
NumberProperty
public NumberProperty(java.lang.String id, long value, double low, double high)The property constructor. Type of number will be LONG.- Parameters:
id- the ID of property.value- the value of the property.low- lowest range of the number.high- highest range of the number.
-
-
Method Detail
-
getValueStringRepresentation
public java.lang.String getValueStringRepresentation()
Returns value's string representation.- Overrides:
getValueStringRepresentationin classProperty- Returns:
- the string representation of the number.
-
getPattern
@CheckForNull public static java.lang.String getPattern(Property property)
-
getStringRepresentation
public static java.lang.String getStringRepresentation(int type, @CheckForNull java.lang.Double value, @CheckForNull java.lang.String pattern)
-
getStringRepresentation
public static java.lang.String getStringRepresentation(int type, @CheckForNull java.lang.Double value)
-
toDouble
@CheckForNull public static java.lang.Double toDouble(java.lang.Number number)
-
accept
public void accept(PropertyVisitor v) throws java.lang.Exception
Description copied from class:PropertyAccepts the given visitor.- Specified by:
acceptin interfacePropertyVisitorAcceptor- Overrides:
acceptin classProperty- Parameters:
v- the PropertyVisitor.- Throws:
java.lang.Exception
-
getInteger
public int getInteger()
Returns value as int (primitive type).- Returns:
- property value as int. 0 if value is null
-
getLong
public long getLong()
Returns value as long (primitive type).- Returns:
- property value as long. 0 if value is null
-
getDouble
public double getDouble()
Returns value as double (primitive type).- Returns:
- property value as double. 0 if value is null
-
getFloat
public float getFloat()
Returns value as float (primitive type).- Returns:
- property value as float. 0 if value is null
-
getDoubleObject
@CheckForNull public java.lang.Double getDoubleObject()
Returns value as Double object.- Returns:
- property value as Double.
-
setValue
public void setValue(int value)
Sets value as primitive integer.- Parameters:
value- a new integer value.
-
setValue
public void setValue(double value)
Sets value as primitive double type.- Parameters:
value- a new double value.
-
setValue
public void setValue(float value)
Sets value as primitive float type.- Parameters:
value- a new float value.
-
setValue
public void setValue(java.lang.Object value)
Description copied from class:PropertySets new property value. Will fire aPropertyChangeEventwith propertyName - property ID, newValue and oldValue.
-
isValueCompatible
protected boolean isValueCompatible(java.lang.Object value)
- Overrides:
isValueCompatiblein classProperty- Returns:
- true if given object can be assigned as value to this property
-
getValue
@CheckForNull public java.lang.Object getValue()
Description copied from class:PropertyReturns properties value.
-
getClassType
public java.lang.String getClassType()
Returns property class type.- Specified by:
getClassTypein interfacePropertyVisitorAcceptor- Overrides:
getClassTypein classProperty- Returns:
- PropertyID.NUMBER_PROPERTY
- See Also:
PropertyID.NUMBER_PROPERTY
-
getNumberType
public int getNumberType()
Returns type of the number.- Returns:
- number type - INT, DOUBLE or FLOAT.
-
setNumberType
public void setNumberType(int type)
Sets type of the number.- Parameters:
type- the number type - INT, DOUBLE or FLOAT.
-
getLowRange
public double getLowRange()
Returns lowest range of the number value.- Returns:
- lowest range.
-
getHighRange
public double getHighRange()
Returns highest range of the value.- Returns:
- highest range.
-
setLowRange
public void setLowRange(double range)
Returns lowest range of the value.- Parameters:
range- the lowest range.
-
setHighRange
public void setHighRange(double range)
Returns highest range of the value.- Parameters:
range- the highest range.
-
hasError
@CheckForNull public static java.lang.String hasError(NumberProperty property, java.lang.String newNumber) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
isSoftRange
public boolean isSoftRange()
- Returns:
- Property is not allowed to cross the range boundaries.
-
setSoftRange
public void setSoftRange(boolean softRange)
- Parameters:
softRange- Property is allowed to cross the range boundaries. Default is false.
-
clone
public NumberProperty clone()
Description copied from class:PropertyClones the property. Clone is not deep, the clone will have the same instance of value. The clone will not have registered PropertyChangeListeners.
-
-