Replace anonymous types with lambdas and method refs

This commit is contained in:
Chris Beams 2014-12-27 02:36:03 +01:00
parent 366f6246ce
commit d099100adf
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
14 changed files with 156 additions and 280 deletions

View File

@ -65,11 +65,7 @@ public class EthereumImpl implements Ethereum {
worldManager.loadBlockchain();
if (CONFIG.listenPort() > 0) {
Executors.newSingleThreadExecutor().submit(
new Runnable() {
public void run() {
peerServer.start(CONFIG.listenPort());
}
}
() -> peerServer.start(CONFIG.listenPort())
);
}
}

View File

@ -132,9 +132,7 @@ public abstract class FastByteComparisons {
static {
theUnsafe = (Unsafe) AccessController.doPrivileged(
new PrivilegedAction<Object>() {
@Override
public Object run() {
(PrivilegedAction<Object>) () -> {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
@ -146,7 +144,6 @@ public abstract class FastByteComparisons {
} catch (IllegalAccessException e) {
throw new Error();
}
}
});
BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);

View File

@ -26,7 +26,6 @@ import java.math.BigInteger;
import java.security.SignatureException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -175,12 +174,7 @@ public class ECKeyTest {
final ECKey key = new ECKey();
for (byte i = 0; i < ITERATIONS; i++) {
final byte[] hash = HashUtil.sha3(new byte[]{i});
sigFutures.add(executor.submit(new Callable<ECKey.ECDSASignature>() {
@Override
public ECKey.ECDSASignature call() throws Exception {
return key.doSign(hash);
}
}));
sigFutures.add(executor.submit(() -> key.doSign(hash)));
}
List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
for (ECKey.ECDSASignature signature : sigs) {

View File

@ -823,16 +823,12 @@ public class BlockChainTable extends JFrame implements ActionListener {
transactionPanel.add(nonce, c);
JButton data = new JButton("Data");
data.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
data.addActionListener(event -> {
if (transactionDataWindow == null)
transactionDataWindow = new TransactionData(blockchainTable);
transactionDataWindow.setData(transaction.getData());
transactionDataWindow.setVisible(true);
transactionDataWindow.highlightText(findText.getText(), painter);
}
});
data.setFont(plain);
if (findText.getText().length() > 0 && ByteUtil.toHexString(transaction.getData()).contains(findText.getText

View File

@ -89,14 +89,12 @@ public class ConnectionConsoleWindow extends JFrame {
UIEthereumManager.ethereum.addListener(new EthereumListenerAdapter() {
@Override
public void trace(final String output) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
textArea.append(output);
textArea.append("\n");
if (autoScroll)
textArea.setCaretPosition(textArea.getText().length());
}
});
}
});
@ -149,11 +147,7 @@ public class ConnectionConsoleWindow extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ConnectionConsoleWindow(null).setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new ConnectionConsoleWindow(null).setVisible(true));
}

View File

@ -70,11 +70,7 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog {
@Override
public void focusLost(FocusEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
populateContractDetails();
}
});
SwingUtilities.invokeLater(ContractCallDialog.this::populateContractDetails);
}
});

View File

@ -235,11 +235,9 @@ class PayOutDialog extends JDialog implements MessageAwareDialog {
inputMap.put(stroke, "ESCAPE");
rootPane.getActionMap().put("ESCAPE", actionListener);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
setSize(500, 255);
setVisible(true);
}
});
@ -250,26 +248,22 @@ class PayOutDialog extends JDialog implements MessageAwareDialog {
final PayOutDialog dialog = this;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
dialog.statusMsg.setForeground(Color.GREEN.darker().darker());
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
}
});
}
public void alertStatusMsg(final String text) {
final PayOutDialog dialog = this;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
dialog.statusMsg.setForeground(Color.RED);
dialog.statusMsg.setText(text);
dialog.revalidate();
dialog.repaint();
}
});
}

View File

