public static List<EffigyFieldPair> pair(HollowEffigy from, HollowEffigy to, Map<String, PrimaryKey> matchHints) { if(from == null || to == null) return new HollowEffigyNullPartnerPairer(from, to).pair(); if(from.getDataAccess() == null) return new HollowEffigyObjectPairer(from, to).pair(); HollowSchema schema = from.getDataAccess().getSchema(); switch(schema.getSchemaType()) { case OBJECT: return new HollowEffigyObjectPairer(from, to).pair(); case MAP: String keyType = ((HollowMapSchema)schema).getKeyType(); return new HollowEffigyMapPairer(from, to, matchHints.get(keyType)).pair(); case LIST: case SET: String elementType = ((HollowCollectionSchema)schema).getElementType(); return new HollowEffigyCollectionPairer(from, to, matchHints.get(elementType)).pair(); } throw new IllegalArgumentException("I don't know how to pair fields for type " + schema.getName() + "(" + schema.getSchemaType() + ")"); } }
@Test public void test() { HollowEffigy list1 = list( element("1", 1, 1), element("2", 2, 2), element("3", 3, 3), element("4", 4, 4) ); HollowEffigy list2 = list( element("3", 103, 103), element("1", 2, 1), element("2", 102, 2), element("5", 5, 5), element("1", 1, 1) ); HollowEffigyCollectionPairer pairer = new HollowEffigyCollectionPairer(list1, list2, null); List<EffigyFieldPair> pairs = pairer.pair(); Assert.assertEquals(6, pairs.size()); assertPair(pairs.get(0), "1", "1"); assertPair(pairs.get(1), "2", "2"); assertPair(pairs.get(2), "3", "3"); assertPair(pairs.get(3), "4", null); assertPair(pairs.get(4), null, "1"); assertPair(pairs.get(5), null, "5"); }