Object o = id.getAsShort(); return (T) o;
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
public static Short getShortFromJson(JsonElement value) { if (value.isJsonNull()) { return null; } return value.getAsShort(); }
public short getShort(String key) { if (!dataCatcher.has(key)) return 0; return dataCatcher.get(key).getAsShort(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
/** * convenience method to get this array as a primitive short if it contains a single element. * * @return get this element as a primitive short if it is single element array. * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and * is not a valid short. * @throws IllegalStateException if the array has more than one element. */ @Override public short getAsShort() { if (elements.size() == 1) { return elements.get(0).getAsShort(); } throw new IllegalStateException(); }
private static ObjectId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json instanceof JsonObject) { JsonObject jo = (JsonObject) json; return new ObjectId(jo.get("timestamp").getAsInt(), jo.get("machineIdentifier").getAsInt(), jo.get("processIdentifier").getAsShort(), jo.get("counter").getAsInt()); } return new ObjectId(json.getAsString()); }
@Override public void shortProperty(PropertyName name, JsonObject context) throws IOException { JsonElement prop = property(context, name); if (prop == null) { return; } builder.add(name, prop.getAsShort()); }
public Short deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return json.getAsShort(); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } catch (UnsupportedOperationException e) { throw new JsonSyntaxException(e); } catch (IllegalStateException e) { throw new JsonSyntaxException(e); } }
return (T) (Byte) input.getAsByte(); } else if (expected == short.class || expected == Short.class) { return (T) (Short) input.getAsShort(); } else if (expected == int.class || expected == Integer.class) { return (T) (Integer) input.getAsInt();
Object o = id.getAsShort(); return (T) o;
return (T) (Byte) input.getAsByte(); } else if (expected == short.class || expected == Short.class) { return (T) (Short) input.getAsShort(); } else if (expected == int.class || expected == Integer.class) { return (T) (Integer) input.getAsInt();
break; case SHORT: pack.putShort(key, elementValue.getAsShort()); break; case BYTE:
@Test public void testRuleSerialization() { Condition one = new OrCondition(Arrays.asList((Condition) new EqualsCondition("header1", "val1"), (Condition) new JavaRegexCondition("header", "\\d+"))); Condition two = new EqualsCondition("header2", "val2"); Condition condition = new AndCondition(Arrays.asList(one, two)); Action action = new TemplatedAlertAction((short) 2, (short) 2); SimpleRule rule = new SimpleRule((short) 123, "hello", true, condition, action); String jsonRule = RuleSerializer.serializeRuleToJSONString(rule, false); JsonObject object = new Gson().fromJson(jsonRule, JsonObject.class); assertEquals(123, object.get("ruleId").getAsShort()); assertEquals("hello", object.get("name").getAsString()); JsonObject actionArray = object.get("actions").getAsJsonArray().get(0).getAsJsonObject(); assertEquals(Utils.CLASSNAME_FORWARD_MAP.get(TemplatedAlertAction.class.getCanonicalName()), actionArray.get("type").getAsString()); }
@Test public void testValueOfNumber() { JsonObject joShort = JsonFunctions.valueOfNumber("propName").apply(Short.MAX_VALUE); assertEquals(Short.MAX_VALUE, joShort.get("propName").getAsShort()); JsonObject joInt = JsonFunctions.valueOfNumber("propName").apply(Integer.MAX_VALUE); assertEquals(Integer.MAX_VALUE, joInt.get("propName").getAsInt()); JsonObject joLong = JsonFunctions.valueOfNumber("propName").apply(Long.MAX_VALUE); assertEquals(Long.MAX_VALUE, joLong.get("propName").getAsLong()); JsonObject joFloat = JsonFunctions.valueOfNumber("propName").apply(Float.MAX_VALUE); assertEquals(Float.MAX_VALUE, joFloat.get("propName").getAsFloat(), 0.0f); JsonObject joDouble = JsonFunctions.valueOfNumber("propName").apply(Double.MAX_VALUE); assertEquals(Double.MAX_VALUE, joDouble.get("propName").getAsDouble(), 0.0d); }