| | 927 | |
| | 928 | /** |
| | 929 | * Cleanup entries where it is the same as the default, or it matches some other condition (for example, cached files). |
| | 930 | * This should (generally) be run by JOSM core, <i>not</i> plugins. |
| | 931 | * |
| | 932 | * @throws IOException - if any I/O error occurs |
| | 933 | * @since xxx |
| | 934 | */ |
| | 935 | public void cleanup() throws IOException { |
| | 936 | List<String> keysToRemove = new ArrayList<>(); |
| | 937 | for (Map.Entry<String, Setting<?>> defaultSetting : defaultsMap.entrySet()) { |
| | 938 | Setting<?> setting = this.settingsMap.get(defaultSetting.getKey()); |
| | 939 | if ((setting != null && setting.equals(setting.getValue())) |
| | 940 | || (setting == null && defaultSetting.getValue() == null)) { |
| | 941 | keysToRemove.add(defaultSetting.getKey()); |
| | 942 | } else if (defaultSetting.getKey() != null && defaultSetting.getKey().startsWith("mirror.") && |
| | 943 | !defaultSetting.getKey().equals("mirror.maxtime")) { |
| | 944 | if (defaultSetting.getValue() == null || setting == null) { |
| | 945 | keysToRemove.add(defaultSetting.getKey()); |
| | 946 | } else if (setting instanceof ListSetting) { |
| | 947 | ListSetting listSetting = (ListSetting) setting; |
| | 948 | if (listSetting.getValue().isEmpty() || Long.parseLong(listSetting.getValue().get(0)) < System.currentTimeMillis()) { |
| | 949 | Files.deleteIfExists(Paths.get(listSetting.getValue().get(1))); |
| | 950 | keysToRemove.add(defaultSetting.getKey()); |
| | 951 | } |
| | 952 | } |
| | 953 | } |
| | 954 | } |
| | 955 | keysToRemove.stream().forEach(this.defaultsMap::remove); |
| | 956 | keysToRemove.stream().forEach(this.settingsMap::remove); |
| | 957 | this.save(); |
| | 958 | this.saveDefaults(); |
| | 959 | } |