本文整理匯總了Java中javax.json.JsonNumber.isIntegral方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNumber.isIntegral方法的具體用法?Java JsonNumber.isIntegral怎麽用?Java JsonNumber.isIntegral使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.json.JsonNumber
的用法示例。
在下文中一共展示了JsonNumber.isIntegral方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toJavaObject
import javax.json.JsonNumber; //導入方法依賴的package包/類
/**
* Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link
* JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link
* #toJavaList}, respectively.
*/
@Nullable
public static Object toJavaObject(JsonValue value) {
switch (value.getValueType()) {
case ARRAY:
return toJavaList((JsonArray) value);
case FALSE:
return Boolean.FALSE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.intValue() : number.doubleValue();
case OBJECT:
return toJavaMap((JsonObject) value);
case STRING:
return ((JsonString) value).getString();
case TRUE:
return Boolean.TRUE;
default:
throw new VerifyException("Json value with unknown type: " + value);
}
}
示例2: unbox
import javax.json.JsonNumber; //導入方法依賴的package包/類
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException {
switch (value.getValueType()) {
case ARRAY:
case OBJECT:
return convert.apply((JsonStructure) value);
case FALSE:
return Boolean.FALSE;
case TRUE:
return Boolean.TRUE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.longValue() : number.doubleValue();
case STRING:
return ((JsonString) value).getString();
default:
throw new JsonException("Unknow value type");
}
}
示例3: verifyInjectedCustomInteger
import javax.json.JsonNumber; //導入方法依賴的package包/類
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
boolean pass = false;
String msg;
// iat
Object test = customInteger.get();
System.out.printf("+++ verifyInjectedCustomInteger, JsonNumber.class.CL: %s\n",
JsonNumber.class.getClassLoader());
System.out.printf("+++ customInteger.CL: %s\n",
test.getClass().getClassLoader());
Class[] ifaces = test.getClass().getInterfaces();
for(Class iface : ifaces) {
System.out.printf("%s: %s\n", iface, iface.getClassLoader());
}
JsonNumber customValue = JsonNumber.class.cast(test);
if(customValue == null || customValue.isIntegral() == false) {
msg = "customInteger value is null or not integral, FAIL";
}
else if(customValue.longValueExact() == value) {
msg = "customInteger PASS";
pass = true;
}
else {
msg = String.format("customInteger: %d != %d", customValue, value);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例4: verifyInjectedCustomInteger
import javax.json.JsonNumber; //導入方法依賴的package包/類
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
boolean pass = false;
String msg;
// iat
Object test = customInteger.getValue();
System.out.printf("+++ verifyInjectedCustomInteger, JsonNumber.class.CL: %s\n",
JsonNumber.class.getClassLoader());
System.out.printf("+++ customInteger.CL: %s\n",
test.getClass().getClassLoader());
Class[] ifaces = test.getClass().getInterfaces();
for(Class iface : ifaces) {
System.out.printf("%s: %s\n", iface, iface.getClassLoader());
}
JsonNumber customValue = JsonNumber.class.cast(test);
if(customValue == null || customValue.isIntegral() == false) {
msg = "customInteger value is null or not integral, FAIL";
}
else if(customValue.longValueExact() == value) {
msg = "customInteger PASS";
pass = true;
}
else {
msg = String.format("customInteger: %d != %d", customValue, value);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例5: equals
import javax.json.JsonNumber; //導入方法依賴的package包/類
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof JsonNumber)) {
return false;
}
JsonNumber other = (JsonNumber)obj;
if (other.isIntegral()) {
return value == other.longValue();
} else {
return false;
}
}