Skip to content

Commit

Permalink
Add constructors for default units
Browse files Browse the repository at this point in the history
Before the addition of units, the OME-XML schema assumed certain units.
And the OME-XML Java library had methods that took various sorts of
numbers (Double, Integer, PositiveInteger, etc.) using these units
implicitly.

When converting code from the old API to the new one, it is very
convenient to simply change e.g. "new PositiveFloat(foo)" to "new
Length(foo)" but this only works if there is a constructor for each type
of quantity that assumes the unit from earlier schema versions.
  • Loading branch information
ctrueden committed Mar 23, 2015
1 parent d16899c commit 17300c4
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Angle.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Angle extends Quantity implements Comparable<Angle>
Unit<ome.units.quantity.Angle> unit;
private int hashCodeValue;

/**
* Creates a new angle quantity with the default unit of
* {@link UNITS#RADIAN radians}.
*/
public Angle(Number inValue)
{
this(inValue, UNITS.RADIAN);
}

public Angle(Number inValue,
Unit<ome.units.quantity.Angle> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/ElectricPotential.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class ElectricPotential extends Quantity implements Comparable<ElectricPo
Unit<ome.units.quantity.ElectricPotential> unit;
private int hashCodeValue;

/**
* Creates a new electric potential quantity with the default unit of
* {@link UNITS#VOLT volts}.
*/
public ElectricPotential(Number inValue)
{
this(inValue, UNITS.VOLT);
}

public ElectricPotential(Number inValue,
Unit<ome.units.quantity.ElectricPotential> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Frequency.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Frequency extends Quantity implements Comparable<Frequency>
Unit<ome.units.quantity.Frequency> unit;
private int hashCodeValue;

/**
* Creates a new frequency quantity with the default unit of
* {@link UNITS#MEGAHZ MHz}.
*/
public Frequency(Number inValue)
{
this(inValue, UNITS.MEGAHZ);
}

public Frequency(Number inValue,
Unit<ome.units.quantity.Frequency> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Length.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Length extends Quantity implements Comparable<Length>
Unit<ome.units.quantity.Length> unit;
private int hashCodeValue;

/**
* Creates a new length quantity with the default unit of
* {@link UNITS#MICROM microns}.
*/
public Length(Number inValue)
{
this(inValue, UNITS.MICROM);
}

public Length(Number inValue,
Unit<ome.units.quantity.Length> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Power.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Power extends Quantity implements Comparable<Power>
Unit<ome.units.quantity.Power> unit;
private int hashCodeValue;

/**
* Creates a new power quantity with the default unit of
* {@link UNITS#WATT watts}.
*/
public Power(Number inValue)
{
this(inValue, UNITS.WATT);
}

public Power(Number inValue,
Unit<ome.units.quantity.Power> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Pressure.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Pressure extends Quantity implements Comparable<Pressure>
Unit<ome.units.quantity.Pressure> unit;
private int hashCodeValue;

/**
* Creates a new pressure quantity with the default unit of
* {@link UNITS#PASCAL pascals}.
*/
public Pressure(Number inValue)
{
this(inValue, UNITS.PASCAL);
}

public Pressure(Number inValue,
Unit<ome.units.quantity.Pressure> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Temperature.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Temperature extends Quantity implements Comparable<Temperature>
Unit<ome.units.quantity.Temperature> unit;
private int hashCodeValue;

/**
* Creates a new temperature quantity with the default unit of
* {@link UNITS#DEGREEC degrees Celsius}.
*/
public Temperature(Number inValue)
{
this(inValue, UNITS.DEGREEC);
}

public Temperature(Number inValue,
Unit<ome.units.quantity.Temperature> inUnit)
{
Expand Down
10 changes: 10 additions & 0 deletions components/ome-xml/src/ome/units/quantity/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package ome.units.quantity;

import ome.units.UNITS;
import ome.units.unit.Unit;

/**
Expand All @@ -52,6 +53,15 @@ public class Time extends Quantity implements Comparable<Time>
Unit<ome.units.quantity.Time> unit;
private int hashCodeValue;

/**
* Creates a new time quantity with the default unit of
* {@link UNITS#SECOND seconds}.
*/
public Time(Number inValue)
{
this(inValue, UNITS.SECOND);
}

public Time(Number inValue,
Unit<ome.units.quantity.Time> inUnit)
{
Expand Down

0 comments on commit 17300c4

Please sign in to comment.