public boolean sync(Map<FlagId, FlagData> flagData) {
        boolean modified = false;
        Map<FlagId, FlagData> currentFlagData = read();
        Set<FlagId> flagIdsToBeRemoved = new HashSet<>(currentFlagData.keySet());
        List<FlagData> flagDataList = new ArrayList<>(flagData.values());

        for (FlagData data : flagDataList) {
            flagIdsToBeRemoved.remove(data.id());

            FlagData existingFlagData = currentFlagData.get(data.id());
            if (existingFlagData == null) {
                logger.log(Level.INFO, "New flag " + data.id() + ": " + data.serializeToJson());
                modified = true;

                // Could also consider testing with FlagData::equals, but that would be too fragile?
            } else if (!Objects.equals(data.serializeToJson(), existingFlagData.serializeToJson())){
                logger.log(Level.INFO, "Updating flag " + data.id() + " from " +
                        existingFlagData.serializeToJson() + " to " + data.serializeToJson());
                modified = true;
            }
        }

        if (!flagIdsToBeRemoved.isEmpty()) {
            String flagIdsString = flagIdsToBeRemoved.stream().map(FlagId::toString).collect(Collectors.joining(", "));
            logger.log(Level.INFO, "Removing flags " + flagIdsString);
            modified = true;
        }

        if (!modified) return false;

        writeFile(FlagData.serializeListToUtf8Json(flagDataList));

        return modified;
    }
Java API for a flag database stored in a single file

@author hakonhall
flags/src/main/java/com/yahoo/vespa/flags/file/FlagDbFile.java