1 package org.djunits.value.vdouble.matrix.base;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.Unit;
6 import org.djunits.value.ValueRuntimeException;
7 import org.djunits.value.util.ValueUtil;
8 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
9 import org.djutils.exceptions.Throw;
10
11
12
13
14
15
16
17
18
19
20
21 public class DoubleSparseValue<U extends Unit<U>, S extends DoubleScalar<U, S>> implements Serializable
22 {
23
24 private static final long serialVersionUID = 20191018L;
25
26
27 private final int row;
28
29
30 private final int column;
31
32
33 private final double valueSI;
34
35
36
37
38
39
40
41 public DoubleSparseValue(final int row, final int column, final S value)
42 {
43 this(row, column, checkNull(value).getSI());
44 }
45
46
47
48
49
50
51
52
53 private static <U extends Unit<U>, S extends DoubleScalar<U, S>> S checkNull(final S value)
54 {
55 Throw.whenNull(value, "value may not be null");
56 return value;
57 }
58
59
60
61
62
63
64
65
66 public DoubleSparseValue(final int row, final int column, final double valueInUnit, final U unit)
67 {
68 this(row, column, (float) ValueUtil.expressAsSIUnit(valueInUnit, unit));
69 }
70
71
72
73
74
75
76
77 public DoubleSparseValue(final int row, final int column, final double valueSI)
78 {
79 Throw.when(row < 0, ValueRuntimeException.class, "row may not be negative");
80 Throw.when(column < 0, ValueRuntimeException.class, "column may not be negative");
81 this.row = row;
82 this.column = column;
83 this.valueSI = valueSI;
84 }
85
86
87
88
89 public final int getRow()
90 {
91 return this.row;
92 }
93
94
95
96
97 public final int getColumn()
98 {
99 return this.column;
100 }
101
102
103
104
105 public final double getValueSI()
106 {
107 return this.valueSI;
108 }
109
110 @Override
111 public String toString()
112 {
113 return "DoubleSparseValue [row=" + this.row + ", column=" + this.column + ", valueSI=" + this.valueSI + "]";
114 }
115
116 }