Browse Source

Filter duplicate icons

pull/299/head
Jannis Weis 3 years ago
parent
commit
59d3be81bc
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 20
      core/src/test/java/com/github/weisj/darklaf/icon/AllIconsDemo.java

20
core/src/test/java/com/github/weisj/darklaf/icon/AllIconsDemo.java

@ -21,10 +21,8 @@
package com.github.weisj.darklaf.icon; package com.github.weisj.darklaf.icon;
import java.awt.*; import java.awt.*;
import java.util.HashSet; import java.util.*;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.swing.*; import javax.swing.*;
@ -104,21 +102,21 @@ public class AllIconsDemo extends BaseComponentDemo {
return new NamedIcon<>(p, centered ? new CenterIcon(icon, displaySize, displaySize) : icon); return new NamedIcon<>(p, centered ? new CenterIcon(icon, displaySize, displaySize) : icon);
}).collect(Collectors.groupingBy(pair -> pathToIconName(pair.getFirst()))) }).collect(Collectors.groupingBy(pair -> pathToIconName(pair.getFirst())))
.values().stream() .values().stream()
.map(HashSet::new)
.peek(list -> makeUnique(list, 1)) .peek(list -> makeUnique(list, 1))
.flatMap(List::stream) .flatMap(Set::stream)
.sorted(Pair.compareFirst(AllIconsDemo::pathToIconName)).collect(Collectors.toList()); .sorted(Pair.compareFirst()).collect(Collectors.toList());
} }
} }
private static <T extends Icon> void makeUnique(final List<NamedIcon<T>> iconList, final int depth) { private static <T extends Icon> void makeUnique(final Set<NamedIcon<T>> iconSet, final int depth) {
if (iconList.size() <= 1) { if (iconSet.size() <= 1) {
iconList.forEach(p -> p.setFirst(pathToIconName(p.getFirst(), depth))); iconSet.forEach(p -> p.setFirst(pathToIconName(p.getFirst(), depth)));
} else { } else {
new HashSet<>(iconList) iconSet.stream()
.stream()
.collect(Collectors.groupingBy(p -> pathToIconName(p.getFirst(), depth + 1))) .collect(Collectors.groupingBy(p -> pathToIconName(p.getFirst(), depth + 1)))
.values() .values()
.forEach(list -> makeUnique(list, depth + 1)); .forEach(list -> makeUnique(new HashSet<>(list), depth + 1));
} }
} }

Loading…
Cancel
Save