164 lines
3.1 KiB
Java
164 lines
3.1 KiB
Java
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2021, Edouard DUPIN, all right reserved
|
|
* @license MPL v2.0 (see license file)
|
|
*/
|
|
package org.atriasoft.ejson.model;
|
|
|
|
/**
|
|
* Text node interface (internal data between two Marker: <XXX> ALL here </XXX>
|
|
*/
|
|
public class JsonNumber extends JsonNode {
|
|
private Object value;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public JsonNumber() {
|
|
final Long tmp = 0L;
|
|
this.value = tmp;
|
|
};
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final byte _data) {
|
|
super();
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final double _data) {
|
|
super();
|
|
final Double tmp = (double) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final float _data) {
|
|
super();
|
|
final Double tmp = (double) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final int _data) {
|
|
super();
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final long _data) {
|
|
super();
|
|
final Long tmp = _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public JsonNumber(final short _data) {
|
|
super();
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
@Override
|
|
public JsonNodeType getType() {
|
|
return JsonNodeType.Number;
|
|
}
|
|
|
|
public double getValue() {
|
|
if (this.value instanceof Double) {
|
|
return (Double) this.value;
|
|
}
|
|
return (Long) this.value;
|
|
}
|
|
|
|
public long getValueLong() {
|
|
if (this.value instanceof Double) {
|
|
final double val = (Double) this.value;
|
|
return (long) val;
|
|
}
|
|
return (Long) this.value;
|
|
}
|
|
|
|
public boolean isDouble() {
|
|
return this.value instanceof Double;
|
|
}
|
|
|
|
public boolean isLong() {
|
|
return this.value instanceof Long;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final byte _data) {
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final double _data) {
|
|
final Double tmp = (double) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final float _data) {
|
|
final Double tmp = (double) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final int _data) {
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final long _data) {
|
|
final Long tmp = _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
/**
|
|
* Set the value of the Number element
|
|
* @param[in] _data Value of the Number
|
|
*/
|
|
public void setValue(final short _data) {
|
|
final Long tmp = (long) _data;
|
|
this.value = tmp;
|
|
}
|
|
|
|
}; |