Skip to content

Commit

Permalink
fix sonarlint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-szarkowicz committed May 22, 2024
1 parent a9a172c commit 73ed9c3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
8 changes: 4 additions & 4 deletions test/core/src/temalab/communicator/Communicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public Communicator(Team team, String fileName, String strategy) {
this.team = team;
javaLogLabel = new Label(
team.getName() + " java",
Label.Color.Black,
team.getName() == "red" ? Label.Color.Red : Label.Color.White
Label.Color.BLACK,
team.getName().equals("red") ? Label.Color.RED : Label.Color.WHITE
);
pythonLogLabel = new Label(
team.getName() + " python",
Label.Color.Black,
team.getName() == "red" ? Label.Color.Red : Label.Color.White
Label.Color.BLACK,
team.getName().equals("red") ? Label.Color.RED : Label.Color.WHITE
);
String currDir = System.getProperty("user.dir");
ProcessBuilder processBuilder = new ProcessBuilder("python3", currDir + '/' + fileName, strategy);
Expand Down
13 changes: 8 additions & 5 deletions test/core/src/temalab/communicator/MainCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import temalab.common.MainModel;
import temalab.common.MainModelCommunicatorListener;
import temalab.logger.Label;
import temalab.logger.Log;

import java.util.ArrayList;
Expand All @@ -16,8 +17,11 @@ public class MainCommunicator implements MainModelCommunicatorListener {
private boolean runCommThread;
private Thread shutdownHook;

private final Label communicationLogLabel;

public MainCommunicator(MainModel mm) {
communictors = new ArrayList<>();
communicationLogLabel = new Label("Communication", Label.Color.NONE, Label.Color.NONE);
var teams = mm.getTeams();
for (var t : teams) {
communictors.add(new Communicator(t, "python/test1.py", t.getStrategy()));
Expand Down Expand Up @@ -54,7 +58,7 @@ private void communicate(MainModel mm) {
for (var c : communictors) {
c.communicate();
mm.controlPointsUpdate();
Log.d("Communication", "--------Egy kor lement--------");
Log.d(communicationLogLabel, "--------Egy kor lement--------");
if (manualResetEvent) {
pause = true;
}
Expand Down Expand Up @@ -88,14 +92,13 @@ public void change() {
if (pause) {
pause = false;
waiter.notifyAll();
Log.d("Communication", "RESUMED");
Log.d(communicationLogLabel, "RESUMED");
} else {
pause = true;
System.out.println("PAUSED");
Log.d("Communication", "PAUSED");
Log.d(communicationLogLabel, "PAUSED");
}
}
Log.d("Communication", "paused = " + pause);
Log.d(communicationLogLabel, "paused = " + pause);
}

@Override
Expand Down
24 changes: 12 additions & 12 deletions test/core/src/temalab/logger/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

public class Label {
public enum Color {
Black(30, 40),
Red(31, 41),
Green(32, 42),
Yellow(33, 43),
Blue(34, 44),
Magenta(35, 45),
Cyan(36, 46),
White(37, 47),
Default(39, 49),
None(0, 0);
BLACK(30, 40),
RED(31, 41),
GREEN(32, 42),
YELLOW(33, 43),
BLUE(34, 44),
MAGENTA(35, 45),
CYAN(36, 46),
WHITE(37, 47),
DEFAULT(39, 49),
NONE(0, 0);

final String foreground;
final String background;
Expand All @@ -28,7 +28,7 @@ public enum Color {
public Label(String label, Label.Color foregroundColor, Label.Color backgroundColor) {
this.label = label;
this.color =
(foregroundColor.equals(Label.Color.None) ? "" : foregroundColor.foreground)
+ (backgroundColor.equals(Label.Color.None) ? "" : backgroundColor.background);
(foregroundColor.equals(Label.Color.NONE) ? "" : foregroundColor.foreground)
+ (backgroundColor.equals(Label.Color.NONE) ? "" : backgroundColor.background);
}
}
26 changes: 13 additions & 13 deletions test/core/src/temalab/logger/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ public final class Log {
* The default logger is a {@link ConsoleLogger}.
* Use this method to change it.
*/
public void setLogger(Logger newLogger) {
public static synchronized void setLogger(Logger newLogger) {
logger = newLogger;
}

public synchronized static void d(String label, String message) {
public static synchronized void d(String label, String message) {
logger.debug(
new Label(label, Label.Color.None, Label.Color.None),
new Label(label, Label.Color.NONE, Label.Color.NONE),
message);
}

public synchronized static void i(String label, String message) {
public static synchronized void i(String label, String message) {
logger.info(
new Label(label, Label.Color.None, Label.Color.None),
new Label(label, Label.Color.NONE, Label.Color.NONE),
message);
}

public synchronized static void w(String label, String message) {
public static synchronized void w(String label, String message) {
logger.warning(
new Label(label, Label.Color.None, Label.Color.None),
new Label(label, Label.Color.NONE, Label.Color.NONE),
message);
}

public synchronized static void e(String label, String message) {
public static synchronized void e(String label, String message) {
logger.error(
new Label(label, Label.Color.None, Label.Color.None),
new Label(label, Label.Color.NONE, Label.Color.NONE),
message);
}

public synchronized static void d(Label label, String message) {
public static synchronized void d(Label label, String message) {
logger.debug(label, message);
}

public synchronized static void i(Label label, String message) {
public static synchronized void i(Label label, String message) {
logger.info(label, message);
}

public synchronized static void w(Label label, String message) {
public static synchronized void w(Label label, String message) {
logger.warning(label, message);
}

public synchronized static void e(Label label, String message) {
public static synchronized void e(Label label, String message) {
logger.error(label, message);
}
}
2 changes: 1 addition & 1 deletion test/core/src/temalab/logger/LoggerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected StackTraceElement getCallerStackTraceElement() {
var callIndex = 0;
var maxCallIndex = stackTrace.length - 2;
while (
stackTrace[callIndex].getClassName() != Log.class.getName()
!stackTrace[callIndex].getClassName().equals(Log.class.getName())
&& callIndex <= maxCallIndex
) {
++callIndex;
Expand Down
Binary file added test/tests/build/libs/tests-1.0.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions test/tests/build/tmp/jar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

0 comments on commit 73ed9c3

Please sign in to comment.