Mutation { protected static Set<String> getUpdatedColumns( final Map<String, ?> previousValues, final Map<String, ?> currentValues) { final Set<String> previousColumns = previousValues.keySet(); final Set<String> currentColumns = currentValues.keySet(); return ImmutableSet.<String>builder() .addAll(Sets.symmetricDifference(currentColumns, previousColumns)) .addAll( Sets.intersection(currentColumns, previousColumns) .stream() .filter( column -> !Objects.deepEquals(previousValues.get(column), currentValues.get(column))) .collect(Collectors.toSet())) .build(); }    }
@Test public void testAddAndRemoveScalarColumns() { String removedKey = "removedKey"; String addedKey = "addedKey"; Map<String, String> previousColumns = ImmutableMap.of( removedKey, "removedValue", SHARED_KEY, "sharedValue"); Map<String, String> currentColumns = ImmutableMap.of( SHARED_KEY, "sharedValue", addedKey, "addedValue"); assertEquals( ImmutableSet.of(removedKey, addedKey), Mutation.getUpdatedColumns(previousColumns, currentColumns)); }
@Test public void testUpdateScalarColumnValues() { String updatedKey = "updatedKey"; Map<String, String> previousColumns = ImmutableMap.of( SHARED_KEY, "sharedValue", updatedKey, "previousValue"); Map<String, String> currentColumns = ImmutableMap.of( SHARED_KEY, "sharedValue", updatedKey, "currentValue"); assertEquals( ImmutableSet.of(updatedKey), Mutation.getUpdatedColumns(previousColumns, currentColumns)); }
@Test public void testUpdateArrayColumnValues() { String updatedKey = "updatedKey"; Map<String, Object> previousColumns = ImmutableMap.of( SHARED_KEY, new byte[] {0x00, 0x01}, updatedKey, new byte[] {0x02, 0x03}); Map<String, Object> currentColumns = ImmutableMap.of( SHARED_KEY, new byte[] {0x00, 0x01}, updatedKey, new byte[] {0x04, 0x05}); assertEquals( ImmutableSet.of(updatedKey), Mutation.getUpdatedColumns(previousColumns, currentColumns)); }