Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PersistableQuantity.cs
1
using
System;
2
using
System.Text;
3
using
Waher.Content
;
4
using
Waher.Persistence.Attributes
;
5
using
Waher.Script.Exceptions
;
6
using
Waher.Script.Objects
;
7
using
Waher.Script.Units
;
8
9
namespace
Waher.Things.SensorData
10
{
14
public
class
PersistableQuantity
:
IPhysicalQuantity
, IComparable
15
{
19
public
PersistableQuantity
()
20
{
21
}
22
29
public
PersistableQuantity
(
double
Value
,
string
Unit
,
byte
NrDecimals
)
30
{
31
this.Value =
Value
;
32
this.Unit =
Unit
;
33
this.NrDecimals =
NrDecimals
;
34
}
35
39
[ShortName(
"v"
)]
40
public
double
Value
{
get
;
set
; }
41
45
[ShortName(
"d"
)]
46
[DefaultValueStringEmpty]
47
public
string
Unit
{
get
;
set
; }
48
52
[DefaultValue(0)]
53
public
byte
NrDecimals
{
get
;
set
; }
54
56
public
override
bool
Equals
(
object
obj)
57
{
58
return
obj is
PersistableQuantity
Q &&
59
this.Value == Q.Value &&
60
this.Unit == Q.Unit &&
61
this.NrDecimals == Q.
NrDecimals
;
62
}
63
65
public
override
int
GetHashCode
()
66
{
67
int
Result = this.
Value
.GetHashCode();
68
Result ^= Result << 5 ^ (this.
Unit
?.
GetHashCode
() ?? 0);
69
Result ^= Result << 5 ^ this.
NrDecimals
.GetHashCode();
70
71
return
Result;
72
}
73
75
public
override
string
ToString
()
76
{
77
StringBuilder sb =
new
StringBuilder();
78
79
sb.Append(
CommonTypes
.
Encode
(
this
.Value,
this
.NrDecimals));
80
81
if
(!
string
.IsNullOrEmpty(this.
Unit
))
82
{
83
sb.Append(
' '
);
84
sb.Append(this.
Unit
);
85
}
86
87
return
sb.ToString();
88
}
89
94
public
PhysicalQuantity
ToPhysicalQuantity
()
95
{
96
return
new
PhysicalQuantity
(this.
Value
,
new
Unit
(this.
Unit
));
97
}
98
102
public
int
CompareTo
(
object
obj)
103
{
104
if
(!(obj is
IPhysicalQuantity
PQ))
105
throw
new
ScriptException
(
"Values not comparable."
);
106
107
return
this.
ToPhysicalQuantity
().
CompareTo
(PQ.ToPhysicalQuantity());
108
}
109
}
110
}
Waher.Content.CommonTypes
Helps with parsing of commong data types.
Definition:
CommonTypes.cs:13
Waher.Content.CommonTypes.Encode
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition:
CommonTypes.cs:594
Waher.Script.Exceptions.ScriptException
Base class for script exceptions.
Definition:
ScriptException.cs:9
Waher.Script.Objects.PhysicalQuantity
Physical quantity.
Definition:
PhysicalQuantity.cs:14
Waher.Script.Objects.PhysicalQuantity.CompareTo
int CompareTo(object obj)
IComparable.CompareTo
Definition:
PhysicalQuantity.cs:286
Waher.Script.Units.Unit
Represents a unit.
Definition:
Unit.cs:15
Waher.Script.Units.Unit.GetHashCode
override int GetHashCode()
Definition:
Unit.cs:506
Waher.Things.SensorData.PersistableQuantity
Persistable quantity object.
Definition:
PersistableQuantity.cs:15
Waher.Things.SensorData.PersistableQuantity.ToString
override string ToString()
Definition:
PersistableQuantity.cs:75
Waher.Things.SensorData.PersistableQuantity.Value
double Value
Magnitude
Definition:
PersistableQuantity.cs:40
Waher.Things.SensorData.PersistableQuantity.Unit
string Unit
Unit
Definition:
PersistableQuantity.cs:47
Waher.Things.SensorData.PersistableQuantity.CompareTo
int CompareTo(object obj)
IComparable.CompareTo
Definition:
PersistableQuantity.cs:102
Waher.Things.SensorData.PersistableQuantity.PersistableQuantity
PersistableQuantity(double Value, string Unit, byte NrDecimals)
Persistable quantity object.
Definition:
PersistableQuantity.cs:29
Waher.Things.SensorData.PersistableQuantity.PersistableQuantity
PersistableQuantity()
Persistable quantity object.
Definition:
PersistableQuantity.cs:19
Waher.Things.SensorData.PersistableQuantity.NrDecimals
byte NrDecimals
Number of decimals.
Definition:
PersistableQuantity.cs:53
Waher.Things.SensorData.PersistableQuantity.Equals
override bool Equals(object obj)
Definition:
PersistableQuantity.cs:56
Waher.Things.SensorData.PersistableQuantity.GetHashCode
override int GetHashCode()
Definition:
PersistableQuantity.cs:65
Waher.Things.SensorData.PersistableQuantity.ToPhysicalQuantity
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
Definition:
PersistableQuantity.cs:94
Waher.Script.Objects.IPhysicalQuantity
Interface for objects that can be represented as a physical quantity.
Definition:
IPhysicalQuantity.cs:7
Waher.Content
Definition:
Array.cs:6
Waher.Persistence.Attributes
Definition:
ArchivingTimeAttribute.cs:4
Waher.Script.Exceptions
Definition:
ScriptAbortedException.cs:4
Waher.Script.Objects
Definition:
BooleanValue.cs:7
Waher.Script.Units
Definition:
AtomicUnit.cs:2
Waher.Things.SensorData
Definition:
BooleanField.cs:6
IoTGateway
Things
Waher.Things
SensorData
PersistableQuantity.cs
Generated by
1.9.5