Skip to content

Commit

Permalink
Added no-args constructors to all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Feb 23, 2022
1 parent 4033425 commit 6431f91
Show file tree
Hide file tree
Showing 47 changed files with 243 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public Dimension getDimension()
{
return new Dimension().add(Lightbulb.DIMENSION, 1).add(Quantity.TIME, -1);
}

@Override
public String toString()
public DimensionValue asBaseUnit()
{
return m_value + "boxes/h";
return new NamelessDimensionValue(m_value.multiply(s_factor), getDimension());
}

@Override
public DimensionValue asBaseUnit()
public String getUnitName()
{
return new NamelessDimensionValue(m_value.multiply(s_factor), getDimension());
return "boxes/h";
}


Expand Down
4 changes: 2 additions & 2 deletions Source/examples/ca/uqac/lif/units/examples/factory/Euro.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public Dimension getDimension()
}

@Override
public String toString()
public String getUnitName()
{
return m_value + " €";
return "€";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public Dimension getDimension()
}

@Override
public String toString()
public String getUnitName()
{
return m_value + " lightbulb(s)";
return "lightbulb(s)";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public Dimension getDimension()
}

@Override
public String toString()
public String getUnitName()
{
return m_value + " box(es)";
return "box(es)";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public String toString()
{
return "$" + m_value;
}

@Override
public String getUnitName()
{
return "$";
}

@Override
public USDollar asBaseUnit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public String toString()
{
return "$" + m_value + "/box";
}

@Override
public String getUnitName()
{
return "$/box";
}

@Override
public DimensionValue asBaseUnit()
Expand Down
8 changes: 8 additions & 0 deletions Source/src/ca/uqac/lif/numbers/FloatingPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public class FloatingPoint implements Real
*/
protected final double m_uncertainty;

/**
* No-args constructor. Used only for deserialization.
*/
protected FloatingPoint()
{
this(0);
}

/**
* Creates a new floating point number and specifies its uncertainty.
* @param value The value of the floating point number
Expand Down
4 changes: 2 additions & 2 deletions Source/src/ca/uqac/lif/numbers/NumberFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class NumberFormatter
/**
* The UTF-8 "plus or minus" symbol.
*/
public static final String U_PM = "\u00b1";
public static final transient String U_PM = "\u00b1";

/**
* The UTF-8 "times" symbol.
*/
public static final String U_TIMES = "\u00d7";
public static final transient String U_TIMES = "\u00d7";

/**
* Private constructor, as this class is not meant to be instantiated.
Expand Down
8 changes: 8 additions & 0 deletions Source/src/ca/uqac/lif/numbers/Whole.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public class Whole implements Real
*/
protected final double m_uncertainty;

/**
* No-args constructor. Used only for deserialization.
*/
protected Whole()
{
this(0);
}

/**
* Creates a whole number out of a integer value.
* @param value The integer value of the number
Expand Down
10 changes: 9 additions & 1 deletion Source/src/ca/uqac/lif/units/Angle.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class Angle extends DimensionValue
/**
* The dimension of the angle value (i.e. <i>algne</i><sup>1</sup>).
*/
/*@ non_null @*/ public static final Dimension DIMENSION = new Dimension().add(Quantity.ANGLE, 1);
/*@ non_null @*/ public static final transient Dimension DIMENSION = new Dimension().add(Quantity.ANGLE, 1);

public Angle(double x)
{
Expand All @@ -41,6 +41,14 @@ public Angle(/*@ non_null @*/ Real x)
super(x);
}

/**
* No-args constructor. Used only for deserialization.
*/
protected Angle()
{
super();
}

@Override
/*@ non_null @*/ public Dimension getDimension()
{
Expand Down
7 changes: 6 additions & 1 deletion Source/src/ca/uqac/lif/units/AngularVelocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class AngularVelocity extends DimensionValue
/**
* The dimension of the time value (i.e. <i>angle</i><sup>1</sup> &sdot; <i>time</i><sup>-1</sup>).
*/
public static final Dimension DIMENSION = new Dimension().add(Quantity.ANGLE, 1).add(Quantity.TIME, -1);
public static final transient Dimension DIMENSION = new Dimension().add(Quantity.ANGLE, 1).add(Quantity.TIME, -1);

public AngularVelocity(DimensionValue x)
{
Expand All @@ -45,6 +45,11 @@ public AngularVelocity(double x)
super(x);
}

protected AngularVelocity()
{
super();
}

@Override
public Dimension getDimension()
{
Expand Down
10 changes: 9 additions & 1 deletion Source/src/ca/uqac/lif/units/DimensionValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ public abstract class DimensionValue implements Comparable<DimensionValue>
/**
* The value in "native" units.
*/
/*@ non_null @*/ protected final Real m_value;
/*@ non_null @*/ protected Real m_value;

/**
* No-args constructor. Used only for deserialization.
*/
protected DimensionValue()
{
this(0);
}

/**
* Creates a new dimension value from a scalar number.
Expand Down
4 changes: 2 additions & 2 deletions Source/src/ca/uqac/lif/units/DimensionValuePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public abstract class DimensionValuePart implements Part
/**
* Public instance of the {@link UnitName} part.
*/
public static final UnitName unitName = new UnitName();
public static final transient UnitName unitName = new UnitName();

/**
* Public instance of the {@link ScalarPart} part.
*/
public static final ScalarPart scalar = new ScalarPart();
public static final transient ScalarPart scalar = new ScalarPart();

@Override
public boolean appliesTo(Object o)
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/Frequency.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Frequency(DimensionValue x)
super(x);
}

protected Frequency()
{
super();
}

@Override
public Dimension getDimension()
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/Length.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Length(/*@ non_null @*/ Real x)
super(x);
}

public Length()
{
super();
}

@Override
/*@ non_null @*/ public Dimension getDimension()
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/Mass.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Mass(/*@ non_null @*/ DimensionValue x)
super(x);
}

