Skip to content

Commit df28d64

Browse files
authored
0.44.0
- Make many DSElements comparable - Add some default editor metadata
2 parents 56ebf6e + 960cd18 commit df28d64

29 files changed

+1648
-43
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subprojects {
55
apply plugin: 'maven'
66

77
group 'org.iot-dsa'
8-
version '0.43.0'
8+
version '0.44.0'
99

1010
sourceCompatibility = 1.6
1111
targetCompatibility = 1.6

dslink-v2/src/main/java/org/iot/dsa/node/DSBool.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @author Aaron Hansen
88
*/
9-
public class DSBool extends DSElement implements DSIBoolean {
9+
public class DSBool extends DSElement implements Comparable<DSIValue>, DSIBoolean {
1010

1111
// Constants
1212
// ---------
@@ -30,6 +30,21 @@ private DSBool(boolean val) {
3030
// Public Methods
3131
// --------------
3232

33+
@Override
34+
public int compareTo(DSIValue val) {
35+
if ((val instanceof DSIValue) && (((DSIValue) val).isNull())) {
36+
return (this == NULL) ? 0 : 1;
37+
}
38+
if (isNull()) {
39+
return -1;
40+
}
41+
boolean b = val.toElement().toBoolean();
42+
if (b == value) {
43+
return 0;
44+
}
45+
return b ? -1 : 1;
46+
}
47+
3348
@Override
3449
public boolean equals(Object arg) {
3550
if (arg instanceof DSBool) {

dslink-v2/src/main/java/org/iot/dsa/node/DSDouble.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @author Aaron Hansen
77
*/
8-
public class DSDouble extends DSElement implements DSINumber {
8+
public class DSDouble extends DSElement implements Comparable<DSINumber>, DSINumber {
99

1010
// Constants
1111
// ---------
@@ -27,6 +27,24 @@ public class DSDouble extends DSElement implements DSINumber {
2727
// Public Methods
2828
// --------------
2929

30+
@Override
31+
public int compareTo(DSINumber arg) {
32+
if ((arg instanceof DSIValue) && (((DSIValue) arg).isNull())) {
33+
return (this == NULL) ? 0 : 1;
34+
}
35+
if (isNull()) {
36+
return -1;
37+
}
38+
if (arg.isDouble()) {
39+
return (int) (value - arg.toDouble());
40+
} else if (arg.isFloat()) {
41+
return (int) (value - arg.toFloat());
42+
} else if (arg.isInt()) {
43+
return (int) (value - arg.toInt());
44+
}
45+
return (int) (value - arg.toLong());
46+
}
47+
3048
/**
3149
* True if the argument is a DSINumber and the values are equal or they are both isNull.
3250
*/

dslink-v2/src/main/java/org/iot/dsa/node/DSFloat.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @author Aaron Hansen
88
*/
9-
public class DSFloat extends DSValue implements DSINumber {
9+
public class DSFloat extends DSValue implements Comparable<DSINumber>, DSINumber {
1010

1111
// Constants
1212
// ---------
@@ -28,6 +28,24 @@ private DSFloat(float val) {
2828
// Public Methods
2929
// --------------
3030

31+
@Override
32+
public int compareTo(DSINumber arg) {
33+
if ((arg instanceof DSIValue) && (((DSIValue) arg).isNull())) {
34+
return (this == NULL) ? 0 : 1;
35+
}
36+
if (isNull()) {
37+
return -1;
38+
}
39+
if (arg.isFloat()) {
40+
return (int) (value - arg.toFloat());
41+
} else if (arg.isDouble()) {
42+
return (int) (value - arg.toDouble());
43+
} else if (arg.isInt()) {
44+
return (int) (value - arg.toInt());
45+
}
46+
return (int) (value - arg.toLong());
47+
}
48+
3149
/**
3250
* True if the argument is a DSINumber and the values are equal or they are both isNull.
3351
*/

dslink-v2/src/main/java/org/iot/dsa/node/DSInt.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @author Aaron Hansen
77
*/
8-
public class DSInt extends DSValue implements DSINumber {
8+
public class DSInt extends DSValue implements Comparable<DSINumber>, DSIMetadata, DSINumber {
99

1010
// Constants
1111
// ---------
@@ -27,6 +27,24 @@ private DSInt(int val) {
2727
// Public Methods
2828
// --------------
2929

30+
@Override
31+
public int compareTo(DSINumber arg) {
32+
if ((arg instanceof DSIValue) && (((DSIValue) arg).isNull())) {
33+
return (this == NULL) ? 0 : 1;
34+
}
35+
if (isNull()) {
36+
return -1;
37+
}
38+
if (arg.isInt()) {
39+
return value - arg.toInt();
40+
} else if (arg.isDouble()) {
41+
return (int) (value - arg.toDouble());
42+
} else if (arg.isFloat()) {
43+
return (int) (value - arg.toFloat());
44+
}
45+
return (int) (value - arg.toLong());
46+
}
47+
3048
/**
3149
* True if the argument is a DSINumber and the values are equal or they are both isNull.
3250
*/
@@ -50,6 +68,11 @@ public boolean equals(Object arg) {
5068
return false;
5169
}
5270

71+
@Override
72+
public void getMetadata(DSMap bucket) {
73+
bucket.put(DSMetadata.EDITOR, DSMetadata.NUM_EDITOR_INT);
74+
}
75+
5376
@Override
5477
public DSValueType getValueType() {
5578
return DSValueType.NUMBER;

dslink-v2/src/main/java/org/iot/dsa/node/DSLong.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @author Aaron Hansen
77
*/
8-
public class DSLong extends DSElement implements DSINumber {
8+
public class DSLong extends DSElement implements Comparable<DSINumber>, DSIMetadata, DSINumber {
99

1010
// Constants
1111
// ---------
@@ -27,6 +27,24 @@ public class DSLong extends DSElement implements DSINumber {
2727
// Public Methods
2828
// --------------
2929

30+
@Override
31+
public int compareTo(DSINumber arg) {
32+
if ((arg instanceof DSIValue) && (((DSIValue) arg).isNull())) {
33+
return (this == NULL) ? 0 : 1;
34+
}
35+
if (isNull()) {
36+
return -1;
37+
}
38+
if (arg.isLong()) {
39+
return (int) (value = arg.toLong());
40+
} else if (arg.isDouble()) {
41+
return (int) (value - arg.toDouble());
42+
} else if (arg.isFloat()) {
43+
return (int) (value - arg.toFloat());
44+
}
45+
return (int) (value - arg.toInt());
46+
}
47+
3048
/**
3149
* True if the argument is a DSINumber and the values are equal or they are both isNull.
3250
*/
@@ -55,6 +73,11 @@ public DSElementType getElementType() {
5573
return DSElementType.LONG;
5674
}
5775

76+
@Override
77+
public void getMetadata(DSMap bucket) {
78+
bucket.put(DSMetadata.EDITOR, DSMetadata.NUM_EDITOR_INT);
79+
}
80+
5881
@Override
5982
public DSValueType getValueType() {
6083
return DSValueType.NUMBER;

dslink-v2/src/main/java/org/iot/dsa/node/DSMetadata.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@ public class DSMetadata {
1313

1414
public static final String BOOLEAN_RANGE = "booleanRange";
1515
public static final String DESCRIPTION = "description";
16-
public static final String DECIMAL_PLACES = "decimalPlaces";
1716
public static final String DEFAULT = "default";
1817
public static final String DISPLAY_NAME = "displayName";
1918
public static final String EDITOR = "editor";
2019
public static final String ENUM_RANGE = "enumRange";
2120
public static final String NAME = "name";
22-
public static final String MAX_VALUE = "maxValue";
23-
public static final String MIN_VALUE = "minValue";
21+
public static final String MAX = "max";
22+
public static final String MIN = "min";
2423
public static final String PLACEHOLDER = "placeholder";
24+
public static final String PRECISION = "precision";
2525
public static final String TYPE = "type";
2626
public static final String UNIT = "unit";
2727

28-
//public static final String EDITOR_DATE = "date";
29-
//public static final String EDITOR_DATE_RANGE = "daterange";
30-
//public static final String EDITOR_FILE_INPUT = "fileinput";
31-
//public static final String EDITOR_PASSWORD = "password";
32-
//public static final String EDITOR_TEXT_AREA = "textarea";
28+
public static final String NUM_EDITOR_INT = "int";
29+
public static final String NUM_EDITOR_COLOR = "color";
30+
public static final String STR_EDITOR_DATE = "date";
31+
public static final String STR_EDITOR_DATE_RANGE = "daterange";
32+
public static final String STR_EDITOR_FILE_INPUT = "fileinput";
33+
public static final String STR_EDITOR_PASSWORD = "password";
34+
public static final String STR_EDITOR_TEXT_AREA = "textarea";
3335

3436
///////////////////////////////////////////////////////////////////////////
3537
// Fields
@@ -63,10 +65,6 @@ public DSMetadata clear(String key) {
6365
return this;
6466
}
6567

66-
public DSMap getMap() {
67-
return map;
68-
}
69-
7068
/**
7169
* The boolean range, or null. If not null, the length will be 2, index 0 will be the false
7270
* text and index 1 the true text.
@@ -75,13 +73,6 @@ public DSList getBooleanRange() {
7573
return (DSList) map.get(BOOLEAN_RANGE);
7674
}
7775

78-
/**
79-
* The decimal precision or null.
80-
*/
81-
public DSLong getDecimalPlaces() {
82-
return (DSLong) map.get(DECIMAL_PLACES);
83-
}
84-
8576
/**
8677
* The default value for an action parameter, or null.
8778
*/
@@ -117,11 +108,15 @@ public DSList getEnumRange() {
117108
return map.getList(ENUM_RANGE);
118109
}
119110

111+
public DSMap getMap() {
112+
return map;
113+
}
114+
120115
/**
121116
* The max value, or null.
122117
*/
123118
public DSElement getMaxValue() {
124-
return map.get(MAX_VALUE);
119+
return map.get(MAX);
125120
}
126121

127122
/**
@@ -152,7 +147,7 @@ public static DSMap getMetadata(DSInfo info, DSMap bucket) {
152147
* The min value, or null.
153148
*/
154149
public DSElement getMinValue() {
155-
return map.get(MIN_VALUE);
150+
return map.get(MIN);
156151
}
157152

158153
/**
@@ -169,6 +164,13 @@ public String getPlaceHolder() {
169164
return map.getString(PLACEHOLDER);
170165
}
171166

167+
/**
168+
* The decimal precision or null.
169+
*/
170+
public DSLong getPrecision() {
171+
return (DSLong) map.get(PRECISION);
172+
}
173+
172174
/**
173175
* The type for action parameters, can be used to override types in the responder api.
174176
*/
@@ -233,13 +235,6 @@ public DSMetadata setDefault(DSIValue arg) {
233235
return this;
234236
}
235237

236-
public DSMetadata setDecimalPlaces(DSLong arg) {
237-
if (arg != null) {
238-
map.put(DECIMAL_PLACES, arg);
239-
}
240-
return this;
241-
}
242-
243238
public DSMetadata setDescription(String arg) {
244239
if (arg != null) {
245240
map.put(DESCRIPTION, arg);
@@ -298,7 +293,7 @@ public DSMetadata setMap(DSMap arg) {
298293
*/
299294
public DSMetadata setMaxValue(DSElement arg) {
300295
if (arg != null) {
301-
map.put(MIN_VALUE, arg);
296+
map.put(MIN, arg);
302297
}
303298
return this;
304299
}
@@ -308,7 +303,7 @@ public DSMetadata setMaxValue(DSElement arg) {
308303
*/
309304
public DSMetadata setMinValue(DSElement arg) {
310305
if (arg != null) {
311-
map.put(MIN_VALUE, arg);
306+
map.put(MIN, arg);
312307
}
313308
return this;
314309
}
@@ -330,6 +325,13 @@ public DSMetadata setPlaceHolder(String arg) {
330325
return this;
331326
}
332327

328+
public DSMetadata setPrecision(DSLong arg) {
329+
if (arg != null) {
330+
map.put(PRECISION, arg);
331+
}
332+
return this;
333+
}
334+
333335
/**
334336
* Sets the type and if the given is an enum, sets the enum range as well.
335337
*/

dslink-v2/src/main/java/org/iot/dsa/node/DSString.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author Aaron Hansen
99
*/
10-
public class DSString extends DSElement {
10+
public class DSString extends DSElement implements Comparable<Object> {
1111

1212
// Constants
1313
// ---------
@@ -39,6 +39,17 @@ public class DSString extends DSElement {
3939
// Public Methods
4040
// --------------
4141

42+
@Override
43+
public int compareTo(Object arg) {
44+
if ((arg instanceof DSIValue) && (((DSIValue) arg).isNull())) {
45+
return (this == NULL) ? 0 : 1;
46+
}
47+
if (isNull()) {
48+
return -1;
49+
}
50+
return value.compareTo(arg.toString());
51+
}
52+
4253
@Override
4354
public boolean equals(Object o) {
4455
if (o == this) {

0 commit comments

Comments
 (0)