X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Ftype%2FNumberType.java;h=b6c35824308442cc02074832fa7af254fb2f4432;hb=a1696e5257fae039410c924155fdeffc1ce1b3e9;hp=53ce107aa79aab34252afe93a5f13fc659842081;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/NumberType.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/NumberType.java index 53ce107aa..b6c358243 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/type/NumberType.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/type/NumberType.java @@ -1,21 +1,21 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ +/******************************************************************************* + * 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; -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; +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: @@ -23,16 +23,16 @@ import org.simantics.databoard.util.RangeException; * */ public abstract class NumberType extends Datatype { - - /** 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; + + /** 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. @@ -54,65 +54,65 @@ public abstract class NumberType extends Datatype { * @see Units */ public void setUnit(String unit) { - if (unit==null) metadata.remove( KEY_UNIT ); + if (unit==null) metadata.remove( KEY_UNIT ); else metadata.put( KEY_UNIT, unit ); } - 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 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) { + public void setRange(String range) { if (range==null) metadata.remove( KEY_RANGE ); else metadata.put( KEY_RANGE, range ); } - public void setRange(Range range) { - this.range = range; - if (range==null) { - rangeIsForStr = null; - metadata.remove( KEY_RANGE ); - } else { + 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 ); - } - } - - @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 getChildType(ChildReference reference) throws ReferenceException { - if (reference==null) return (T) this; - throw new ReferenceException(reference.getClass()+" is not a subreference of NumberType"); - } + 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 getChildType(ChildReference reference) throws ReferenceException { + if (reference==null) return (T) this; + throw new ReferenceException(reference.getClass()+" is not a subreference of NumberType"); + } }