private boolean setOrderingExists(HollowSetTypeReadState bTypeState, String... orderedCValues) { for(int i=0;i<=bTypeState.maxOrdinal();i++) { GenericHollowSet set = new GenericHollowSet(bTypeState, i); Iterator<HollowRecord> iter = set.iterator(); for(int j=0;j<orderedCValues.length;j++) { if(!iter.hasNext()) break; HollowObject obj = (HollowObject)iter.next(); String cValue = obj.getString("c1"); if(!cValue.equals(orderedCValues[j])) break; if(j == (orderedCValues.length - 1)) return true; } } return false; }
@Override public HollowRecord instantiateElement(int elementOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getElementType(), elementOrdinal); }
@Test public void testCompletelyMissingSet() throws IOException { roundTripSnapshot(); readStateEngine.setMissingDataHandler(new FakeMissingDataHandler()); GenericHollowSet set = (GenericHollowSet) GenericHollowRecordHelper.instantiate(readStateEngine, "MissingSet", 0); Assert.assertEquals(2, set.size()); Assert.assertTrue(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 2))); Assert.assertFalse(set.contains(new FakeMissingHollowRecord(new HollowObjectMissingDataAccess(readStateEngine, "MissingObject"), 0))); Iterator<HollowRecord> rec = set.iterator(); Assert.assertTrue(rec.hasNext()); HollowRecord next = rec.next(); Assert.assertEquals(2, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertTrue(rec.hasNext()); next = rec.next(); Assert.assertEquals(3, next.getOrdinal()); Assert.assertEquals("MissingObject", next.getSchema().getName()); Assert.assertFalse(rec.hasNext()); }
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()); }
Assert.assertEquals("two", typeA0.getString("a2")); Assert.assertEquals("three", typeA0.getObject("a3").getString("b1")); Assert.assertEquals(2, typeA0.getSet("a4").size()); Assert.assertTrue(typeA0.getSet("a4").findElement("four") != null); Assert.assertTrue(typeA0.getSet("a4").findElement("five") != null); Assert.assertEquals(4, typeA1.getSet("a4").size()); Assert.assertTrue(typeA1.getSet("a4").findElement("six") != null); Assert.assertTrue(typeA1.getSet("a4").findElement("eight") != null); Assert.assertTrue(typeA1.getSet("a4").findElement("é with acute accent") != null); Assert.assertTrue(typeA1.getSet("a4").findElement("ten") != null); Assert.assertEquals("four", typeC0.getObject("c2").getString("b1")); Assert.assertEquals(typeC0.getObject("c2").getOrdinal(), typeA0.getSet("a4").findElement("four").getOrdinal());
GenericHollowObject element = (GenericHollowObject) obj.getSet("setById").findElement(1); Assert.assertEquals("US", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(2); Assert.assertEquals("CA", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(3); Assert.assertEquals("IT", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(4); Assert.assertEquals("GB", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(5); Assert.assertEquals("IT", element.getObject("country").getString("value")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(1, "US"); Assert.assertEquals(1, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(2, "CA"); Assert.assertEquals(2, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(3, "IT"); Assert.assertEquals(3, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(4, "GB"); Assert.assertEquals(4, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(5, "IT"); Assert.assertEquals(5, element.getInt("id")); element = (GenericHollowObject)obj.getSet("intSet").findElement(100); Assert.assertEquals(100, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(200); Assert.assertEquals(200, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(300); Assert.assertEquals(300, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(400);
@Override public boolean equalsElement(int elementOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getElementType(), elementOrdinal, testObject); }
GenericHollowObject element = (GenericHollowObject) obj.getSet("setById").findElement(1); Assert.assertEquals("US", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(2); Assert.assertEquals("CA", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(3); Assert.assertEquals("IT", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(4); Assert.assertEquals("GB", element.getObject("country").getString("value")); element = (GenericHollowObject) obj.getSet("setById").findElement(5); Assert.assertEquals("IT", element.getObject("country").getString("value")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(1, "US"); Assert.assertEquals(1, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(2, "CA"); Assert.assertEquals(2, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(3, "IT"); Assert.assertEquals(3, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(4, "GB"); Assert.assertEquals(4, element.getInt("id")); element = (GenericHollowObject)obj.getSet("setByIdCountry").findElement(5, "IT"); Assert.assertEquals(5, element.getInt("id")); element = (GenericHollowObject)obj.getSet("intSet").findElement(100); Assert.assertEquals(100, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(200); Assert.assertEquals(200, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(300); Assert.assertEquals(300, element.getInt("value")); element = (GenericHollowObject)obj.getSet("intSet").findElement(400);