Package ome.model.units
Class Conversion
- java.lang.Object
-
- ome.model.units.Conversion
-
- Direct Known Subclasses:
Conversion.Add
,Conversion.Int
,Conversion.Mul
,Conversion.Pow
,Conversion.Rat
,Conversion.Sym
public abstract class Conversion extends java.lang.Object
Base-functor like object which can be used for preparing complex equations for converting from one unit to another. Primarily these classes and static methods are used via code-generation. Sympy-generated strings are placed directly into code. If the proper imports are in place, then a top-levelConversion
(usually of typeConversion.Add
orConversion.Mul
is returned from the evaluation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Conversion.Add
Sums allConversion
instances viaBigDecimal.add(BigDecimal)
.static class
Conversion.Int
Simply is a representation of a possibly large integer.static class
Conversion.Mul
Multiplies allConversion
instances viaBigDecimal.multiply(BigDecimal)
.static class
Conversion.Pow
Exponentiates twoConversion
instances viaBigDecimal.pow(int)
.static class
Conversion.Rat
Divides twoConversion
instances viaBigDecimal.divide(BigDecimal, MathContext)
.static class
Conversion.Sym
Simply represents the variable of the source unit so thatConversion.Sym.convert(double)
just returns the value passed in.
-
Field Summary
Fields Modifier and Type Field Description protected Conversion[]
conversions
Conversions, if any, which are passed into the constructor of this instance.
-
Constructor Summary
Constructors Constructor Description Conversion(Conversion... conversions)
Primary constructor for aConversion
object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Conversion
Add(Conversion... conversions)
Static helper for creatingConversion.Add
instances.abstract java.math.BigDecimal
convert(double original)
Primary operator forConversion
instances.static Conversion
Int(long i)
Static helper for creatingConversion.Int
instances.static Conversion
Int(java.lang.String i)
Static helper for creatingConversion.Int
instances.static Conversion
Mul(Conversion... conversions)
Static helper for creatingConversion.Mul
instances.static Conversion
Pow(long num, int den)
Static helper for creatingConversion.Pow
instances.static Conversion
Rat(long num, long den)
Static helper for creatingConversion.Rat
instances.static Conversion
Rat(Conversion... conversions)
Static helper for creatingConversion.Rat
instances.static Conversion
Sym(java.lang.String sym)
Static helper for creatingConversion.Sym
instances.
-
-
-
Field Detail
-
conversions
protected final Conversion[] conversions
Conversions, if any, which are passed into the constructor of this instance. If none are passed, then the implementation has a short-cut form, e.g. taking anInteger
rather than anConversion.Int
.
-
-
Constructor Detail
-
Conversion
public Conversion(Conversion... conversions)
Primary constructor for aConversion
object. No processing happens during constructor. Instead, theconvert(double)
method will handle descending through the recursive structure.- Parameters:
conversions
- can be empty.
-
-
Method Detail
-
Add
public static Conversion Add(Conversion... conversions)
Static helper for creatingConversion.Add
instances.
-
Int
public static Conversion Int(long i)
Static helper for creatingConversion.Int
instances.
-
Int
public static Conversion Int(java.lang.String i)
Static helper for creatingConversion.Int
instances.
-
Mul
public static Conversion Mul(Conversion... conversions)
Static helper for creatingConversion.Mul
instances.
-
Pow
public static Conversion Pow(long num, int den)
Static helper for creatingConversion.Pow
instances.
-
Rat
public static Conversion Rat(long num, long den)
Static helper for creatingConversion.Rat
instances.
-
Rat
public static Conversion Rat(Conversion... conversions)
Static helper for creatingConversion.Rat
instances.
-
Sym
public static Conversion Sym(java.lang.String sym)
Static helper for creatingConversion.Sym
instances.
-
convert
public abstract java.math.BigDecimal convert(double original)
Primary operator forConversion
instances.- Parameters:
original
- A unit value which is to be processed through the tree-like representation of this equation. OnlyConversion.Sym
objects will actually use the "original" value.- Returns:
- a
BigDecimal
result from the calculation. If this value maps toDouble.NEGATIVE_INFINITY
orDouble.POSITIVE_INFINITY
, then aBigResult
exception should be thrown before returning to clients.
-
-