protected Mass()
{
super();
}

@Override
public Dimension getDimension()
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/NamelessDimensionValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public NamelessDimensionValue(/*@ non_null @*/ DimensionValue x)
super(x);
m_dimension = x.getDimension();
}

protected NamelessDimensionValue()
{
super();
}

@Override
protected Real fromBaseUnit(Real x)
Expand Down
7 changes: 6 additions & 1 deletion Source/src/ca/uqac/lif/units/Scalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class Scalar extends DimensionValue
{
public static final Dimension DIMENSION = new Dimension();
public static final transient Dimension DIMENSION = new Dimension();

public Scalar(DimensionValue x)
{
Expand All @@ -32,6 +32,11 @@ public Scalar(double d)
{
super(d);
}

protected Scalar()
{
super();
}

@Override
public DimensionValue asBaseUnit()
Expand Down
7 changes: 6 additions & 1 deletion Source/src/ca/uqac/lif/units/SurfaceValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class SurfaceValue extends DimensionValue
/**
* The dimension of the surface value (i.e. <i>length</i><sup>2</sup>).
*/
/*@ non_null @*/ public static final Dimension DIMENSION = new Dimension().add(Quantity.LENGTH, 2);
/*@ non_null @*/ public static final transient Dimension DIMENSION = new Dimension().add(Quantity.LENGTH, 2);

public SurfaceValue(double x)
{
Expand All @@ -34,6 +34,11 @@ public SurfaceValue(/*@ non_null @*/ DimensionValue x)
super(x);
}

protected SurfaceValue()
{
super();
}

@Override
/*@ non_null @*/ public Dimension getDimension()
{
Expand Down
7 changes: 6 additions & 1 deletion Source/src/ca/uqac/lif/units/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class Time extends DimensionValue
/**
* The dimension of the time value (i.e. <i>time</i><sup>1</sup>).
*/
/*@ non_null @*/ public static final Dimension DIMENSION = new Dimension().add(Quantity.TIME, 1);
/*@ non_null @*/ public static final transient Dimension DIMENSION = new Dimension().add(Quantity.TIME, 1);

public Time(double x)
{
Expand All @@ -45,6 +45,11 @@ public Time(/*@ non_null @*/ Real x)
super(x);
}

protected Time()
{
super();
}

@Override
public Dimension getDimension()
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/Velocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public Velocity(double x)
super(x);
}

protected Velocity()
{
super();
}

@Override
public Dimension getDimension()
{
Expand Down
7 changes: 6 additions & 1 deletion Source/src/ca/uqac/lif/units/computer/Bit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class Bit extends Memory
{
protected static final Whole s_factor = Whole.get(8);
protected static final transient Whole s_factor = Whole.get(8);

public Bit(DimensionValue x)
{
Expand All @@ -22,6 +22,11 @@ public Bit(double x)
super(x);
}

protected Bit()
{
super();
}

@Override
protected Real fromBaseUnit(Real x)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/computer/Byte.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public Byte(Real x)
super(x);
}

protected Byte()
{
super();
}

@Override
public String getUnitName()
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/computer/Kilobyte.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public Kilobyte(double x)
super(x);
}

protected Kilobyte()
{
super();
}

@Override
protected Real fromBaseUnit(Real x)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/src/ca/uqac/lif/units/computer/Megabyte.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public Megabyte(Real x)
super(x);
}

protected Megabyte()
{
super();
}

@Override
protected Real fromBaseUnit(Real x)
{
Expand Down
Loading

0 comments on commit 6431f91

Please sign in to comment.