@ -81,10 +81,6 @@ public class PeerInfoWindow extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new PeerInfoWindow(null).setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new PeerInfoWindow(null).setVisible(true));
}
}

View File

@ -32,12 +32,7 @@ public class PeersTableModel extends AbstractTableModel {
updater.scheduleAtFixedRate(new TimerTask() {
public void run() {
SwingUtilities.invokeLater(
new Runnable() {
@Override
public void run() {
updateModel();
}
}
PeersTableModel.this::updateModel
);
}
}, 0, 100);

View File

@ -64,11 +64,7 @@ public class PeersTableWindow extends JFrame {
PeersTableModel model = (PeersTableModel) table.getModel();
if (me.getClickCount() == 2) {
final PeersTableModel.PeerInfo peerInfo = model.getPeerInfo(row);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new PeerInfoWindow(peerInfo).setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new PeerInfoWindow(peerInfo).setVisible(true));
System.out.println(peerInfo);
}
}

View File

@ -190,10 +190,6 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
// final byte[] code = SerpentCompiler.compileAssemblyToMachine(asmCode);
final byte[] code = Hex.decode("7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d6552656700000000000000000000000000000000000000000000000000573360455760415160566000396000f20036602259604556330e0f600f5933ff33560f601e5960003356576000335700604158600035560f602b590033560f60365960003356573360003557600035335700");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(code, null, null);
}
});
SwingUtilities.invokeLater(() -> createAndShowGUI(code, null, null));
}
}

View File

@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
@ -277,9 +276,7 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("OpenFileButton", openFile);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
button.addActionListener(e -> {
File file = callFileChooser();
try {
if (file == null)
@ -292,7 +289,6 @@ public class SerpentEditor extends JFrame {
// don't worry it's just the file is empty
codeArea.setText("");
}
}
});
toolbar.add(button);
}
@ -331,9 +327,7 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("OpenSaveButton", saveFile);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
button.addActionListener(e -> {
File file = null;
@ -357,7 +351,6 @@ public class SerpentEditor extends JFrame {
} catch (IOException e1) {
logger.error(e1.getMessage(), e1);
}
}
});
toolbar.add(button);
}
@ -384,12 +377,7 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("CompileButton", compile);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
compileCode();
}
});
button.addActionListener(e -> compileCode());
toolbar.add(button);
}
@ -415,14 +403,12 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("DeployButton", deploy);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.addActionListener(e -> {
byte[] machineCode = prepareCodeForSend();
if (machineCode == null) return;
ContractSubmitDialog payOutDialog =
new ContractSubmitDialog((Frame) SwingUtilities.getAncestorOfClass(JFrame.class,
contentPane), machineCode);
}
});
toolbar.add(button);
}
@ -449,12 +435,10 @@ public class SerpentEditor extends JFrame {
mainContentPane.getActionMap().put("CallButton", call);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.addActionListener(e -> {
ContractCallDialog payOutDialog = new ContractCallDialog(
(Frame) SwingUtilities.getAncestorOfClass(
JFrame.class, contentPane));
}
});
toolbar.add(button);
}
@ -489,10 +473,6 @@ public class SerpentEditor extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SerpentEditor(null).setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new SerpentEditor(null).setVisible(true));
}
}

View File

