Skip to content

Commit d01b8ef

Browse files
committed
did many small tasks to solve minor sonar issues
1 parent 65083f9 commit d01b8ef

File tree

16 files changed

+370
-418
lines changed

16 files changed

+370
-418
lines changed

src/main/java/de/doubleslash/keeptime/DefaultExceptionHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
*/
1313
public class DefaultExceptionHandler implements UncaughtExceptionHandler {
1414

15-
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
15+
private final Logger log = LoggerFactory.getLogger(this.getClass());
1616

1717
@Override
1818
public void uncaughtException(final Thread t, final Throwable e) {
19-
LOG.error("Uncaught exception on thread '{}'.", t, e);
19+
log.error("Uncaught exception on thread '{}'.", t, e);
2020
}
2121

2222
/**
2323
* Registers this class as default uncaught exception handler
2424
*/
2525
public void register() {
26-
LOG.debug("Registering uncaught exception handler");
26+
log.debug("Registering uncaught exception handler");
2727
final UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
2828
if (defaultUncaughtExceptionHandler != null) {
29-
LOG.warn("Uncaught exception handler was already set ('{}'). Overwritting.", defaultUncaughtExceptionHandler);
29+
log.warn("Uncaught exception handler was already set ('{}'). Overwritting.", defaultUncaughtExceptionHandler);
3030
}
3131
Thread.setDefaultUncaughtExceptionHandler(this);
3232
}

src/main/java/de/doubleslash/keeptime/Main.java

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import de.doubleslash.keeptime.model.Settings;
2121
import de.doubleslash.keeptime.model.Work;
2222
import de.doubleslash.keeptime.view.ViewController;
23-
import de.doubleslash.keeptime.viewPopup.GlobalScreenListener;
24-
import de.doubleslash.keeptime.viewPopup.ViewControllerPopup;
23+
import de.doubleslash.keeptime.viewpopup.GlobalScreenListener;
24+
import de.doubleslash.keeptime.viewpopup.ViewControllerPopup;
2525
import javafx.application.Application;
2626
import javafx.fxml.FXMLLoader;
2727
import javafx.scene.Parent;
@@ -34,7 +34,7 @@
3434
@SpringBootApplication
3535
public class Main extends Application {
3636

37-
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
37+
private final Logger log = LoggerFactory.getLogger(this.getClass());
3838

3939
public static final String VERSION = "v0.0.2";
4040

@@ -47,7 +47,7 @@ public class Main extends Application {
4747

4848
@Override
4949
public void init() throws Exception {
50-
LOG.info("Starting KeepTime {}", VERSION);
50+
log.info("Starting KeepTime {}", VERSION);
5151
final DefaultExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler();
5252
defaultExceptionHandler.register();
5353

@@ -60,14 +60,14 @@ public void init() throws Exception {
6060
@Override
6161
public void start(final Stage primaryStage) throws Exception {
6262

63-
LOG.debug("Reading configuration");
63+
log.debug("Reading configuration");
6464

6565
// TODO there should just be one instance of settings in the repo
66-
final List<Settings> settingsList = model.settingsRepository.findAll();
66+
final List<Settings> settingsList = model.getSettingsRepository().findAll();
6767
final Settings settings;
6868
if (settingsList.isEmpty()) {
6969
settings = new Settings();
70-
settings.setTaskBarColor(model.taskBarColor.get());
70+
settings.setTaskBarColor(Model.TASK_BAR_COLOR.get());
7171

7272
settings.setDefaultBackgroundColor(model.defaultBackgroundColor.get());
7373
settings.setDefaultFontColor(model.defaultFontColor.get());
@@ -76,7 +76,7 @@ public void start(final Stage primaryStage) throws Exception {
7676
settings.setHoverFontColor(model.hoverFontColor.get());
7777
settings.setUseHotkey(false);
7878
settings.setDisplayProjectsRight(true);
79-
model.settingsRepository.save(settings);
79+
model.getSettingsRepository().save(settings);
8080
} else {
8181
settings = settingsList.get(0);
8282
}
@@ -85,21 +85,21 @@ public void start(final Stage primaryStage) throws Exception {
8585
model.defaultFontColor.set(settings.getDefaultFontColor());
8686
model.hoverBackgroundColor.set(settings.getHoverBackgroundColor());
8787
model.hoverFontColor.set(settings.getHoverFontColor());
88-
model.taskBarColor.set(settings.getTaskBarColor());
89-
model.useHotkey.set(settings.isUseHotkey());
88+
Model.TASK_BAR_COLOR.set(settings.getTaskBarColor());
89+
Model.USE_HOTKEY.set(settings.isUseHotkey());
9090
model.displayProjectsRight.set(settings.isDisplayProjectsRight());
9191

92-
final List<Work> todaysWorkItems = model.workRepository.findByCreationDate(LocalDate.now());
93-
LOG.info("Found {} past work items", todaysWorkItems.size());
94-
model.pastWorkItems.addAll(todaysWorkItems);
92+
final List<Work> todaysWorkItems = model.getWorkRepository().findByCreationDate(LocalDate.now());
93+
log.info("Found {} past work items", todaysWorkItems.size());
94+
model.getPastWorkItems().addAll(todaysWorkItems);
9595

96-
final List<Project> projects = model.projectRepository.findAll();
96+
final List<Project> projects = model.getProjectRepository().findAll();
9797

98-
LOG.debug("Found '{}' projects", projects.size());
98+
log.debug("Found '{}' projects", projects.size());
9999
if (projects.isEmpty()) {
100-
LOG.info("Adding default project");
101-
projects.add(model.DEFAULT_PROJECT);
102-
model.projectRepository.save(model.DEFAULT_PROJECT);
100+
log.info("Adding default project");
101+
projects.add(Model.DEFAULT_PROJECT);
102+
model.getProjectRepository().save(Model.DEFAULT_PROJECT);
103103
}
104104

105105
model.allProjects.addAll(projects);
@@ -109,25 +109,25 @@ public void start(final Stage primaryStage) throws Exception {
109109
// set default project
110110
final Optional<Project> findAny = projects.stream().filter(p -> p.isDefault()).findAny();
111111
if (findAny.isPresent()) {
112-
model.idleProject = findAny.get();
113-
LOG.debug("Using project '{}' as default project.", model.idleProject);
112+
Model.idleProject = findAny.get();
113+
log.debug("Using project '{}' as default project.", Model.idleProject);
114114
}
115115

116-
primaryStage.setOnHiding((we) -> {
116+
primaryStage.setOnHiding(we -> {
117117
popupViewStage.close();
118118
globalScreenListener.register(false); // deregister, as this will keep app running
119119
});
120120

121121
try {
122122
initialiseUI(primaryStage);
123123
} catch (final Exception e) {
124-
LOG.error(e.getMessage());
124+
log.error(e.getMessage());
125125
}
126126

127127
try {
128128
initialisePopupUI(primaryStage);
129129
} catch (final Exception e) {
130-
LOG.error(e.getMessage());
130+
log.error(e.getMessage());
131131
}
132132
}
133133

@@ -137,10 +137,8 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
137137
// TODO register only if it is enabled
138138
globalScreenListener = new GlobalScreenListener();
139139
// TODO stop and close stage when main stage is shutdown
140-
model.useHotkey.addListener((a, b, newValue) -> {
141-
globalScreenListener.register(newValue);
142-
});
143-
globalScreenListener.register(model.useHotkey.get());
140+
Model.USE_HOTKEY.addListener((a, b, newValue) -> globalScreenListener.register(newValue));
141+
globalScreenListener.register(Model.USE_HOTKEY.get());
144142

145143
// Platform.setImplicitExit(false); // TODO maybe not needed as other view will be available
146144
popupViewStage = new Stage();
@@ -158,7 +156,7 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
158156
// Give the controller access to the main app.
159157
popupViewStage.setAlwaysOnTop(true);
160158
final ViewControllerPopup viewControllerPopupController = loader.getController();
161-
viewControllerPopupController.setStage(popupViewStage, popupScene);
159+
viewControllerPopupController.setStage(popupViewStage);
162160
viewControllerPopupController.setController(controller, model);
163161
globalScreenListener.setViewController(viewControllerPopupController);
164162

@@ -184,7 +182,7 @@ private void initialiseUI(final Stage primaryStage) {
184182
primaryStage.setAlwaysOnTop(true);
185183
primaryStage.setResizable(false);
186184

187-
primaryStage.setOnCloseRequest(actionEvent -> LOG.info("On close request"));
185+
primaryStage.setOnCloseRequest(actionEvent -> log.info("On close request"));
188186

189187
viewController = loader.getController();
190188
// Give the controller access to the main app.
@@ -197,7 +195,7 @@ private void initialiseUI(final Stage primaryStage) {
197195
} catch (
198196

199197
final Exception e) {
200-
LOG.error("Error: " + e.toString(), e);
198+
log.error("Error: " + e.toString(), e);
201199
}
202200
}
203201

src/main/java/de/doubleslash/keeptime/common/ConfigParser.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import javafx.scene.paint.Color;
1818

1919
public class ConfigParser {
20-
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
20+
private final Logger log = LoggerFactory.getLogger(this.getClass());
2121

2222
private final Controller controller;
2323

@@ -31,13 +31,13 @@ public static boolean hasConfigFile(final String fileName) {
3131
}
3232

3333
public void parseConfig(final File inputFile) {
34-
LOG.info("Starting import of projects in file '{}'.", inputFile);
34+
log.info("Starting import of projects in file '{}'.", inputFile);
3535
try {
3636
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
3737
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
3838
final Document doc = dBuilder.parse(inputFile);
3939
doc.getDocumentElement().normalize();
40-
LOG.debug("Root element '{}'.", doc.getDocumentElement().getNodeName());
40+
log.debug("Root element '{}'.", doc.getDocumentElement().getNodeName());
4141
final NodeList nList = doc.getElementsByTagName("project");
4242

4343
// index makes sure to add new projects at the end
@@ -51,7 +51,7 @@ public void parseConfig(final File inputFile) {
5151
final String isWork = eElement.getElementsByTagName("isWork").item(0).getTextContent();
5252
final String color = eElement.getElementsByTagName("color").item(0).getTextContent();
5353

54-
LOG.debug("Testing if project with name '{}' already exists.", name);
54+
log.debug("Testing if project with name '{}' already exists.", name);
5555
boolean exists = false;
5656

5757
for (final Project p : controller.getAvailableProjects()) {
@@ -61,19 +61,19 @@ public void parseConfig(final File inputFile) {
6161
}
6262
}
6363
if (!exists) {
64-
LOG.info("Adding project '{}'.", name);
64+
log.info("Adding project '{}'.", name);
6565
final Color colorTemp = Color.valueOf(color);
6666
controller.addNewProject(name, Boolean.parseBoolean(isWork), colorTemp, index);
6767
index++;
6868
} else {
69-
LOG.debug("Project '{}' already exists", name);
69+
log.debug("Project '{}' already exists", name);
7070
}
7171

7272
}
7373
}
74-
LOG.info("Import of '{}' finished.", inputFile);
74+
log.info("Import of '{}' finished.", inputFile);
7575
} catch (final Exception e) {
76-
LOG.error("There was an error while importing projects from config.xml", e);
76+
log.error("There was an error while importing projects from config.xml", e);
7777
}
7878
}
7979
}

src/main/java/de/doubleslash/keeptime/common/Resources.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ public String getResourceLocation() {
3030

3131
public static URL getResource(final RESOURCE resource) {
3232
return Resources.class.getResource(resource.getResourceLocation());
33-
// return ClassLoader.getSystemResource(resource.getResourceLocation());
3433
}
3534
}

0 commit comments

Comments
 (0)