public static WikidataValue forItem(int itemId) { JsonObject obj = new JsonObject(); obj.addProperty("entity-type", "item"); obj.addProperty("numeric-id", itemId); return new WikidataValue(Type.ITEM, itemId, obj); }
public static WikidataValue forProperty(int propId) { JsonObject obj = new JsonObject(); obj.addProperty("entity-type", "property"); obj.addProperty("numeric-id", propId); return new WikidataValue(Type.PROPERTY, propId, obj); }
public static WikidataValue forString(String s) { return new WikidataValue(Type.STRING, s, new JsonPrimitive(s)); }
public static WikidataValue forInt(int value) { return new WikidataValue(Type.INT, value, new JsonPrimitive(value)); }
public static WikidataValue forProperty(int propId) { JsonObject obj = new JsonObject(); obj.addProperty("entity-type", "property"); obj.addProperty("numeric-id", propId); return new WikidataValue(Type.PROPERTY, propId, obj); }
public static WikidataValue forInt(int value) { return new WikidataValue(Type.INT, value, new JsonPrimitive(value)); }
public static WikidataValue forItem(int itemId) { JsonObject obj = new JsonObject(); obj.addProperty("entity-type", "item"); obj.addProperty("numeric-id", itemId); return new WikidataValue(Type.ITEM, itemId, obj); }
public static WikidataValue forString(String s) { return new WikidataValue(Type.STRING, s, new JsonPrimitive(s)); }
@Override public WikidataValue visit(GlobeCoordinatesValue value) { return new WikidataValue(type, gsonToPrimitive(jsonValue), jsonValue); }
@Override public WikidataValue visit(QuantityValue value) { return new WikidataValue(type, gsonToPrimitive(jsonValue), jsonValue); }
@Override public WikidataValue visit(GlobeCoordinatesValue value) { return new WikidataValue(type, gsonToPrimitive(jsonValue), jsonValue); }
@Override public WikidataValue visit(QuantityValue value) { return new WikidataValue(type, gsonToPrimitive(jsonValue), jsonValue); }
public WikidataValue jsonToValue(String type, JsonElement element) throws WpParseException { if (type.equals("somevalue")) { return new WikidataValue(WikidataValue.Type.SOMEVALUE, null, JsonNull.INSTANCE); } else if (type.equals("novalue")) { return new WikidataValue(WikidataValue.Type.NOVALUE, null, JsonNull.INSTANCE); } else if (type.equals("item") || type.equals("property")) { type = "wikibase-entityid"; } String fullJson = "{ \"type\" : \"" + type + "\", \"value\" : " + element.toString() + " }"; try { Value snak = mapper.readValue(fullJson, JacksonValue.class); return snakToValue(type, snak); } catch (IOException e) { throw new WpParseException(e); } }
public WikidataValue jsonToValue(String type, JsonElement element) throws WpParseException { if (type.equals("somevalue")) { return new WikidataValue(WikidataValue.Type.SOMEVALUE, null, JsonNull.INSTANCE); } else if (type.equals("novalue")) { return new WikidataValue(WikidataValue.Type.NOVALUE, null, JsonNull.INSTANCE); } else if (type.equals("item") || type.equals("property")) { type = "wikibase-entityid"; } String fullJson = "{ \"type\" : \"" + type + "\", \"value\" : " + element.toString() + " }"; try { Value snak = mapper.readValue(fullJson, JacksonValue.class); return snakToValue(type, snak); } catch (IOException e) { throw new WpParseException(e); } }
@Override public WikidataValue visit(TimeValue value) { Calendar c = new GregorianCalendar( ((int)value.getYear()), value.getMonth()-1, value.getDay(), value.getHour(), value.getMinute(), value.getSecond()); return new WikidataValue( WikidataValue.Type.TIME, c.getTime(), jsonValue ); }
@Override public WikidataValue visit(TimeValue value) { Calendar c = new GregorianCalendar( ((int)value.getYear()), value.getMonth()-1, value.getDay(), value.getHour(), value.getMinute(), value.getSecond()); return new WikidataValue( WikidataValue.Type.TIME, c.getTime(), jsonValue ); }