-/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
+/*******************************************************************************
+ * Copyright (c) 2010 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
package org.simantics.databoard.type;
-import org.simantics.databoard.Units;\r
-import org.simantics.databoard.accessor.error.ReferenceException;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.util.Range;\r
-import org.simantics.databoard.util.RangeException;\r
+import org.simantics.databoard.Units;
+import org.simantics.databoard.accessor.error.ReferenceException;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.util.Range;
+import org.simantics.databoard.util.RangeException;
/**
* NumberType is comparable primitive type:
*
*/
public abstract class NumberType extends Datatype {
- \r
- /** Unit string describes the quantity, magnitude and unit of the value. */\r
- public static final String KEY_UNIT = "unit";\r
- \r
- /** Value ranges that are valid. */\r
- public static final String KEY_RANGE = "range";\r
- \r
- // Cached Range\r
- private transient Range range;\r
- private transient String rangeIsForStr;\r
+
+ /** Unit string describes the quantity, magnitude and unit of the value. */
+ public static final String KEY_UNIT = "unit";
+
+ /** Value ranges that are valid. */
+ public static final String KEY_RANGE = "range";
+
+ // Cached Range
+ private transient Range range;
+ private transient String rangeIsForStr;
/**
* Get the unit type.
* @see Units
*/
public void setUnit(String unit) {
- if (unit==null) metadata.remove( KEY_UNIT ); \r
+ if (unit==null) metadata.remove( KEY_UNIT );
else metadata.put( KEY_UNIT, unit );
}
- public Range getRange() {\r
- String rangeStr = metadata.get( KEY_RANGE );\r
- if (rangeStr == null) return null;\r
- if (range != null && rangeStr!=null && rangeStr==rangeIsForStr) return range;\r
- try {\r
- rangeIsForStr = rangeStr;\r
- range = Range.valueOf( rangeStr );\r
- } catch (RangeException e) {\r
- range = null;\r
- }\r
- return range;\r
+ public Range getRange() {
+ String rangeStr = metadata.get( KEY_RANGE );
+ if (rangeStr == null) return null;
+ if (range != null && rangeStr!=null && rangeStr==rangeIsForStr) return range;
+ try {
+ rangeIsForStr = rangeStr;
+ range = Range.valueOf( rangeStr );
+ } catch (RangeException e) {
+ range = null;
+ }
+ return range;
}
public String getRangeStr() {
return metadata.get( KEY_RANGE );
}
- public void setRange(String range) {\r
+ public void setRange(String range) {
if (range==null) metadata.remove( KEY_RANGE ); else
metadata.put( KEY_RANGE, range );
}
- public void setRange(Range range) {\r
- this.range = range;\r
- if (range==null) {\r
- rangeIsForStr = null;\r
- metadata.remove( KEY_RANGE );\r
- } else {\r
+ public void setRange(Range range) {
+ this.range = range;
+ if (range==null) {
+ rangeIsForStr = null;
+ metadata.remove( KEY_RANGE );
+ } else {
rangeIsForStr = range.toString();
- metadata.put( KEY_RANGE, rangeIsForStr );\r
- }\r
- }\r
- \r
- @Override\r
- public int getComponentCount() {\r
- return 0;\r
- }\r
- \r
- @Override\r
- public Datatype getComponentType(int index) {\r
- throw new IllegalArgumentException();\r
- }\r
- \r
- @Override\r
- public Datatype getComponentType(ChildReference path) {\r
- if (path==null) return this;\r
- throw new IllegalArgumentException();\r
- } \r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {\r
- if (reference==null) return (T) this;\r
- throw new ReferenceException(reference.getClass()+" is not a subreference of NumberType"); \r
- }\r
+ metadata.put( KEY_RANGE, rangeIsForStr );
+ }
+ }
+
+ @Override
+ public int getComponentCount() {
+ return 0;
+ }
+
+ @Override
+ public Datatype getComponentType(int index) {
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public Datatype getComponentType(ChildReference path) {
+ if (path==null) return this;
+ throw new IllegalArgumentException();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Datatype> T getChildType(ChildReference reference) throws ReferenceException {
+ if (reference==null) return (T) this;
+ throw new ReferenceException(reference.getClass()+" is not a subreference of NumberType");
+ }
}