|
|
@ -19,4 +19,44 @@ public class KingIODataItemEntity { |
|
|
this.timestamp = formattedTimestamp; |
|
|
this.timestamp = formattedTimestamp; |
|
|
this.quality = s; |
|
|
this.quality = s; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 自定义的 getter 方法,根据原始 value 的类型返回预处理后的值。 |
|
|
|
|
|
* 注意:这里返回 Float 而不是 float,因为 Object 不能持有原始类型。 |
|
|
|
|
|
*/ |
|
|
|
|
|
public Object getValue() { |
|
|
|
|
|
if (this.value instanceof Number) { // 检查是否为数字类型
|
|
|
|
|
|
Number num = (Number) this.value; |
|
|
|
|
|
// 检查是否为整数类型 (Integer, Long, Short, Byte)
|
|
|
|
|
|
if (this.value instanceof Integer || |
|
|
|
|
|
this.value instanceof Long || |
|
|
|
|
|
this.value instanceof Short || |
|
|
|
|
|
this.value instanceof Byte) { |
|
|
|
|
|
// 返回 Integer (intValue() 返回 int,自动装箱为 Integer)
|
|
|
|
|
|
// 如果 value 本身就是 Integer,直接返回即可
|
|
|
|
|
|
if (this.value instanceof Integer) { |
|
|
|
|
|
return this.value; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果是 Long, Short, Byte,转换为 Integer
|
|
|
|
|
|
return num.intValue(); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 其他数字类型 (Double, Float 等) 视为小数
|
|
|
|
|
|
// 你要求返回 float,所以即使是 Double 也转换为 float
|
|
|
|
|
|
// 注意:从 Double 转换为 Float 可能会有精度损失
|
|
|
|
|
|
if (this.value instanceof Float) { |
|
|
|
|
|
return this.value; // 如果 value 本身就是 Float,直接返回
|
|
|
|
|
|
} else { |
|
|
|
|
|
return num.floatValue(); // 返回 Float (如从 Double 转换)
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else if (this.value instanceof String) { |
|
|
|
|
|
return this.value; // 如果是 String,直接返回
|
|
|
|
|
|
} else if (this.value instanceof Boolean) { |
|
|
|
|
|
return this.value; // 如果是 Boolean,直接返回
|
|
|
|
|
|
} |
|
|
|
|
|
// 如果是其他类型(如 Character 等),也可以按需处理
|
|
|
|
|
|
// 或者保持原样返回
|
|
|
|
|
|
return this.value; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|