static Map applyFieldsDelta()

in scripts/src/main/java/com/gu/typesafe/config/impl/SimpleConfigOrigin.java [501:563]


    static Map<SerializedField, Object> applyFieldsDelta(Map<SerializedField, Object> base,
            Map<SerializedField, Object> delta) throws IOException {

        Map<SerializedField, Object> m = new EnumMap<SerializedField, Object>(delta);

        for (Map.Entry<SerializedField, Object> baseEntry : base.entrySet()) {
            SerializedField f = baseEntry.getKey();
            if (delta.containsKey(f)) {
                // delta overrides when keys are in both
                // "m" should already contain the right thing
            } else {
                // base has the key and delta does not.
                // we inherit from base unless a "NULL" key blocks.
                switch (f) {
                case ORIGIN_DESCRIPTION:
                    m.put(f, base.get(f));
                    break;
                case ORIGIN_URL:
                    if (delta.containsKey(SerializedField.ORIGIN_NULL_URL)) {
                        m.remove(SerializedField.ORIGIN_NULL_URL);
                    } else {
                        m.put(f, base.get(f));
                    }
                    break;
                case ORIGIN_RESOURCE:
                    if (delta.containsKey(SerializedField.ORIGIN_NULL_RESOURCE)) {
                        m.remove(SerializedField.ORIGIN_NULL_RESOURCE);
                    } else {
                        m.put(f, base.get(f));
                    }
                    break;
                case ORIGIN_COMMENTS:
                    if (delta.containsKey(SerializedField.ORIGIN_NULL_COMMENTS)) {
                        m.remove(SerializedField.ORIGIN_NULL_COMMENTS);
                    } else {
                        m.put(f, base.get(f));
                    }
                    break;
                case ORIGIN_NULL_URL: // FALL THRU
                case ORIGIN_NULL_RESOURCE: // FALL THRU
                case ORIGIN_NULL_COMMENTS: // FALL THRU
                    // base objects shouldn't contain these, should just
                    // lack the field. these are only in deltas.
                    throw new com.gu.typesafe.config.ConfigException.BugOrBroken("applying fields, base object should not contain " + f + " "
                            + base);
                case ORIGIN_END_LINE_NUMBER: // FALL THRU
                case ORIGIN_LINE_NUMBER: // FALL THRU
                case ORIGIN_TYPE:
                    m.put(f, base.get(f));
                    break;

                case END_MARKER:
                case ROOT_VALUE:
                case ROOT_WAS_CONFIG:
                case UNKNOWN:
                case VALUE_DATA:
                case VALUE_ORIGIN:
                    throw new ConfigException.BugOrBroken("should not appear here: " + f);
                }
            }
        }
        return m;
    }