Change conversion of config stream to map to pairs
Change conversion of config stream to map and then creating new stream and just iterating entries to mapping config stream to pairs (map entries, becuase Java do not have generic pair implementation). Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.config;
|
package net.runelite.client.plugins.config;
|
||||||
|
|
||||||
|
import static javax.swing.JOptionPane.WARNING_MESSAGE;
|
||||||
|
import static javax.swing.JOptionPane.YES_NO_OPTION;
|
||||||
|
import static javax.swing.JOptionPane.YES_OPTION;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
@@ -35,10 +38,9 @@ import java.awt.event.MouseAdapter;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
@@ -48,9 +50,6 @@ import javax.swing.JFormattedTextField;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import static javax.swing.JOptionPane.WARNING_MESSAGE;
|
|
||||||
import static javax.swing.JOptionPane.YES_NO_OPTION;
|
|
||||||
import static javax.swing.JOptionPane.YES_OPTION;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
@@ -115,22 +114,21 @@ public class ConfigPanel extends PluginPanel
|
|||||||
Map<String, JPanel> newChildren = new TreeMap<>();
|
Map<String, JPanel> newChildren = new TreeMap<>();
|
||||||
configManager.getConfigProxies()
|
configManager.getConfigProxies()
|
||||||
.stream()
|
.stream()
|
||||||
// Config cannot be key because Proxy does not implement hashCode
|
// Convert config proxies to pair of config descriptors and config proxies
|
||||||
.collect(Collectors.toMap(configManager::getConfigDescriptor, Function.identity()))
|
.map(c -> new AbstractMap.SimpleEntry<>(configManager.getConfigDescriptor(c), c))
|
||||||
.entrySet().stream()
|
.filter(e -> e.getKey().getItems().stream().anyMatch(cid -> !cid.getItem().hidden()))
|
||||||
.filter(e -> e.getKey().getItems().stream()
|
|
||||||
.anyMatch(cid -> !cid.getItem().hidden()))
|
|
||||||
.forEach(e ->
|
.forEach(e ->
|
||||||
{
|
{
|
||||||
ConfigDescriptor cd = e.getKey();
|
ConfigDescriptor cd = e.getKey();
|
||||||
Config config = e.getValue();
|
Config config = e.getValue();
|
||||||
|
|
||||||
String groupName = cd.getGroup().name();
|
String groupName = cd.getGroup().name();
|
||||||
|
|
||||||
if (children.containsKey(groupName))
|
if (children.containsKey(groupName))
|
||||||
{
|
{
|
||||||
newChildren.put(groupName, children.get(groupName));
|
newChildren.put(groupName, children.get(groupName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JPanel groupPanel = new JPanel();
|
JPanel groupPanel = new JPanel();
|
||||||
groupPanel.setLayout(new BorderLayout());
|
groupPanel.setLayout(new BorderLayout());
|
||||||
JButton viewGroupItemsButton = new JButton(groupName);
|
JButton viewGroupItemsButton = new JButton(groupName);
|
||||||
@@ -138,6 +136,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
groupPanel.add(viewGroupItemsButton);
|
groupPanel.add(viewGroupItemsButton);
|
||||||
newChildren.put(groupName, groupPanel);
|
newChildren.put(groupName, groupPanel);
|
||||||
});
|
});
|
||||||
|
|
||||||
children = newChildren;
|
children = newChildren;
|
||||||
openConfigList();
|
openConfigList();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user