private static List<Rule> optimizeRules(List<Rule> rules) {
        // Remove trailing rules without value, as absent value implies the code default.
        // Removing trailing rules may further simplify when e.g. this results in no rules,
        // which is equivalent to no flag data at all, and flag data may be deleted from a zone.
        if (rules.isEmpty()) return rules;
        if (rules.get(rules.size() - 1).getValueToApply().isPresent()) return rules;
        var newRules = new ArrayList<>(rules);
        while (newRules.size() > 0) {
            Rule lastRule = newRules.get(newRules.size() - 1);
            if (lastRule.getValueToApply().isEmpty()) {
                newRules.remove(newRules.size() - 1);
            } else {
                break;
            }
        }
        return newRules;
    }
Take a raw list of rules from e.g. deserialization or partial resolution and normalize/simplify it.
flags/src/main/java/com/yahoo/vespa/flags/json/FlagData.java