@Override public boolean equals(Object other) { if(!(other instanceof HollowObjectSchema)) return false; HollowObjectSchema otherSchema = (HollowObjectSchema) other; if(!getName().equals(otherSchema.getName())) return false; if(otherSchema.numFields() != numFields()) return false; if (!isNullableObjectEquals(primaryKey, otherSchema.getPrimaryKey())) return false; for(int i=0;i<numFields();i++) { if(getFieldType(i) != otherSchema.getFieldType(i)) return false; if(!getFieldName(i).equals(otherSchema.getFieldName(i))) return false; } return true; }
public HollowObjectSchema findCommonSchema(HollowObjectSchema otherSchema) { if(!getName().equals(otherSchema.getName())) { throw new IllegalArgumentException("Cannot find common schema of two schemas with different names!"); } int commonFields = 0; for (String fieldName : fieldNames) { if(otherSchema.getPosition(fieldName) != -1) { commonFields++; } } PrimaryKey primaryKey = isNullableObjectEquals(this.primaryKey, otherSchema.getPrimaryKey()) ? this.primaryKey : null; HollowObjectSchema commonSchema = new HollowObjectSchema(getName(), commonFields, primaryKey); for (int i = 0; i < fieldNames.length; i++) { int otherFieldIndex = otherSchema.getPosition(fieldNames[i]); if (otherFieldIndex != -1) { if (fieldTypes[i] != otherSchema.getFieldType(otherFieldIndex) || !referencedTypesEqual(referencedTypes[i], otherSchema.getReferencedType(otherFieldIndex))) { String fieldType = fieldTypes[i] == FieldType.REFERENCE ? referencedTypes[i] : fieldTypes[i].toString().toLowerCase(); String otherFieldType = otherSchema.getFieldType(otherFieldIndex) == FieldType.REFERENCE ? otherSchema.getReferencedType(otherFieldIndex) : otherSchema.getFieldType(otherFieldIndex).toString().toLowerCase(); throw new IncompatibleSchemaException(getName(), fieldNames[i], fieldType, otherFieldType); } commonSchema.addField(fieldNames[i], fieldTypes[i], referencedTypes[i]); } } return commonSchema; }
public HollowObjectSchema findUnionSchema(HollowObjectSchema otherSchema) { if(!getName().equals(otherSchema.getName())) { throw new IllegalArgumentException("Cannot find common schema of two schemas with different names!"); } int totalFields = otherSchema.numFields(); for (String fieldName : fieldNames) { if(otherSchema.getPosition(fieldName) == -1) totalFields++; } PrimaryKey primaryKey = isNullableObjectEquals(this.primaryKey, otherSchema.getPrimaryKey()) ? this.primaryKey : null; HollowObjectSchema unionSchema = new HollowObjectSchema(getName(), totalFields, primaryKey); for(int i=0;i<fieldNames.length;i++) { unionSchema.addField(fieldNames[i], fieldTypes[i], referencedTypes[i]); } for(int i=0;i<otherSchema.numFields();i++) { if(getPosition(otherSchema.getFieldName(i)) == -1) { unionSchema.addField(otherSchema.getFieldName(i), otherSchema.getFieldType(i), otherSchema.getReferencedType(i)); } } return unionSchema; }