public static Type getByCode(char code) { code = Character.toUpperCase(code); for (Type type : values()) { if (type.code == code) { return type; } } throw new IllegalArgumentException("Unknown type code: " + code); } }
protected WikidataStatement buildStatement(Record record) throws DaoException { if (record == null) { return null; } WikidataEntity item = new WikidataEntity( WikidataEntity.Type.getByCode(record.getValue(Tables.WIKIDATA_STATEMENT.ENTITY_TYPE).charAt(0)), record.getValue(Tables.WIKIDATA_STATEMENT.ENTITY_ID) ); WikidataEntity prop = getProperty(record.getValue(Tables.WIKIDATA_STATEMENT.PROP_ID)); Short rankOrdinal = record.getValue(Tables.WIKIDATA_STATEMENT.RANK); JsonElement json = new JsonParser().parse(record.getValue(Tables.WIKIDATA_STATEMENT.VAL_STR)); WikidataValue val; try { val = parser.jsonToValue( record.getValue(Tables.WIKIDATA_STATEMENT.VAL_TYPE), json); } catch (WpParseException e) { throw new DaoException(e); } WikidataStatement stmt = new WikidataStatement( record.getValue(Tables.WIKIDATA_STATEMENT.ID), item, prop, val, WikidataStatement.Rank.values()[rankOrdinal] ); return stmt; }
protected WikidataStatement buildStatement(Record record) throws DaoException { if (record == null) { return null; } WikidataEntity item = new WikidataEntity( WikidataEntity.Type.getByCode(record.getValue(Tables.WIKIDATA_STATEMENT.ENTITY_TYPE).charAt(0)), record.getValue(Tables.WIKIDATA_STATEMENT.ENTITY_ID) ); WikidataEntity prop = getProperty(record.getValue(Tables.WIKIDATA_STATEMENT.PROP_ID)); Short rankOrdinal = record.getValue(Tables.WIKIDATA_STATEMENT.RANK); JsonElement json = new JsonParser().parse(record.getValue(Tables.WIKIDATA_STATEMENT.VAL_STR)); WikidataValue val; try { val = parser.jsonToValue( record.getValue(Tables.WIKIDATA_STATEMENT.VAL_TYPE), json); } catch (WpParseException e) { throw new DaoException(e); } WikidataStatement stmt = new WikidataStatement( record.getValue(Tables.WIKIDATA_STATEMENT.ID), item, prop, val, WikidataStatement.Rank.values()[rankOrdinal] ); return stmt; }
@Override public int hashCode() { return type.hashCode() + 37 * id; }
@Override public int hashCode() { return type.hashCode() + 37 * id; }
public static Type getByCode(char code) { code = Character.toUpperCase(code); for (Type type : values()) { if (type.code == code) { return type; } } throw new IllegalArgumentException("Unknown type code: " + code); } }