Skip to content

Commit

Permalink
Fix sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Oct 6, 2024
1 parent 1e43d25 commit 2b50559
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface MonthDataStorage extends PluginFeature
/**
* A {@link ModelFactory} allows creating new instances of the data model.
*/
public interface ModelFactory
interface ModelFactory
{
/**
* Create a new {@link MonthData} instance.
Expand All @@ -82,4 +82,4 @@ public interface ModelFactory
*/
ActivityData createActivityData();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public interface ActivityData
* the new comment.
*/
void setComment(String comment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ public interface DayData
* new new activities.
*/
void setActivities(List<ActivityData> activities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum DayType

private final boolean workDay;

private DayType(final boolean workDay)
DayType(final boolean workDay)
{
this.workDay = workDay;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ public interface MonthData
* the new {@link DayData}s.
*/
void setDays(List<DayData> days);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public interface Project
* @return the cost carrier of this project.
*/
String getCostCarrier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public interface ProjectReport
* @return the activities in this project report.
*/
List<ProjectReportActivity> getProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javafx.application.Platform;

public class JavaFxUtil
public final class JavaFxUtil
{
private JavaFxUtil()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ else if (os.indexOf("linux") >= 0)
{
return OSType.LINUX;
}
return OSType.OTHER;
else
{
return OSType.OTHER;
}
}

public boolean isDesktopSupported()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import javafx.stage.Modality;
import javafx.stage.Stage;

public class UiActions
public final class UiActions
{
private static final Logger LOG = LogManager.getLogger(UiActions.class);

Expand Down Expand Up @@ -95,7 +95,7 @@ private void createAndOpenDirectory(final Path directory)
openFileWithDefaultProgram(directory);
}

private void createDir(final Path directory)
private static void createDir(final Path directory)
{
try
{
Expand Down Expand Up @@ -195,14 +195,14 @@ private String formatAboutHeaderText()
return "White Rabbit version " + properties.getVersion() + " (" + properties.getBuildDate() + ")";
}

private String formatSystemPropertyValues(final Map<String, String> properties)
private static String formatSystemPropertyValues(final Map<String, String> properties)
{
return properties.entrySet().stream() //
.map(entry -> entry.getKey() + ": " + System.getProperty(entry.getValue())) //
.collect(joining("\n"));
}

private Map<String, String> getProperties()
private static Map<String, String> getProperties()
{
final Map<String, String> properties = new LinkedHashMap<>();
properties.put("Java Vendor", "java.vendor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import javafx.beans.property.SimpleObjectProperty;

public class ClockPropertyFactory
public final class ClockPropertyFactory
{
private static final Logger LOG = LogManager.getLogger(ClockPropertyFactory.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public interface DesktopService
{

static DesktopService create()
{
final Logger log = LogManager.getLogger(DesktopService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class RealDesktopService implements DesktopService
private static final Logger LOG = LogManager.getLogger(RealDesktopService.class);
private final Desktop desktop;

RealDesktopService(Desktop desktop)
RealDesktopService(final Desktop desktop)
{
this.desktop = desktop;
}

@Override
public void open(Path file)
public void open(final Path file)
{
SwingUtil.invokeInAwtEventQueue(() -> {
LOG.info("Opening file {} with default application", file);
Expand All @@ -34,4 +34,4 @@ public void open(Path file)
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class SplashScreenLoader extends Preloader
{
private static final Logger LOG = LogManager.getLogger(SplashScreenLoader.class);

private Stage splashScreen;
private Stage splashScreen = null;

@Override
public void start(Stage stage)
public void start(final Stage stage)
{
splashScreen = stage;
splashScreen.initStyle(StageStyle.UNDECORATED);
Expand All @@ -49,7 +49,7 @@ public Scene createScene()
return new Scene(root, 300, 300);
}

private Image loadImage(String resourceName)
private Image loadImage(final String resourceName)
{
try (InputStream iconStream = getClass().getResourceAsStream(resourceName))
{
Expand All @@ -62,11 +62,10 @@ private Image loadImage(String resourceName)
}

@Override
public void handleApplicationNotification(PreloaderNotification notification)
public void handleApplicationNotification(final PreloaderNotification notification)
{
if (notification instanceof ProgressPreloaderNotification)
if (notification instanceof final ProgressPreloaderNotification progressNotification)
{
final ProgressPreloaderNotification progressNotification = (ProgressPreloaderNotification) notification;
LOG.debug("Preloader application notification: {}", progressNotification.getNotificationType());
if (progressNotification.getNotificationType() == Type.STARTUP_FINISHED)
{
Expand All @@ -81,23 +80,23 @@ public void handleApplicationNotification(PreloaderNotification notification)
}

@Override
public boolean handleErrorNotification(ErrorNotification info)
public boolean handleErrorNotification(final ErrorNotification info)
{
splashScreen.hide();
final Alert alert = createAlert(info);
alert.showAndWait();
return false;
}

private Alert createAlert(ErrorNotification info)
private static Alert createAlert(final ErrorNotification info)
{
final Throwable exception = info.getCause();
if (exception instanceof OtherInstanceAlreadyRunningException)
{
final String message = "Another instance of WhiteRabbit is already running.\n\n" + exception.getMessage();
return new Alert(AlertType.WARNING, message, ButtonType.OK);
}
final String location = info.getLocation() != null ? info.getLocation() + "\n" : "";
final String location = info.getLocation() != null ? (info.getLocation() + "\n") : "";
final String message = "Error during initialization: " + location + info.getDetails() + "\n" + exception;
LOG.error(message, exception);
return new Alert(AlertType.ERROR, message, ButtonType.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

public interface DesktopIntegration
{
public static DesktopIntegration getInstance()
static DesktopIntegration getInstance()
{
return StaticInstanceHolder.getInstance();
}

void register();

void setUiActions(UiActions actions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.itsallcode.whiterabbit.jfxui.OsCheck;

class StaticInstanceHolder
final class StaticInstanceHolder
{
private static DesktopIntegration instance;

Expand All @@ -26,7 +26,7 @@ static class InstanceFactory
{
private final OsCheck osCheck;

InstanceFactory(OsCheck osCheck)
InstanceFactory(final OsCheck osCheck)
{
this.osCheck = osCheck;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ public class DelegatingChangeListener<T> implements ChangeListener<T>
private final ChangeListener<T> delegate;
private final BooleanProperty currentlyUpdating;

public DelegatingChangeListener(ChangeListener<T> delegate, BooleanProperty currentlyUpdating)
public DelegatingChangeListener(final ChangeListener<T> delegate, final BooleanProperty currentlyUpdating)
{
this.delegate = delegate;
this.currentlyUpdating = currentlyUpdating;
}

@Override
public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue)
public void changed(final ObservableValue<? extends T> observable, final T oldValue, final T newValue)
{
if (!currentlyUpdating.get())
{
delegate.changed(observable, oldValue, newValue);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
public class DayTypeStringConverter extends StringConverter<DayType>
{
@Override
public String toString(DayType object)
public String toString(final DayType object)
{
return object != null ? object.name() : null;
}

@Override
public DayType fromString(String string)
public DayType fromString(final String string)
{
return DayType.valueOf(string);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void exportButtonsFromPluginsAvailable()
{
time().tickSeparateMinutes(2);
final DailyProjectReportWindow report = app().openDailyProjectReport();
report.assertExportButtons("Export to demo", "Export to pmsmart");
report.assertExportButtons("Export to demo", "Export to csv");
report.closeViaEscKey();
}

Expand All @@ -72,7 +72,7 @@ void filledProjectReport()

@Override
@Start
void start(Stage stage)
void start(final Stage stage)
{
setLocale(Locale.GERMANY);
setInitialTime(Instant.parse("2007-12-03T10:15:30.20Z"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static PluginOrigin forJar(final Path jar)

private static ClassLoader getBaseClassLoader()
{
return PluginOrigin.class.getClassLoader();
return Thread.currentThread().getContextClassLoader();
}

private static ClassLoader createClassLoader(final Path jar)
Expand Down

0 comments on commit 2b50559

Please sign in to comment.