public <K extends HollowRecord, V extends HollowRecord> Iterable<Map.Entry<K, V>>entries() { return new GenericHollowMapEntryIterable<K, V>(entrySet()); }
@Override public HollowRecord instantiateKey(int keyOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getKeyType(), keyOrdinal); }
@Test public void testCompletelyMissingMap() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowMap map = (GenericHollowMap) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingMap", 0); Assert.assertEquals(2, map.size()); Assert.assertTrue(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertEquals(300, map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 3)).getOrdinal()); Assert.assertFalse(map.containsKey(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Assert.assertNull(map.get(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 4))); Iterator<Map.Entry<HollowRecord, HollowRecord>> rec = map.entrySet().iterator(); Assert.assertTrue(rec.hasNext()); Map.Entry<HollowRecord, HollowRecord> next = rec.next(); Assert.assertEquals(2, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(200, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getKey().getOrdinal()); Assert.assertEquals("MissingObject", next.getKey().getSchema().getName()); Assert.assertEquals(300, next.getValue().getOrdinal()); Assert.assertEquals("MissingObject", next.getValue().getSchema().getName()); Assert.assertEquals(300, map.get(next.getKey()).getOrdinal()); Assert.assertEquals("MissingObject", map.get(next.getKey()).getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
GenericHollowObject key = (GenericHollowObject) obj.getMap("mapById").findKey(1); Assert.assertEquals("US", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(2); Assert.assertEquals("CA", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(3); Assert.assertEquals("IT", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(4); Assert.assertEquals("GB", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(5); Assert.assertEquals("IT", key.getObject("country").getString("value")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(1, "US"); Assert.assertEquals(1, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(2, "CA"); Assert.assertEquals(2, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(3, "IT"); Assert.assertEquals(3, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(4, "GB"); Assert.assertEquals(4, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(5, "IT"); Assert.assertEquals(5, key.getInt("id")); key = (GenericHollowObject) obj.getMap("mapByIdCityCountry").findKey(1, "New York", "US"); Assert.assertEquals(1, key.getInt("id")); key = (GenericHollowObject) obj.getMap("mapByIdCityCountry").findKey(2, "Ottawa", "CA"); Assert.assertEquals(2, key.getInt("id")); key = (GenericHollowObject) obj.getMap("mapByIdCityCountry").findKey(3, "Rome", "IT"); Assert.assertEquals(3, key.getInt("id")); key = (GenericHollowObject) obj.getMap("mapByIdCityCountry").findKey(4, "London", "GB");
@Test public void testLookupOfLongKey() throws IOException { HollowWriteStateEngine writeEngine = new HollowWriteStateEngine(); HollowObjectMapper mapper = new HollowObjectMapper(writeEngine); mapper.initializeTypeState(TypeWithLongMap.class); TypeWithLongMap top = new TypeWithLongMap(); long longValue = (long)Integer.MAX_VALUE+1; top.longMap.put(longValue, 100L); mapper.add(top); HollowReadStateEngine readEngine = StateEngineRoundTripper.roundTripSnapshot(writeEngine); GenericHollowMap map = new GenericHollowMap(readEngine, "MapOfLongToLong", 0); GenericHollowObject value = new GenericHollowObject(readEngine, "Long", map.findValue(longValue).getOrdinal()); Assert.assertEquals(100L, value.getLong("value")); }
public static HollowRecord instantiate(HollowDataAccess dataAccess, String typeName, int ordinal) { HollowTypeDataAccess typeState = dataAccess.getTypeDataAccess(typeName, ordinal); if(typeState != null) { if(typeState instanceof HollowObjectTypeDataAccess) return new GenericHollowObject(new HollowObjectGenericDelegate((HollowObjectTypeDataAccess)typeState), ordinal); if(typeState instanceof HollowListTypeDataAccess) return new GenericHollowList(new HollowListLookupDelegate<HollowRecord>((HollowListTypeDataAccess)typeState), ordinal); if(typeState instanceof HollowSetTypeDataAccess) return new GenericHollowSet(new HollowSetLookupDelegate<HollowRecord>((HollowSetTypeDataAccess)typeState), ordinal); if(typeState instanceof HollowMapTypeDataAccess) return new GenericHollowMap(new HollowMapLookupDelegate<HollowRecord, HollowRecord>((HollowMapTypeDataAccess)typeState), ordinal); } else { HollowSchema schema = dataAccess.getMissingDataHandler().handleSchema(typeName); if(schema instanceof HollowObjectSchema) return new GenericHollowObject(new HollowObjectGenericDelegate(new HollowObjectMissingDataAccess(dataAccess, typeName)), ordinal); if(schema instanceof HollowListSchema) return new GenericHollowList(new HollowListLookupDelegate<HollowRecord>(new HollowListMissingDataAccess(dataAccess, typeName)), ordinal); if(schema instanceof HollowSetSchema) return new GenericHollowSet(new HollowSetLookupDelegate<HollowRecord>(new HollowSetMissingDataAccess(dataAccess, typeName)), ordinal); if(schema instanceof HollowMapSchema) return new GenericHollowMap(new HollowMapLookupDelegate<HollowRecord, HollowRecord>(new HollowMapMissingDataAccess(dataAccess, typeName)), ordinal); } throw new UnsupportedOperationException("I don't know how to instantiate a generic object given a " + typeState.getClass().getSimpleName()); }
@Override public boolean equalsKey(int keyOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getKeyType(), keyOrdinal, testObject); }
GenericHollowObject key = (GenericHollowObject) obj.getMap("mapById").findKey(1); Assert.assertEquals("US", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(2); Assert.assertEquals("CA", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(3); Assert.assertEquals("IT", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(4); Assert.assertEquals("GB", key.getObject("country").getString("value")); key = (GenericHollowObject) obj.getMap("mapById").findKey(5); Assert.assertEquals("IT", key.getObject("country").getString("value")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(1, "US"); Assert.assertEquals(1, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(2, "CA"); Assert.assertEquals(2, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(3, "IT"); Assert.assertEquals(3, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(4, "GB"); Assert.assertEquals(4, key.getInt("id")); key = (GenericHollowObject)obj.getMap("mapByIdCountry").findKey(5, "IT"); Assert.assertEquals(5, key.getInt("id")); GenericHollowObject value = (GenericHollowObject) obj.getMap("mapById").findValue(1); Assert.assertEquals(100, value.getInt("value")); value = (GenericHollowObject) obj.getMap("mapById").findValue(2); Assert.assertEquals(200, value.getInt("value")); value = (GenericHollowObject) obj.getMap("mapById").findValue(3); Assert.assertEquals(300, value.getInt("value")); value = (GenericHollowObject) obj.getMap("mapById").findValue(4);
@Override public boolean equalsValue(int valueOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getValueType(), valueOrdinal, testObject); }
@Override public HollowRecord instantiateValue(int valueOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getValueType(), valueOrdinal); }