Skip to content

Commit f106dcc

Browse files
author
Bytekeeper
committed
Inspection fixes and upgrade of most libraries and some more whacky hacks to make JavaFX tests work.
1 parent 41ed1db commit f106dcc

File tree

17 files changed

+78
-85
lines changed

17 files changed

+78
-85
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: java
22
jdk:
33
- oraclejdk8
44
addons:
5-
sonarqube:
5+
sonarcloud:
66
branches:
77
- dev
88
- master

build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
9+
classpath 'com.github.ben-manes:gradle-versions-plugin:0.16.0'
1010
}
1111
}
1212

1313
plugins {
14-
id "net.ltgt.apt" version "0.10"
14+
id "net.ltgt.apt-idea" version "0.12"
1515
id "org.sonarqube" version "2.5"
1616
}
1717

@@ -56,17 +56,17 @@ configurations {
5656
dependencies {
5757
antlr group: "org.antlr", name: "antlr4", version: "4.7"
5858
compile group: "org.antlr", name: "antlr4-runtime", version: "4.7"
59-
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.7-M5'
60-
compile 'org.yaml:snakeyaml:1.18'
61-
compile 'com.google.dagger:dagger:2.11'
59+
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.8.0'
60+
compile 'org.yaml:snakeyaml:1.19'
61+
compile 'com.google.dagger:dagger:2.12'
6262
compile 'javax.inject:javax.inject:1'
63-
apt 'com.google.dagger:dagger-compiler:2.11'
63+
apt 'com.google.dagger:dagger-compiler:2.12'
6464
compile 'net.engio:mbassador:1.3.1'
6565
compile 'org.controlsfx:controlsfx:8.40.14'
6666
compile 'net.rcarz:jira-client:0.5'
67-
compile 'com.jsoniter:jsoniter:0.9.15'
67+
compile 'com.jsoniter:jsoniter:0.9.17'
6868

69-
testCompile 'commons-io:commons-io:2.5'
69+
testCompile 'commons-io:commons-io:2.6'
7070
testCompile 'junit:junit-dep:4.11'
7171
testCompile 'org.hamcrest:hamcrest-core:1.3'
7272
testCompile 'org.hamcrest:hamcrest-library:1.3'
@@ -96,7 +96,7 @@ tasks.withType(FindBugs) {
9696
}
9797

9898
task wrapper(type: Wrapper) {
99-
gradleVersion = '3.5'
99+
gradleVersion = '4.2.1'
100100
}
101101

102102
task release(dependsOn: 'distZip') {

gradle/wrapper/gradle-wrapper.jar

504 Bytes
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Mar 22 22:45:21 WAT 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip

gradlew

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/stt/command/Activities.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,28 @@ public void removeActivityAndCloseGap(RemoveActivity command) {
9797
Optional<TimeTrackingItem> previous = adjacentItems.previousItem();
9898
Optional<TimeTrackingItem> next = adjacentItems.nextItem();
9999

100-
if (previousAndNextActivitiesMatch(previous, next)) {
101-
TimeTrackingItem replaceAllWith = next.get().getEnd()
102-
.map(previous.get()::withEnd).orElse(previous.get().withPendingEnd());
103-
persister.persist(replaceAllWith);
104-
publisher.publish(new ItemInserted(replaceAllWith));
105-
} else if (previous.isPresent()
106-
&& DateTimes.isOnSameDay(previous.get().getStart(), command.itemToDelete.getStart())
107-
&& !command.itemToDelete.getEnd().isPresent()) {
108-
TimeTrackingItem replaceAllWith = previous.get().withPendingEnd();
109-
persister.persist(replaceAllWith);
110-
publisher.publish(new ItemInserted(replaceAllWith));
111-
} else {
112-
removeActivity(command);
100+
if (previous.isPresent()) {
101+
TimeTrackingItem previousItem = previous.get();
102+
if (next.isPresent() && previousAndNextActivitiesMatch(previousItem, next.get())) {
103+
TimeTrackingItem replaceAllWith = next.get().getEnd()
104+
.map(previousItem::withEnd).orElse(previousItem.withPendingEnd());
105+
persister.persist(replaceAllWith);
106+
publisher.publish(new ItemInserted(replaceAllWith));
107+
return;
108+
}
109+
if (DateTimes.isOnSameDay(previousItem.getStart(), command.itemToDelete.getStart())
110+
&& !command.itemToDelete.getEnd().isPresent()) {
111+
TimeTrackingItem replaceAllWith = previousItem.withPendingEnd();
112+
persister.persist(replaceAllWith);
113+
publisher.publish(new ItemInserted(replaceAllWith));
114+
return;
115+
}
113116
}
117+
removeActivity(command);
114118
}
115119

116-
private boolean previousAndNextActivitiesMatch(Optional<TimeTrackingItem> previous, Optional<TimeTrackingItem> next) {
117-
return previous.isPresent() && next.isPresent()
118-
&& previous.get().getActivity().equals(next.get().getActivity());
120+
private boolean previousAndNextActivitiesMatch(TimeTrackingItem previousItem, TimeTrackingItem nextItem) {
121+
return previousItem.getActivity().equals(nextItem.getActivity());
119122
}
120123

121124
@Override

src/main/java/org/stt/gui/jfx/JFXModule.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ static ActivityTextDisplayProcessor hyperlinkMapper(ExecutorService executorServ
105105
});
106106
}
107107

108-
private static Stream<?> toHyperlink(ExecutorService executorService, String o) {
108+
private static Stream<?> toHyperlink(ExecutorService executorService, String activity) {
109109
List<Object> result = new ArrayList<>();
110-
String string = o;
111-
Matcher matcher = URL_PATTERN.matcher(string);
110+
Matcher matcher = URL_PATTERN.matcher(activity);
112111
int index = 0;
113112
while (matcher.find(index)) {
114-
String preamble = string.substring(index, matcher.start());
113+
String preamble = activity.substring(index, matcher.start());
115114
if (!preamble.isEmpty()) {
116115
result.add(preamble);
117116
}
118-
String uri = string.substring(matcher.start(), matcher.end());
117+
String uri = activity.substring(matcher.start(), matcher.end());
119118
Hyperlink hyperlink = new Hyperlink(uri);
120119
hyperlink.setOnAction(event -> executorService.submit(() -> {
121120
try {
@@ -127,7 +126,7 @@ private static Stream<?> toHyperlink(ExecutorService executorService, String o)
127126
result.add(hyperlink);
128127
index = matcher.end();
129128
}
130-
result.add(string.substring(index));
129+
result.add(activity.substring(index));
131130
return result.stream();
132131
}
133132

src/main/java/org/stt/gui/jfx/text/CommandHighlighter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void update() {
4545
TokenStream tokenStream = new CommonTokenStream(lexer);
4646
EnglishCommandsParser parser = new EnglishCommandsParser(tokenStream);
4747
parser.command().accept(visitor);
48-
ItemGrouper.Group[] groups = itemGrouper.getGroupsOf(text).stream().toArray(ItemGrouper.Group[]::new);
48+
ItemGrouper.Group[] groups = itemGrouper.getGroupsOf(text).toArray(new ItemGrouper.Group[0]);
4949
for (int i = 0; i < groups.length - 1; i++) {
5050
ItemGrouper.Group group = groups[i];
5151
if (group.type == ItemGrouper.Type.MATCH) {

src/main/java/org/stt/model/TimeTrackingItem.java

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.stt.time.DateTimes;
44

55
import java.time.LocalDateTime;
6+
import java.util.Objects;
67
import java.util.Optional;
78

89
import static java.util.Objects.requireNonNull;
@@ -12,7 +13,7 @@
1213
public final class TimeTrackingItem {
1314
private final String activity;
1415
private final LocalDateTime start;
15-
private final Optional<LocalDateTime> end;
16+
private final LocalDateTime end;
1617

1718
/**
1819
* @param activity activity string describing this item.
@@ -21,9 +22,9 @@ public final class TimeTrackingItem {
2122
*/
2223
public TimeTrackingItem(String activity, LocalDateTime start, LocalDateTime end) {
2324
this.activity = requireNonNull(activity);
24-
this.start = requireNonNull(start, "start must not be null");
25-
this.end = Optional.of(DateTimes.preciseToSecond(end));
26-
requireThat(!end.isBefore(DateTimes.preciseToSecond(start)),
25+
this.start = DateTimes.preciseToSecond(requireNonNull(start, "start must not be null"));
26+
this.end = DateTimes.preciseToSecond(requireNonNull(end, "end must not be null"));
27+
requireThat(!end.isBefore(start),
2728
"end must not be before start for item!");
2829
}
2930

@@ -34,13 +35,12 @@ public TimeTrackingItem(String activity, LocalDateTime start, LocalDateTime end)
3435
public TimeTrackingItem(String activity, LocalDateTime start) {
3536
this.activity = requireNonNull(activity);
3637
this.start = DateTimes.preciseToSecond(requireNonNull(start));
37-
this.end = Optional.empty();
38+
this.end = null;
3839
}
3940

4041
public boolean sameEndAs(TimeTrackingItem other) {
41-
return getEnd()
42-
.map(endA -> other.getEnd().map(endA::equals).orElse(false))
43-
.orElse(!other.getEnd().isPresent());
42+
return end == other.end
43+
|| end != null && end.equals(other.end);
4444
}
4545

4646
public boolean sameActivityAs(TimeTrackingItem other) {
@@ -52,19 +52,16 @@ public boolean sameStartAs(TimeTrackingItem other) {
5252
}
5353

5454
public boolean intersects(TimeTrackingItem other) {
55-
return other.getEnd().map(actualEnd -> actualEnd.isAfter(start)).orElse(true)
56-
&& end.map(actualEnd -> actualEnd.isAfter(other.start)).orElse(true);
55+
return (end == null || end.isAfter(other.start))
56+
&& (other.end == null || other.end.isAfter(start));
5757
}
5858

5959
public boolean endsSameOrAfter(TimeTrackingItem other) {
60-
return end.map(actualEnd -> other.getEnd().map(otherEnd -> !actualEnd.isBefore(otherEnd))
61-
.orElse(false))
62-
.orElse(true);
60+
return end == null || other.end != null && !end.isBefore(other.end);
6361
}
6462

6563
public boolean endsAtOrBefore(LocalDateTime dateTime) {
66-
return end.map(actualEnd -> !dateTime.isBefore(actualEnd))
67-
.orElse(false);
64+
return end != null && !dateTime.isBefore(end);
6865
}
6966

7067
public String getActivity() {
@@ -76,35 +73,30 @@ public LocalDateTime getStart() {
7673
}
7774

7875
public Optional<LocalDateTime> getEnd() {
79-
return end;
76+
return Optional.ofNullable(end);
8077
}
8178

8279

8380
@Override
8481
public String toString() {
8582
return start.toString() + " - "
86-
+ (end.isPresent() ? end.get().toString() : "null") + " : "
83+
+ (end == null ? "null" : end.toString()) + " : "
8784
+ activity;
8885
}
8986

9087
@Override
9188
public boolean equals(Object o) {
9289
if (this == o) return true;
9390
if (o == null || getClass() != o.getClass()) return false;
94-
9591
TimeTrackingItem that = (TimeTrackingItem) o;
96-
97-
if (!activity.equals(that.activity)) return false;
98-
if (!start.equals(that.start)) return false;
99-
return end.equals(that.end);
92+
return Objects.equals(activity, that.activity) &&
93+
Objects.equals(start, that.start) &&
94+
Objects.equals(end, that.end);
10095
}
10196

10297
@Override
10398
public int hashCode() {
104-
int result = activity.hashCode();
105-
result = 31 * result + start.hashCode();
106-
result = 31 * result + end.hashCode();
107-
return result;
99+
return Objects.hash(activity, start, end);
108100
}
109101

110102
public TimeTrackingItem withEnd(LocalDateTime newEnd) {
@@ -118,13 +110,13 @@ public TimeTrackingItem withPendingEnd() {
118110

119111
public TimeTrackingItem withStart(LocalDateTime newStart) {
120112
requireNonNull(newStart);
121-
return end.map(time -> new TimeTrackingItem(activity, newStart, time))
122-
.orElse(new TimeTrackingItem(activity, newStart));
113+
return end != null ? new TimeTrackingItem(activity, newStart, end)
114+
: new TimeTrackingItem(activity, newStart);
123115
}
124116

125117
public TimeTrackingItem withActivity(String newActivity) {
126118
requireNonNull(newActivity);
127-
return end.map(time -> new TimeTrackingItem(newActivity, start, time))
128-
.orElse(new TimeTrackingItem(newActivity, start));
119+
return end != null ? new TimeTrackingItem(newActivity, start, end)
120+
: new TimeTrackingItem(newActivity, start);
129121
}
130122
}

src/main/java/org/stt/persistence/ItemReader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.stt.model.TimeTrackingItem;
44

55
import java.io.Closeable;
6-
import java.io.IOException;
76
import java.util.Optional;
87

98
/**
@@ -22,7 +21,6 @@ public interface ItemReader extends Closeable {
2221
*
2322
* @return An {@link Optional} of the {@link TimeTrackingItem} or absent if
2423
* none is available
25-
* @throws IOException
2624
*/
2725
Optional<TimeTrackingItem> read();
2826

0 commit comments

Comments
 (0)