@ -10,10 +10,6 @@ import org.ethereum.vm.Program;
import org.spongycastle.util.encoders.Hex;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -70,18 +66,11 @@ public class StateExplorerWindow extends JFrame {
btnListAccounts.setBorderPainted(false);
btnListAccounts.setFocusPainted(false);
btnListAccounts.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnListAccounts.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
btnListAccounts.addItemListener(e -> SwingUtilities.invokeLater(() -> {
if (accountsListWindow == null)
accountsListWindow = new AccountsListWindow();
accountsListWindow.setVisible(true);
}
});
}
});
}));
horizontalBox.add(btnListAccounts);
@ -136,12 +125,10 @@ public class StateExplorerWindow extends JFrame {
l1.setAlignmentX(Component.CENTER_ALIGNMENT);
JComboBox cmbKey = new JComboBox(dataTypes);
cmbKey.setSelectedIndex(1);
cmbKey.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cmbKey.addActionListener(e -> {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setKeyEncoding(t);
}
});
VBox1.add(l1);
VBox1.add(cmbKey);
@ -152,12 +139,10 @@ public class StateExplorerWindow extends JFrame {
l2.setAlignmentX(Component.CENTER_ALIGNMENT);
JComboBox cmbValue = new JComboBox(dataTypes);
cmbValue.setSelectedIndex(1);
cmbValue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cmbValue.addActionListener(e -> {
JComboBox cmb = (JComboBox) e.getSource();
DataEncodingType t = DataEncodingType.getTypeFromString((String) cmb.getSelectedItem());
dataModel.setValueEncoding(t);
}
});
VBox2.add(l2);
VBox2.add(cmbValue);
@ -319,10 +304,6 @@ public class StateExplorerWindow extends JFrame {
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StateExplorerWindow(null).setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new StateExplorerWindow(null).setVisible(true));
}
}

View File

@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@ -108,21 +107,16 @@ public class ToolBar extends JFrame {
editorToggle.setBorderPainted(false);
editorToggle.setFocusPainted(false);
editorToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
editorToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
editorToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (serpentEditor == null)
serpentEditor = new SerpentEditor(ToolBar.this);
serpentEditor.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
serpentEditor.setVisible(false);
}
}
});
logToggle = new JToggleButton();
@ -133,21 +127,16 @@ public class ToolBar extends JFrame {
logToggle.setBorderPainted(false);
logToggle.setFocusPainted(false);
logToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
logToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
logToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (connectionConsoleWindow == null)
connectionConsoleWindow = new ConnectionConsoleWindow(ToolBar.this);
connectionConsoleWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
connectionConsoleWindow.setVisible(false);
}
}
});
peersToggle = new JToggleButton();
@ -158,21 +147,16 @@ public class ToolBar extends JFrame {
peersToggle.setBorderPainted(false);
peersToggle.setFocusPainted(false);
peersToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
peersToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
peersToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (mainFrame == null)
mainFrame = new PeersTableWindow(ToolBar.this);
mainFrame.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
mainFrame.setVisible(false);
}
}
});
chainToggle = new JToggleButton();
@ -183,22 +167,17 @@ public class ToolBar extends JFrame {
chainToggle.setBorderPainted(false);
chainToggle.setFocusPainted(false);
chainToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
chainToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
chainToggle.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (blockchainWindow == null)
blockchainWindow = new BlockChainTable(ToolBar.this);
blockchainWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
blockchainWindow.setVisible(false);
}
}
});
walletToggle = new JToggleButton();
@ -210,22 +189,17 @@ public class ToolBar extends JFrame {
walletToggle.setFocusPainted(false);
walletToggle.setCursor(new Cursor(Cursor.HAND_CURSOR));
walletToggle.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (walletWindow == null)
walletWindow = new WalletWindow(ToolBar.this);
walletWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
walletWindow.setVisible(false);
}
}
}
);
stateExplorer = new JToggleButton();
@ -237,22 +211,17 @@ public class ToolBar extends JFrame {
stateExplorer.setFocusPainted(false);
stateExplorer.setCursor(new Cursor(Cursor.HAND_CURSOR));
stateExplorer.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.invokeLater(() -> {
if (stateExplorerWindow == null)
stateExplorerWindow = new StateExplorerWindow(ToolBar.this);
stateExplorerWindow.setVisible(true);
}
});
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
stateExplorerWindow.setVisible(false);
}
}
}
);
@ -268,10 +237,6 @@ public class ToolBar extends JFrame {
}
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ToolBar().setVisible(true);
}
});
SwingUtilities.invokeLater(() -> new ToolBar().setVisible(true));
}
}