Examples of MapDifference


Examples of com.google.common.collect.MapDifference

                String ksName = keyspace.getName();
                MapStringToObject keyspaceOptions = getKeyspaceOptions(keyspace);
               
                if (existingKeyspaces.containsKey(ksName)) {
                    MapStringToObject previousOptions = JsonSerializer.fromString(existingKeyspaces.get(ksName), MapStringToObject.class);
                    MapDifference keyspaceDiff = Maps.difference(keyspaceOptions, previousOptions);
                    if (keyspaceDiff.areEqual()) {
                        LOG.info("Keyspace '{}' didn't change", new Object[]{ksName});
                    }
                    else {
                        changed = true;
                        LOG.info("CF Changed: " + keyspaceDiff.entriesDiffering());
                    }
                }
                else {
                    changed = true;
                }
                String strKeyspaceOptions = JsonSerializer.toString(keyspaceOptions);
               
//                // Keep track of keyspace
                foundKeyspaces.add(keyspace.getName());
                existingKeyspaces.put(ksName, strKeyspaceOptions);
               
                LOG.info("Found keyspace '{}|{}' : {}", new Object[]{entity.getClusterName(), ksName, keyspaceOptions});
               
//                // Iterate found column families
                for (ColumnFamilyDefinition cf : keyspace.getColumnFamilyList()) {
                    // Extract data from the ColumnFamilyDefinition
                    String cfName = String.format("%s|%s", keyspace.getName(), cf.getName());
                    MapStringToObject cfOptions = getColumnFamilyOptions(cf);
                    String strCfOptions = JsonSerializer.toString(cfOptions);
//                   
//                    // Check for changes
                    if (existingColumnFamilies.containsKey(cfName)) {
                        MapStringToObject previousOptions = JsonSerializer.fromString(existingColumnFamilies.get(cfName), MapStringToObject.class);
                       
                        LOG.info("Old options: " + previousOptions);
                       
                        MapDifference cfDiff = Maps.difference(cfOptions, previousOptions);
                        if (cfDiff.areEqual()) {
                            LOG.info("CF '{}' didn't change", new Object[]{cfName});
                        }
                        else {
                            changed = true;
                            LOG.info("CF Changed: " + cfDiff.entriesDiffering());
                        }

                    }
                    else {
                        changed = true;
View Full Code Here

Examples of org.jtester.hamcrest.matcher.property.difference.MapDifference

        // Create copy from which we can remove elements.
        Map<Object, Object> rightCopy = new HashMap<Object, Object>(rightMap);

        ReflectionComparator keyReflectionComparator = createRefectionComparator();
        MapDifference difference = new MapDifference("Different elements", left, right, leftMap, rightMap);

        for (Map.Entry<?, ?> leftEntry : leftMap.entrySet()) {
            Object leftKey = leftEntry.getKey();
            Object leftValue = leftEntry.getValue();

            boolean found = false;
            Iterator<Map.Entry<Object, Object>> rightIterator = rightCopy.entrySet().iterator();
            while (rightIterator.hasNext()) {
                Map.Entry<Object, Object> rightEntry = rightIterator.next();
                Object rightKey = rightEntry.getKey();
                Object rightValue = rightEntry.getValue();

                // compare keys using strict reflection compare
                boolean isKeyEqual = keyReflectionComparator.isEqual(leftKey, rightKey);
                if (isKeyEqual) {
                    found = true;
                    rightIterator.remove();

                    // compare values
                    Difference elementDifference = reflectionComparator.getDifference(leftValue, rightValue, onlyFirstDifference);
                    if (elementDifference != null) {
                        difference.addValueDifference(leftKey, elementDifference);
                        if (onlyFirstDifference) {
                            return difference;
                        }
                    }
                    break;
                }
            }

            if (!found) {
                difference.addLeftMissingKey(leftKey);
            }
        }

        for (Object rightKey : rightCopy.keySet()) {
            difference.addRightMissingKey(rightKey);
        }

        if (difference.getValueDifferences().isEmpty() && difference.getLeftMissingKeys().isEmpty() && difference.getRightMissingKeys().isEmpty()) {
            return null;
        }
        return difference;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.