@Test public void diffTest() { Schema schema1 = Schema.defaultSchema(); Index index11 = makeIndex(schema1, "index11"); makeField(index11, "index11-f1"); makeField(index11, "index11-f2", true); Index index12 = makeIndex(schema1, "index12", true); makeField(index12, "index12-f1"); Index index13 = makeIndex(schema1, "index13", true); makeField(index13, "index13-f1", true); Schema schema2 = Schema.defaultSchema(); Index index21 = makeIndex(schema2, "index21"); makeField(index21, "index21-f1"); Index s2Index13 = makeIndex(schema2, "index13", true); makeField(s2Index13, "index13-f2"); Schema target = Schema.defaultSchema(); Index targetIndex11 = makeIndex(target, "index11"); makeField(targetIndex11, "index11-f1"); makeField(targetIndex11, "index11-f2", true); Index targetIndex12 = makeIndex(target, "index12", true); makeField(targetIndex12, "index12-f1"); Index targetIndex13 = makeIndex(target, "index13", true); makeField(targetIndex13, "index13-f1", true); Schema diff = schema1.diff(schema2); assertEquals(target, diff); }
public Schema diff(Schema other) { Schema result = Schema.defaultSchema(); for (Map.Entry<String, Index> indexEntry : this.indexes.entrySet()) { String indexName = indexEntry.getKey(); Index index = indexEntry.getValue(); if (!other.indexes.containsKey(indexName)) { result.indexes.put(indexName, new Index(indexEntry.getValue())); } else { Index otherIndex = other.indexes.get(indexName); Index resultIndex = Index.create(indexName, otherIndex.getOptions()); Map<String, Field> otherIndexFields = otherIndex.getFields(); for (Map.Entry<String, Field> fieldEntry : index.getFields().entrySet()) { String fieldName = fieldEntry.getKey(); if (!otherIndexFields.containsKey(fieldName)) { resultIndex.field(fieldName, fieldEntry.getValue().getOptions()); } } if (resultIndex.getFields().size() > 0) { result.indexes.put(indexName, resultIndex); } } } return result; }
Schema { public Schema diff(Schema other) { Schema result = Schema.defaultSchema(); for (Map.Entry<String, Index> indexEntry : this.indexes.entrySet()) { String indexName = indexEntry.getKey(); Index index = indexEntry.getValue(); if (!other.indexes.containsKey(indexName)) { result.indexes.put(indexName, new Index(indexEntry.getValue())); } else { Index otherIndex = other.indexes.get(indexName); Index resultIndex = Index.create(indexName, otherIndex.getOptions()); Map<String, Field> otherIndexFields = otherIndex.getFields(); for (Map.Entry<String, Field> fieldEntry : index.getFields().entrySet()) { String fieldName = fieldEntry.getKey(); if (!otherIndexFields.containsKey(fieldName)) { resultIndex.field(fieldName, fieldEntry.getValue().getOptions()); } } if (resultIndex.getFields().size() > 0) { result.indexes.put(indexName, resultIndex); } } } return result; } }
Schema { public Schema diff(Schema other) { Schema result = Schema.defaultSchema(); for (Map.Entry<String, Index> indexEntry : this.indexes.entrySet()) { String indexName = indexEntry.getKey(); Index index = indexEntry.getValue(); if (!other.indexes.containsKey(indexName)) { result.indexes.put(indexName, new Index(indexEntry.getValue())); } else { Index otherIndex = other.indexes.get(indexName); Index resultIndex = Index.create(indexName, otherIndex.getOptions()); Map<String, Field> otherIndexFields = otherIndex.getFields(); for (Map.Entry<String, Field> fieldEntry : index.getFields().entrySet()) { String fieldName = fieldEntry.getKey(); if (!otherIndexFields.containsKey(fieldName)) { resultIndex.field(fieldName, fieldEntry.getValue().getOptions()); } } if (resultIndex.getFields().size() > 0) { result.indexes.put(indexName, resultIndex); } } } return result; } private  Schema(); }
Schema { public Schema diff(Schema other) { Schema result = Schema.defaultSchema(); for (Map.Entry<String, Index> indexEntry : this.indexes.entrySet()) { String indexName = indexEntry.getKey(); Index index = indexEntry.getValue(); if (!other.indexes.containsKey(indexName)) { result.indexes.put(indexName, new Index(indexEntry.getValue())); } else { Index otherIndex = other.indexes.get(indexName); Index resultIndex = Index.create(indexName, otherIndex.getOptions()); Map<String, Field> otherIndexFields = otherIndex.getFields(); for (Map.Entry<String, Field> fieldEntry : index.getFields().entrySet()) { String fieldName = fieldEntry.getKey(); if (!otherIndexFields.containsKey(fieldName)) { resultIndex.field(fieldName, fieldEntry.getValue().getOptions()); } } if (resultIndex.getFields().size() > 0) { result.indexes.put(indexName, resultIndex); } } } return result; } private  Schema(); static Schema defaultSchema(); Index index(String name); Index index(String name, IndexOptions options); Index index(String name, IndexOptions options, long shardWidth); Index index(String name, Map<String, Object> options); Index index(Index other); boolean hasIndex(String indexName); Schema diff(Schema other); Map<String, Index> getIndexes(); @Override boolean equals(Object obj); @Override int hashCode(); }
Schema { public Schema diff(Schema other) { Schema result = Schema.defaultSchema(); for (Map.Entry<String, Index> indexEntry : this.indexes.entrySet()) { String indexName = indexEntry.getKey(); Index index = indexEntry.getValue(); if (!other.indexes.containsKey(indexName)) { result.indexes.put(indexName, new Index(indexEntry.getValue())); } else { Index otherIndex = other.indexes.get(indexName); Index resultIndex = Index.create(indexName, otherIndex.getOptions()); Map<String, Field> otherIndexFields = otherIndex.getFields(); for (Map.Entry<String, Field> fieldEntry : index.getFields().entrySet()) { String fieldName = fieldEntry.getKey(); if (!otherIndexFields.containsKey(fieldName)) { resultIndex.field(fieldName, fieldEntry.getValue().getOptions()); } } if (resultIndex.getFields().size() > 0) { result.indexes.put(indexName, resultIndex); } } } return result; } private  Schema(); static Schema defaultSchema(); Index index(String name); Index index(String name, IndexOptions options); Index index(String name, IndexOptions options, long shardWidth); Index index(String name, Map<String, Object> options); Index index(Index other); boolean hasIndex(String indexName); Schema diff(Schema other); Map<String, Index> getIndexes(); @Override boolean equals(Object obj); @Override int hashCode();  }