Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnnecessaryLambda warnings #1363

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ tasks.withType(JavaCompile).configureEach {
options.errorprone.disable('StaticAssignmentInConstructor')
options.errorprone.disable('StringSplitter')
options.errorprone.disable('ThreadPriorityCheck')
options.errorprone.disable('UnnecessaryLambda')
options.errorprone.disable('UnusedMethod')
options.errorprone.disable('UnusedVariable')
options.compilerArgs += ['-Werror', '--enable-preview',
Expand Down
10 changes: 6 additions & 4 deletions java/org/contikios/cooja/plugins/PowerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.BiConsumer;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
Expand Down Expand Up @@ -306,7 +305,6 @@ public static class MoteTracker {
private Mote mote;
private Radio radio;

private final BiConsumer<Radio.RadioEvent, Radio> trigger = (event, radio) -> update();
MoteTracker(Mote mote) {
this.simulation = mote.getSimulation();
this.mote = mote;
Expand All @@ -323,7 +321,11 @@ public static class MoteTracker {
lastRadioState = RadioState.IDLE;
}
lastUpdateTime = simulation.getSimulationTime();
radio.getRadioEventTriggers().addTrigger(this, trigger);
radio.getRadioEventTriggers().addTrigger(this, this::trigger);
}

private void trigger(Radio.RadioEvent event, Radio radio) {
update();
}

void update() {
Expand Down Expand Up @@ -398,7 +400,7 @@ Mote getMote() {
}

void dispose() {
radio.getRadioEventTriggers().removeTrigger(this, trigger);
radio.getRadioEventTriggers().removeTrigger(this, this::trigger);
radio = null;
mote = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.util.function.BiConsumer;
import org.contikios.cooja.ClassDescription;
import org.contikios.cooja.Mote;
import org.contikios.cooja.Simulation;
Expand All @@ -60,34 +59,37 @@ public class AttributeVisualizerSkin implements VisualizerSkin {
private Simulation simulation;
private Visualizer visualizer;

private final BiConsumer<EventTriggers.AddRemoveUpdate, MoteAttributes.MoteAttributeUpdateData> attributesTrigger = (obs, obj) -> visualizer.repaint();
private final BiConsumer<EventTriggers.AddRemove, Mote> newMotesListener = (event, mote) -> {
private void newMotesListener(EventTriggers.AddRemove event, Mote mote) {
var intf = mote.getInterfaces().getInterfaceOfType(MoteAttributes.class);
if (intf != null) {
if (event == EventTriggers.AddRemove.ADD) {
intf.getAttributesTriggers().addTrigger(this, attributesTrigger);
intf.getAttributesTriggers().addTrigger(this, this::attributesTrigger);
} else {
intf.getAttributesTriggers().removeTrigger(this, attributesTrigger);
intf.getAttributesTriggers().removeTrigger(this, this::attributesTrigger);
}
}
};

private void attributesTrigger(EventTriggers.AddRemoveUpdate obs, MoteAttributes.MoteAttributeUpdateData obj) {
visualizer.repaint();
}

@Override
public void setActive(Simulation simulation, Visualizer vis) {
this.simulation = simulation;
this.visualizer = vis;

simulation.getMoteTriggers().addTrigger(this, newMotesListener);
simulation.getMoteTriggers().addTrigger(this, this::newMotesListener);
for (Mote m: simulation.getMotes()) {
newMotesListener.accept(EventTriggers.AddRemove.ADD, m);
newMotesListener(EventTriggers.AddRemove.ADD, m);
}
}

@Override
public void setInactive() {
simulation.getMoteTriggers().removeTrigger(this, newMotesListener);
simulation.getMoteTriggers().removeTrigger(this, this::newMotesListener);
for (Mote m: simulation.getMotes()) {
newMotesListener.accept(EventTriggers.AddRemove.REMOVE, m);
newMotesListener(EventTriggers.AddRemove.REMOVE, m);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import org.contikios.cooja.ClassDescription;
import org.contikios.cooja.Mote;
import org.contikios.cooja.RadioConnection;
Expand Down Expand Up @@ -67,7 +66,7 @@ public class TrafficVisualizerSkin implements VisualizerSkin {

private final List<RadioConnectionArrow> historyList = new ArrayList<>();

private final BiConsumer<Radio.RadioEvent, Object> radioMediumObserver = (event, obj) -> {
private void radioMediumObserver(Radio.RadioEvent event, Object obj) {
RadioConnection last = radioMedium.getLastConnection();
if (last != null && historyList.size() < MAX_HISTORY_SIZE) {
synchronized(historyList) {
Expand Down Expand Up @@ -109,7 +108,7 @@ public void setActive(final Simulation simulation, Visualizer vis) {
simulation.invokeSimulationThread(() -> {
historyList.clear();
/* Start observing radio medium for transmissions */
radioMedium.getRadioTransmissionTriggers().addTrigger(this, radioMediumObserver);
radioMedium.getRadioTransmissionTriggers().addTrigger(this, this::radioMediumObserver);
/* Fade away arrows */
simulation.scheduleEvent(ageArrowsTimeEvent, simulation.getSimulationTime() + 100*Simulation.MILLISECOND);
});
Expand All @@ -124,7 +123,7 @@ public void setInactive() {
}

/* Stop observing radio medium */
radioMedium.getRadioTransmissionTriggers().removeTrigger(this, radioMediumObserver);
radioMedium.getRadioTransmissionTriggers().removeTrigger(this, this::radioMediumObserver);
}

@Override
Expand Down