Skip to content

Commit bf48da0

Browse files
committed
use lamdas
1 parent fbe9aca commit bf48da0

File tree

14 files changed

+27
-97
lines changed

14 files changed

+27
-97
lines changed

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/components/JExtendedComboBox.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ protected void fireItemStateChanged(ItemEvent e) {
9494
case ItemEvent.SELECTED:
9595

9696
if (e.getItem() instanceof JSeparator) {
97-
SwingUtilities.invokeLater(new Runnable() {
98-
public void run() {
99-
selectNextItem();
100-
}
101-
});
102-
97+
SwingUtilities.invokeLater(this::selectNextItem);
10398
}
10499

105100
break;

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CPUResultsPanel.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ protected JPopupMenu createPopupMenu() {
161161

162162
Font boldfont = popup.getFont().deriveFont(Font.BOLD);
163163

164-
ActionListener menuListener = new ActionListener() {
165-
public void actionPerformed(ActionEvent evt) {
166-
menuActionPerformed(evt);
167-
}
168-
};
164+
ActionListener menuListener = this::menuActionPerformed;
169165

170166
boolean separator = true;
171167
if (popupShowSource != null) {

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/ReverseCallGraphPanel.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,7 @@ protected JPopupMenu createPopupMenu() {
635635
popup.addSeparator();
636636
}
637637

638-
639-
ActionListener menuListener = new ActionListener() {
640-
public void actionPerformed(ActionEvent evt) {
641-
menuActionPerformed(evt);
642-
}
643-
};
644-
645-
if (popupShowSource != null) popupShowSource.addActionListener(menuListener);
638+
if (popupShowSource != null) popupShowSource.addActionListener(this::menuActionPerformed);
646639

647640
return popup;
648641
}

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/StatisticsPanel.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,11 @@ private String getRelValue(double value) {
129129

130130
private void initComponents() {
131131
filler.setOpaque(false);
132-
nameLabel = new KeyboardAwareLabel(model.isSelectable(index),
133-
new Runnable() {
134-
public void run() {
135-
for (Listener l : listeners) {
136-
l.itemClicked(index);
137-
}
138-
}
139-
});
132+
nameLabel = new KeyboardAwareLabel(model.isSelectable(index), () -> {
133+
for (Listener l : listeners) {
134+
l.itemClicked(index);
135+
}
136+
});
140137

141138
valueLabel.setOpaque(false);
142139
valueLabel.setHorizontalAlignment(SwingConstants.TRAILING);
@@ -487,11 +484,7 @@ public StatisticsPanel(HTMLTextArea navArea, PieChart pieChart, Runnable navigat
487484

488485
initComponents(navArea, pieChart);
489486

490-
pieChart.getModel().addChartModelListener(new ChartModelListener() {
491-
public void chartDataChanged() {
492-
updateItemPresenters();
493-
}
494-
});
487+
pieChart.getModel().addChartModelListener(this::updateItemPresenters);
495488
}
496489

497490
//~ Methods ------------------------------------------------------------------------------------------------------------------

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/jdbc/SQLFilterPanel.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ protected void populatePopup(JPopupMenu popup) {
177177
protected void fireActionPerformed(ActionEvent e) {
178178
if (!isSelected()) current.commands.add(command);
179179
else current.commands.remove(command);
180-
SwingUtilities.invokeLater(new Runnable() {
181-
public void run() { apply(); }
182-
});
180+
SwingUtilities.invokeLater(SQLFilterPanel.this::apply);
183181
}
184182
};
185183
popup.add(i);
@@ -204,9 +202,7 @@ protected void displayPopup() {
204202
protected void selectionChanged(Collection<String> selected) {
205203
current.tables.clear();
206204
current.tables.addAll(selected);
207-
SwingUtilities.invokeLater(new Runnable() {
208-
public void run() { apply(); }
209-
});
205+
SwingUtilities.invokeLater(SQLFilterPanel.this::apply);
210206
}
211207
}.show(this);
212208
}
@@ -228,29 +224,23 @@ protected void populatePopup(JPopupMenu popup) {
228224
protected void fireActionPerformed(ActionEvent e) {
229225
if (!isSelected()) current.statements.add(JdbcCCTProvider.SQL_STATEMENT);
230226
else current.statements.remove(JdbcCCTProvider.SQL_STATEMENT);
231-
SwingUtilities.invokeLater(new Runnable() {
232-
public void run() { apply(); }
233-
});
227+
SwingUtilities.invokeLater(SQLFilterPanel.this::apply);
234228
}
235229
});
236230

237231
popup.add(new JCheckBoxMenuItem(STATEMENT_PREPARED, !current.statements.contains(JdbcCCTProvider.SQL_PREPARED_STATEMENT)) {
238232
protected void fireActionPerformed(ActionEvent e) {
239233
if (!isSelected()) current.statements.add(JdbcCCTProvider.SQL_PREPARED_STATEMENT);
240234
else current.statements.remove(JdbcCCTProvider.SQL_PREPARED_STATEMENT);
241-
SwingUtilities.invokeLater(new Runnable() {
242-
public void run() { apply(); }
243-
});
235+
SwingUtilities.invokeLater(SQLFilterPanel.this::apply);
244236
}
245237
});
246238

247239
popup.add(new JCheckBoxMenuItem(STATEMENT_CALLABLE, !current.statements.contains(JdbcCCTProvider.SQL_CALLABLE_STATEMENT)) {
248240
protected void fireActionPerformed(ActionEvent e) {
249241
if (!isSelected()) current.statements.add(JdbcCCTProvider.SQL_CALLABLE_STATEMENT);
250242
else current.statements.remove(JdbcCCTProvider.SQL_CALLABLE_STATEMENT);
251-
SwingUtilities.invokeLater(new Runnable() {
252-
public void run() { apply(); }
253-
});
243+
SwingUtilities.invokeLater(SQLFilterPanel.this::apply);
254244
}
255245
});
256246
}

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/memory/MemoryResultsPanel.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,7 @@ public void actionPerformed(ActionEvent e) {
177177
jScrollPane.getViewport().setBackground(table.getBackground());
178178

179179
if (!registeredMouseListenerWithResTable) {
180-
jScrollPane.addMouseWheelListener(new MouseWheelListener() {
181-
public void mouseWheelMoved(MouseWheelEvent e) {
182-
table.mouseWheelMoved(e);
183-
}
184-
});
180+
jScrollPane.addMouseWheelListener(table);
185181

186182
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
187183
public void valueChanged(ListSelectionEvent e) {

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/swing/ProfilerTreeTable.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,7 @@ protected TableRowSorter createRowSorter() {
588588
ProfilerRowSorter s = new ProfilerTreeTableSorter(getModel()) {
589589
public void allRowsChanged() {
590590
// Must invoke later, JTree.getRowCount() not ready yet
591-
SwingUtilities.invokeLater(new Runnable() {
592-
public void run() { updateColumnsPreferredWidth(); }
593-
});
591+
SwingUtilities.invokeLater(ProfilerTreeTable.this::updateColumnsPreferredWidth);
594592
}
595593
protected void setSortKeysImpl(List newKeys) {
596594
// TODO: Improve to not call createComparator(newKeys) here and from super
@@ -1473,9 +1471,7 @@ public void fireTreeCollapsed(TreePath path) {
14731471
super.removeDescendantToggledPaths(Collections.enumeration(Collections.singletonList(path)));
14741472
// NOTE: uncachePath() must be called for all DescendantToggledPaths once implemented!
14751473
((SortedFilteredTreeModel)getModel()).clearPath(path);
1476-
SwingUtilities.invokeLater(new Runnable() {
1477-
public void run() { updateUI(); }
1478-
});
1474+
SwingUtilities.invokeLater(this::updateUI);
14791475
}
14801476
}
14811477

visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/TimelineView.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,15 @@ JComponent getView() {
164164

165165
selectAllButton = new JButton(Icons.getIcon(TracerIcons.SELECT_ALL)) {
166166
protected void fireActionPerformed(ActionEvent e) {
167-
SwingUtilities.invokeLater(new Runnable() {
168-
public void run() { support.selectAll(); }
169-
});
167+
SwingUtilities.invokeLater(support::selectAll);
170168
}
171169
};
172170
selectAllButton.setToolTipText(Bundle.TOOLTIP_SelectAll());
173171
toolbar.add(selectAllButton);
174172

175173
clearTimestampSelectionButton = new JButton(Icons.getIcon(TracerIcons.MARK_CLEAR)) {
176174
protected void fireActionPerformed(ActionEvent e) {
177-
SwingUtilities.invokeLater(new Runnable() {
178-
public void run() { support.resetSelectedTimestamps(); }
179-
});
175+
SwingUtilities.invokeLater(support::resetSelectedTimestamps);
180176
}
181177
};
182178
clearTimestampSelectionButton.setToolTipText(Bundle.TOOLTIP_ClearMarks());

visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/TracerModel.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public final class TracerModel {
7070

7171
public TracerModel(IdeSnapshot snapshot) {
7272
this.snapshot = snapshot;
73-
timelineSupport = new TimelineSupport(new TimelineSupport.DescriptorResolver() {
74-
public TracerProbeDescriptor getDescriptor(TracerProbe p) {
75-
return TracerModel.this.getDescriptor(p);
76-
}
77-
}, snapshot);
73+
timelineSupport = new TimelineSupport(TracerModel.this::getDescriptor, snapshot);
7874
}
7975

8076

@@ -181,11 +177,7 @@ private void addProbe(TracerPackage p, TracerProbeDescriptor d) {
181177
descriptorsCache.put(r, d);
182178
}
183179
synchronized(probesCache) {
184-
List<TracerProbe> probes = probesCache.get(p);
185-
if (probes == null) {
186-
probes = new ArrayList();
187-
probesCache.put(p, probes);
188-
}
180+
List<TracerProbe> probes = probesCache.computeIfAbsent(p, k -> new ArrayList<>());
189181
probes.add(r);
190182
}
191183

visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/swing/ColorIcon.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ public static void setup(int width, int height, Color foreground, Color backgrou
6767
}
6868

6969
public static ColorIcon fromColor(Color color) {
70-
ColorIcon icon = icons.get(color);
71-
if (icon == null) {
72-
icon = new ColorIcon(color);
73-
icons.put(color, icon);
74-
}
75-
return icon;
70+
return icons.computeIfAbsent(color, ColorIcon::new);
7671
}
7772

7873

0 commit comments

Comments
 (0)