- Timestamp:
- 2020-05-17T18:25:00+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r16438 r16452 9 9 import java.util.Comparator; 10 10 import java.util.LinkedHashSet; 11 import java.util.LinkedList;12 11 import java.util.List; 13 12 import java.util.Objects; … … 134 133 private final String defaultExtension; 135 134 136 protected static void sort(List<ExtensionFileFilter> filters) { 137 filters.sort(new Comparator<ExtensionFileFilter>() { 138 private AllFormatsImporter all = new AllFormatsImporter(); 139 @Override 140 public int compare(ExtensionFileFilter o1, ExtensionFileFilter o2) { 141 if (o1.getDescription().equals(all.filter.getDescription())) return 1; 142 if (o2.getDescription().equals(all.filter.getDescription())) return -1; 143 return o1.getDescription().compareTo(o2.getDescription()); 144 } 145 } 146 ); 135 protected static Comparator<ExtensionFileFilter> comparator() { 136 AllFormatsImporter all = new AllFormatsImporter(); 137 return (o1, o2) -> { 138 if (o1.getDescription().equals(all.filter.getDescription())) return 1; 139 if (o2.getDescription().equals(all.filter.getDescription())) return -1; 140 return o1.getDescription().compareTo(o2.getDescription()); 141 }; 147 142 } 148 143 … … 251 246 return importers.stream() 252 247 .map(importer -> importer.filter) 253 .sorted( )248 .sorted(comparator()) 254 249 .collect(Collectors.toList()); 255 250 } … … 264 259 */ 265 260 public static List<ExtensionFileFilter> getExportExtensionFileFilters() { 266 List<ExtensionFileFilter> filters = new LinkedList<>(); 267 for (FileExporter exporter : exporters) { 268 if (filters.contains(exporter.filter) || !exporter.isEnabled()) { 269 continue; 270 } 271 filters.add(exporter.filter); 272 } 273 sort(filters); 274 return filters; 261 return exporters.stream() 262 .filter(FileExporter::isEnabled) 263 .map(exporter -> exporter.filter) 264 .distinct() 265 .sorted(comparator()) 266 .collect(Collectors.toList()); 275 267 } 276 268 … … 284 276 public static ExtensionFileFilter getDefaultImportExtensionFileFilter(String extension) { 285 277 if (extension == null) return new AllFormatsImporter().filter; 286 for (FileImporter importer : importers) { 287 if (extension.equals(importer.filter.getDefaultExtension())) 288 return importer.filter; 289 } 290 return new AllFormatsImporter().filter; 278 return importers.stream() 279 .filter(importer -> extension.equals(importer.filter.getDefaultExtension())) 280 .findFirst().map(importer -> importer.filter) 281 .orElseGet(() -> new AllFormatsImporter().filter); 291 282 } 292 283
Note:
See TracChangeset
for help on using the changeset viewer.