private boolean isDefinedHashCode(HollowSchema schema) { if(schema instanceof HollowSetSchema) return typeNamesWithDefinedHashCodes.contains(((HollowSetSchema)schema).getElementType()); if(schema instanceof HollowMapSchema) return typeNamesWithDefinedHashCodes.contains(((HollowMapSchema)schema).getKeyType()); return false; }
public HollowDiffMapCountingNode(HollowDiff diff, HollowTypeDiff topLevelTypeDiff, HollowDiffNodeIdentifier nodeId, HollowMapTypeReadState fromState, HollowMapTypeReadState toState) { super(diff, topLevelTypeDiff, nodeId); this.fromState = fromState; this.toState = toState; HollowTypeReadState keyFromState = fromState == null ? null : fromState.getSchema().getKeyTypeState(); HollowTypeReadState keyToState = toState == null ? null : toState.getSchema().getKeyTypeState(); this.keyNode = getHollowDiffCountingNode(keyFromState, keyToState, "key"); HollowTypeReadState valueFromState = fromState == null ? null : fromState.getSchema().getValueTypeState(); HollowTypeReadState valueToState = toState == null ? null : toState.getSchema().getValueTypeState(); this.valueNode = getHollowDiffCountingNode(valueFromState, valueToState, "value"); String keyType = fromState != null ? fromState.getSchema().getKeyType() : toState.getSchema().getKeyType(); String valueType = fromState != null ? fromState.getSchema().getValueType() : toState.getSchema().getValueType(); this.keyFilter = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(keyType)); this.valueFilter = new DiffEqualOrdinalFilter(equalityMapping.getEqualOrdinalMap(valueType)); this.keyRequiresTraversalForMissingFields = equalityMapping.requiresMissingFieldTraversal(keyType); this.valueRequiresTraversalForMissingFields = equalityMapping.requiresMissingFieldTraversal(valueType); }
public HollowMapJavaGenerator(String packageName, String apiClassname, HollowMapSchema schema, HollowDataset dataset, Set<String> parameterizedTypes, boolean parameterizeClassNames, CodeGeneratorConfig config) { super(packageName, apiClassname, schema, dataset, config); this.schema = schema; this.keyClassName = hollowImplClassname(schema.getKeyType()); this.valueClassName = hollowImplClassname(schema.getValueType()); this.parameterizeKey = parameterizeClassNames || parameterizedTypes.contains(schema.getKeyType()); this.parameterizeValue = parameterizeClassNames || parameterizedTypes.contains(schema.getValueType()); }
@Override public boolean equalsKey(int keyOrdinal, Object testObject) { return GenericHollowRecordHelper.equalObject(getSchema().getKeyType(), keyOrdinal, testObject); }
@Override public boolean equals(Object other) { if(!(other instanceof HollowMapSchema)) return false; HollowMapSchema otherSchema = (HollowMapSchema)other; if(!getName().equals(otherSchema.getName())) return false; if(!getKeyType().equals(otherSchema.getKeyType())) return false; if(!getValueType().equals(otherSchema.getValueType())) return false; return isNullableObjectEquals(hashKey, otherSchema.getHashKey()); }
private boolean shouldPreserveHashPositions(HollowSchema schema) { switch(schema.getSchemaType()) { case MAP: return from.getTypesWithDefinedHashCodes().contains(((HollowMapSchema)schema).getKeyType()); case SET: return from.getTypesWithDefinedHashCodes().contains(((HollowSetSchema)schema).getElementType()); default: return false; } }
public static Collection<HollowSchema> convertDiscoveredSchemas(Collection<HollowDiscoveredSchema> discoveredSchemas) { Map<String, HollowSchema> schemaMap = new HashMap<String, HollowSchema>(); for(HollowDiscoveredSchema discoveredSchema : discoveredSchemas) { HollowSchema schema = discoveredSchema.toHollowSchema(); schemaMap.put(schema.getName(), schema); if(schema instanceof HollowMapSchema) { String keyType = ((HollowMapSchema)schema).getKeyType(); if(!schemaMap.containsKey(keyType)) schemaMap.put(keyType, getStringSchema(keyType)); } else if(referencesGenericStringSchema(schema)) { if(!schemaMap.containsKey("String")) schemaMap.put("String", getStringSchema("String")); } } return schemaMap.values(); }
private boolean shouldPreserveHashPositions(HollowSchema schema) { switch(schema.getSchemaType()) { case MAP: return readEngine.getTypesWithDefinedHashCodes().contains(((HollowMapSchema)schema).getKeyType()); case SET: return readEngine.getTypesWithDefinedHashCodes().contains(((HollowSetSchema)schema).getElementType()); default: return false; } }
private boolean isDefinedHashCode(HollowTypeReadState typeState) { if(typeState instanceof HollowSetTypeReadState) return input.getTypesWithDefinedHashCodes().contains(((HollowSetSchema)typeState.getSchema()).getElementType()); if(typeState instanceof HollowMapTypeReadState) return input.getTypesWithDefinedHashCodes().contains(((HollowMapSchema)typeState.getSchema()).getKeyType()); return false; }
public DiffEqualityMapMapper(DiffEqualityMapping mapping, HollowMapTypeReadState fromState, HollowMapTypeReadState toState, boolean oneToOne) { super(fromState, toState, oneToOne); HollowMapSchema schema = fromState.getSchema(); this.keyEqualOrdinalMap = mapping.getEqualOrdinalMap(schema.getKeyType()); this.valueEqualOrdinalMap = mapping.getEqualOrdinalMap(schema.getValueType()); this.requiresTraversalForMissingFields = mapping.requiresMissingFieldTraversal(schema.getKeyType()) || mapping.requiresMissingFieldTraversal(schema.getValueType()); }
@Override public HollowRecord instantiateKey(int keyOrdinal) { return GenericHollowRecordHelper.instantiate(getTypeDataAccess().getDataAccess(), getSchema().getKeyType(), keyOrdinal); }
private String getKeyFieldType(String fieldPath) { try { HollowObjectSchema keySchema = (HollowObjectSchema)dataset.getSchema(schema.getKeyType()); String fieldPathElements[] = fieldPath.split("\\."); int idx = 0; while(idx < fieldPathElements.length-1) { keySchema = (HollowObjectSchema)dataset.getSchema(keySchema.getReferencedType(fieldPathElements[idx])); idx++; } FieldType fieldType = keySchema.getFieldType(keySchema.getPosition(fieldPathElements[idx])); return HollowCodeGenerationUtils.getJavaBoxedType(fieldType); } catch(Throwable th) { } throw new IllegalArgumentException("Field path '" + fieldPath + "' specified incorrectly for type: " + schema.getName()); }
private static void addTransitiveMatches(HollowReadStateEngine stateEngine, HollowMapTypeReadState typeState, Map<String, BitSet> matches) { HollowMapSchema schema = typeState.getSchema(); BitSet matchingOrdinals = getOrCreateBitSet(matches, schema.getName(), typeState.maxOrdinal()); HollowTypeReadState keyTypeState = stateEngine.getTypeState(schema.getKeyType()); HollowTypeReadState valueTypeState = stateEngine.getTypeState(schema.getValueType()); BitSet keyOrdinals = getOrCreateBitSet(matches, schema.getKeyType(), keyTypeState.maxOrdinal()); BitSet valueOrdinals = getOrCreateBitSet(matches, schema.getValueType(), valueTypeState.maxOrdinal()); int ordinal = matchingOrdinals.nextSetBit(0); while(ordinal != -1) { HollowMapEntryOrdinalIterator iter = typeState.ordinalIterator(ordinal); while(iter.next()) { keyOrdinals.set(iter.getKey()); valueOrdinals.set(iter.getValue()); } ordinal = matchingOrdinals.nextSetBit(ordinal + 1); } }
private HollowTypeDataAccess getChildDataAccess(HollowTypeDataAccess typeDataAccess, String childName) { if(typeDataAccess instanceof HollowObjectTypeDataAccess) { HollowObjectSchema schema = (HollowObjectSchema) typeDataAccess.getSchema(); int fieldIdx = schema.getPosition(childName); String childType = schema.getReferencedType(fieldIdx); return dataAccess.getTypeDataAccess(childType); } else if(typeDataAccess instanceof HollowCollectionTypeDataAccess) { HollowCollectionSchema schema = (HollowCollectionSchema) typeDataAccess.getSchema(); return dataAccess.getTypeDataAccess(schema.getElementType()); } else if(typeDataAccess instanceof HollowMapTypeDataAccess) { HollowMapSchema schema = (HollowMapSchema) typeDataAccess.getSchema(); String childType = "key".equals(childName) ? schema.getKeyType() : schema.getValueType(); return dataAccess.getTypeDataAccess(childType); } throw new IllegalArgumentException("I can't create a child node for a " + typeDataAccess.getClass()); }
private List<Field> createMapFields(HollowEffigy effigy) { List<Field> fields = new ArrayList<Field>(); HollowMapTypeDataAccess typeDataAccess = (HollowMapTypeDataAccess)effigy.dataAccess; HollowMapSchema schema = typeDataAccess.getSchema(); HollowMapEntryOrdinalIterator iter = typeDataAccess.ordinalIterator(effigy.ordinal); while(iter.next()) { HollowEffigy entryEffigy = new HollowEffigy("Map.Entry"); entryEffigy.add(new Field("key", effigy(typeDataAccess.getDataAccess(), schema.getKeyType(), iter.getKey()))); entryEffigy.add(new Field("value", effigy(typeDataAccess.getDataAccess(), schema.getValueType(), iter.getValue()))); fields.add(new Field("entry", "Map.Entry", entryEffigy)); } return fields; }
public static HollowSchema withoutKeys(HollowSchema schema) { switch(schema.getSchemaType()) { case SET: HollowSetSchema setSchema = (HollowSetSchema)schema; if(setSchema.getHashKey() != null) setSchema = new HollowSetSchema(setSchema.getName(), setSchema.getElementType()); return setSchema; case MAP: HollowMapSchema mapSchema = (HollowMapSchema)schema; if(mapSchema.getHashKey() != null) mapSchema = new HollowMapSchema(mapSchema.getName(), mapSchema.getKeyType(), mapSchema.getValueType()); return mapSchema; default: return schema; } }
@Override public HollowWriteRecord copy(int ordinal) { HollowMapWriteRecord rec = rec(); rec.reset(); HollowMapEntryOrdinalIterator iter = readState().ordinalIterator(ordinal); String keyType = readState().getSchema().getKeyType(); String valueType = readState().getSchema().getValueType(); while(iter.next()) { int remappedKeyOrdinal = ordinalRemapper.getMappedOrdinal(keyType, iter.getKey()); int remappedValueOrdinal = ordinalRemapper.getMappedOrdinal(valueType, iter.getValue()); int hashCode = preserveHashPositions ? ((HollowMapEntryOrdinalIteratorImpl)iter).getCurrentBucket() : remappedKeyOrdinal; rec.addEntry(remappedKeyOrdinal, remappedValueOrdinal, hashCode); } return rec; }
@Test public void parsesMapSchema() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA>;\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesMapSchemaWithPrimaryKey() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(value);\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(new PrimaryKey("String", "value"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesMapSchemaWithMultiFieldPrimaryKey() throws IOException { String listSchema = "MapOfStringToTypeA Map<String, TypeA> @HashKey(id.value, region.country.id, key);\n"; HollowMapSchema schema = (HollowMapSchema) HollowSchemaParser.parseSchema(listSchema); Assert.assertEquals("MapOfStringToTypeA", schema.getName()); Assert.assertEquals("String", schema.getKeyType()); Assert.assertEquals("TypeA", schema.getValueType()); Assert.assertEquals(new PrimaryKey("String", "id.value", "region.country.id", "key"), schema.getHashKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }