Skip to content

Commit

Permalink
(chores) replacing inner classes with lambda (#10191)
Browse files Browse the repository at this point in the history
* (chores) camel-zookeeper-master: replace inner class with lambda

* (chores) camel-zookeeper: replacing inner classes with lambda

* (chores) camel-optaplanner: replacing inner classes with lambda

* (chores) camel-xchange: replacing inner classes with lambda

* (chores) camel-xmlsecurity: replacing inner classes with lambda
  • Loading branch information
gilvansfilho authored May 23, 2023
1 parent 3489237 commit 277887d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public OptaPlannerConsumer(OptaPlannerEndpoint endpoint, Processor processor, Op
this.endpoint = endpoint;
this.configuration = configuration;

solverJobListener = new OptaplannerSolutionEventListener() {
@Override
public void bestSolutionChanged(OptaplannerSolutionEvent event) {
processSolverJobEvent(event);
}
};
solverJobListener = this::processSolverJobEvent;
}

public void processSolverJobEvent(OptaplannerSolutionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -142,31 +141,23 @@ public List<Balance> getBalances() throws IOException {
}
}
});
return balances.stream().sorted(new Comparator<Balance>() {
public int compare(Balance o1, Balance o2) {
return o1.getCurrency().compareTo(o2.getCurrency());
}
}).collect(Collectors.toList());
return balances.stream().sorted((Balance o1, Balance o2) -> o1.getCurrency().compareTo(o2.getCurrency()))
.collect(Collectors.toList());
}

public List<FundingRecord> getFundingHistory() throws IOException {
AccountService accountService = xchange.getAccountService();
TradeHistoryParams fundingHistoryParams = accountService.createFundingHistoryParams();
return accountService.getFundingHistory(fundingHistoryParams).stream().sorted(new Comparator<FundingRecord>() {
public int compare(FundingRecord o1, FundingRecord o2) {
return o1.getDate().compareTo(o2.getDate());
}
}).collect(Collectors.toList());
return accountService.getFundingHistory(fundingHistoryParams).stream()
.sorted((FundingRecord o1, FundingRecord o2) -> o1.getDate().compareTo(o2.getDate()))
.collect(Collectors.toList());
}

public List<Wallet> getWallets() throws IOException {
AccountService accountService = xchange.getAccountService();
AccountInfo accountInfo = accountService.getAccountInfo();
return accountInfo.getWallets().values().stream().sorted(new Comparator<Wallet>() {
public int compare(Wallet o1, Wallet o2) {
return o1.getName().compareTo(o2.getName());
}
}).collect(Collectors.toList());
return accountInfo.getWallets().values().stream().sorted((Wallet o1, Wallet o2) -> o1.getName().compareTo(o2.getName()))
.collect(Collectors.toList());
}

public Ticker getTicker(CurrencyPair pair) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,12 @@ String getAlias() {
}

private KeySelectorResult getKeySelectorResult(final Key key) {
return new KeySelectorResult() {
public Key getKey() {
return key;
}
};
return () -> key;
}

private KeySelectorResult getNullKeyResult() {
if (nullKeyResult == null) {
nullKeyResult = new KeySelectorResult() {
public Key getKey() {
return null;
}
};
nullKeyResult = () -> null;
}
return nullKeyResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -100,37 +99,27 @@ public class ZooKeeperGroup<T extends NodeState> implements Group<T> {
private final AtomicBoolean unstable = new AtomicBoolean();
private volatile T state;

private final Watcher childrenWatcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
if (event.getType() != Event.EventType.None) {
// only interested in real change events, eg no refresh on Keeper.Disconnect
offerOperation(new RefreshOperation(ZooKeeperGroup.this, RefreshMode.STANDARD));
}
private final Watcher childrenWatcher = (WatchedEvent event) -> {
if (event.getType() != Watcher.Event.EventType.None) {
// only interested in real change events, eg no refresh on Keeper.Disconnect
offerOperation(new RefreshOperation(ZooKeeperGroup.this, RefreshMode.STANDARD));
}
};

private final Watcher dataWatcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
try {
if (event.getType() == Event.EventType.NodeDeleted) {
remove(event.getPath());
} else if (event.getType() == Event.EventType.NodeDataChanged) {
offerOperation(new GetDataOperation(ZooKeeperGroup.this, event.getPath()));
}
} catch (Exception e) {
handleException(e);
private final Watcher dataWatcher = (WatchedEvent event) -> {
try {
if (event.getType() == Watcher.Event.EventType.NodeDeleted) {
remove(event.getPath());
} else if (event.getType() == Watcher.Event.EventType.NodeDataChanged) {
offerOperation(new GetDataOperation(ZooKeeperGroup.this, event.getPath()));
}
} catch (Exception e) {
handleException(e);
}
};

private final ConnectionStateListener connectionStateListener = new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
handleStateChange(newState);
}
};
private final ConnectionStateListener connectionStateListener
= (CuratorFramework client, ConnectionState newState) -> handleStateChange(newState);

/**
* @param client the client
Expand Down Expand Up @@ -177,12 +166,7 @@ public void start() {
}

client.getConnectionStateListenable().addListener(connectionStateListener);
executorService.execute(new Runnable() {
@Override
public void run() {
mainLoop();
}
});
executorService.execute(this::mainLoop);
}
}

Expand Down Expand Up @@ -470,12 +454,7 @@ void refresh(final RefreshMode mode) throws Exception {
try {
ensurePath.ensure(client.getZookeeperClient());
List<String> children = client.getChildren().usingWatcher(childrenWatcher).forPath(path);
Collections.sort(children, new Comparator<String>() {
@Override
public int compare(String left, String right) {
return left.compareTo(right);
}
});
Collections.sort(children, (String left, String right) -> left.compareTo(right));
processChildren(children, mode);
} catch (Exception e) {
handleException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;

import org.apache.zookeeper.AsyncCallback.Children2Callback;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
Expand All @@ -42,9 +41,7 @@ public ChildrenChangedOperation(ZooKeeper connection, String znode, boolean getC

@Override
protected void installWatch() {
connection.getChildren(getNode(), this, new Children2Callback() {
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
}
connection.getChildren(getNode(), this, (int rc, String path, Object ctx, List<String> children, Stat stat) -> {
}, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.camel.component.zookeeper.operations;

import org.apache.zookeeper.AsyncCallback.DataCallback;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
Expand Down Expand Up @@ -45,9 +44,7 @@ public DataChangedOperation(ZooKeeper connection, String znode, boolean getChang

@Override
protected void installWatch() {
connection.getData(getNode(), this, new DataCallback() {
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
}
connection.getData(getNode(), this, (int rc, String path, Object ctx, byte[] data, Stat stat) -> {
}, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.camel.component.zookeeper.operations;

import org.apache.zookeeper.AsyncCallback.StatCallback;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
Expand All @@ -33,9 +32,7 @@ public ExistenceChangedOperation(ZooKeeper connection, String znode) {

@Override
protected void installWatch() {
connection.exists(getNode(), this, new StatCallback() {
public void processResult(int rc, String path, Object ctx, Stat stat) {
}
connection.exists(getNode(), this, (int rc, String path, Object ctx, Stat stat) -> {
}, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Installed exists watch");
Expand Down

0 comments on commit 277887d

Please sign in to comment.