public static boolean typeIsTransitivelyDependent(HollowStateEngine stateEngine, String dependentType, String dependencyType) {
        if(dependentType.equals(dependencyType))
            return true;
        
        HollowSchema dependentTypeSchema = stateEngine.getSchema(dependentType);
        
        if(dependentTypeSchema == null)
            return false;
            
        switch(dependentTypeSchema.getSchemaType()) {
        case OBJECT:
            HollowObjectSchema objectSchema = (HollowObjectSchema)dependentTypeSchema;
            
            for(int i=0;i<objectSchema.numFields();i++) {
                if(objectSchema.getFieldType(i) == FieldType.REFERENCE) {
                    if(typeIsTransitivelyDependent(stateEngine, objectSchema.getReferencedType(i), dependencyType))
                        return true;
                }
            }
            
            break;
        case LIST:
        case SET:
            return typeIsTransitivelyDependent(stateEngine, ((HollowCollectionSchema)dependentTypeSchema).getElementType(), dependencyType);
        case MAP:
            return typeIsTransitivelyDependent(stateEngine, ((HollowMapSchema)dependentTypeSchema).getKeyType(), dependencyType) 
                    || typeIsTransitivelyDependent(stateEngine, ((HollowMapSchema)dependentTypeSchema).getValueType(), dependencyType);
        }
        
        return false;
    }
@Test
    public void determinesIfSchemasAreTransitivelyDependent() throws IOException {
        String schemasText = "TypeA { TypeB b; }"
                           + "TypeB { TypeC c; }"
                           + "TypeC { TypeD d; }";
        
        List<HollowSchema> schemas = HollowSchemaParser.parseCollectionOfSchemas(schemasText);
        
        HollowWriteStateEngine stateEngine = new HollowWriteStateEngine();
        HollowWriteStateCreator.populateStateEngineWithTypeWriteStates(stateEngine, schemas);
        
        Assert.assertTrue(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeA", "TypeB"));
        Assert.assertTrue(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeA", "TypeC"));
        Assert.assertTrue(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeB", "TypeC"));
        Assert.assertFalse(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeC", "TypeB"));
        Assert.assertFalse(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeB", "TypeA"));
        Assert.assertFalse(HollowSchemaSorter.typeIsTransitivelyDependent(stateEngine, "TypeC", "TypeA"));
    }