Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 475d09b

Browse filesBrowse files
committed
- Made an AbstractLogger superclass
- Moved text logging capabilities to TextLogPaneExporter - Added reference to specific Calculation in log entries - Separated MVC functions in logging
1 parent 20a93b1 commit 475d09b
Copy full SHA for 475d09b

File tree

Expand file treeCollapse file tree

10 files changed

+212
-165
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+212
-165
lines changed

‎src/main/java/pulse/io/export/LogPaneExporter.java renamed to ‎src/main/java/pulse/io/export/TextLogPaneExporter.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/io/export/TextLogPaneExporter.java
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44

55
import java.io.FileOutputStream;
66
import java.io.IOException;
7+
import javax.swing.JEditorPane;
78

89
import javax.swing.text.BadLocationException;
910
import javax.swing.text.html.HTMLEditorKit;
1011

11-
import pulse.ui.components.LogPane;
12+
import pulse.ui.components.TextLogPane;
1213

1314
/**
1415
* Similar to a {@code LogExporter}, except that it works only on the contents
1516
* of a {@code LogPane} currently being displayed to the user.
1617
*
1718
*/
18-
public class LogPaneExporter implements Exporter<LogPane> {
19+
public class TextLogPaneExporter implements Exporter<TextLogPane> {
1920

20-
private static LogPaneExporter instance = new LogPaneExporter();
21+
private static TextLogPaneExporter instance = new TextLogPaneExporter();
2122

22-
private LogPaneExporter() {
23+
private TextLogPaneExporter() {
2324
// intentionally blank
2425
}
2526

@@ -29,10 +30,11 @@ private LogPaneExporter() {
2930
* argument is ignored. After exporting, the stream is explicitly closed.
3031
*/
3132
@Override
32-
public void printToStream(LogPane pane, FileOutputStream fos, Extension extension) {
33-
var kit = (HTMLEditorKit) pane.getEditorKit();
33+
public void printToStream(TextLogPane pane, FileOutputStream fos, Extension extension) {
34+
var editorPane = (JEditorPane) pane.getGUIComponent();
35+
var kit = (HTMLEditorKit) editorPane.getEditorKit();
3436
try {
35-
kit.write(fos, pane.getDocument(), 0, pane.getDocument().getLength());
37+
kit.write(fos, editorPane.getDocument(), 0, editorPane.getDocument().getLength());
3638
} catch (IOException | BadLocationException e) {
3739
System.err.println("Could not export the log pane!");
3840
e.printStackTrace();
@@ -50,16 +52,16 @@ public void printToStream(LogPane pane, FileOutputStream fos, Extension extensio
5052
*
5153
* @return an instance of{@code LogPaneExporter}.
5254
*/
53-
public static LogPaneExporter getInstance() {
55+
public static TextLogPaneExporter getInstance() {
5456
return instance;
5557
}
5658

5759
/**
5860
* @return {@code LogPane.class}.
5961
*/
6062
@Override
61-
public Class<LogPane> target() {
62-
return LogPane.class;
63+
public Class<TextLogPane> target() {
64+
return TextLogPane.class;
6365
}
6466

6567
/**
@@ -70,4 +72,4 @@ public Extension[] getSupportedExtensions() {
7072
return new Extension[]{HTML};
7173
}
7274

73-
}
75+
}

‎src/main/java/pulse/search/statistics/FTest.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/search/statistics/FTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ public static Calculation findNested(Calculation a, Calculation b) {
137137
return aParams > bParams ? b : a;
138138
}
139139

140-
}
140+
}

‎src/main/java/pulse/tasks/logs/DataLogEntry.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/logs/DataLogEntry.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.InvocationTargetException;
44
import java.util.List;
5+
import pulse.Response;
56
import pulse.math.Parameter;
67
import pulse.math.ParameterIdentifier;
78
import pulse.properties.NumericProperties;

‎src/main/java/pulse/tasks/logs/Log.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/logs/Log.java
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pulse.tasks.logs;
22

33
import java.time.LocalTime;
4+
import static java.time.temporal.ChronoUnit.MILLIS;
5+
import static java.time.temporal.ChronoUnit.SECONDS;
46
import java.util.List;
57
import java.util.Objects;
68
import java.util.concurrent.CopyOnWriteArrayList;
@@ -186,5 +188,16 @@ public static boolean isVerbose() {
186188
public static void setVerbose(boolean verbose) {
187189
Log.verbose = verbose;
188190
}
191+
192+
/**
193+
* Time taken where the first array element contains seconds [0] and the second contains milliseconds [1].
194+
* @return an array of long values that sum um to the time taken to process a task
195+
*/
196+
197+
public long[] timeTaken() {
198+
var seconds = SECONDS.between(getStart(), getEnd());
199+
var ms = MILLIS.between(getStart(), getEnd()) - 1000L * seconds;
200+
return new long[] {seconds, ms};
201+
}
189202

190203
}

‎src/main/java/pulse/tasks/logs/LogEntry.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/tasks/logs/LogEntry.java
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.time.LocalDateTime;
44
import java.time.LocalTime;
55
import java.util.Objects;
6+
import pulse.Response;
67

78
import pulse.tasks.Identifier;
89
import pulse.tasks.SearchTask;
@@ -21,7 +22,8 @@ public class LogEntry {
2122

2223
private Identifier identifier;
2324
private LocalTime time;
24-
25+
private final Response response;
26+
2527
/**
2628
* <p>
2729
* Creates a {@code LogEntry} from this {@code SearchTask}. The data of the
@@ -34,6 +36,11 @@ public LogEntry(SearchTask t) {
3436
Objects.requireNonNull(t, Messages.getString("LogEntry.NullTaskError"));
3537
time = LocalDateTime.now().toLocalTime();
3638
identifier = t.getIdentifier();
39+
this.response = t.getResponse();
40+
}
41+
42+
public Response getResponse() {
43+
return response;
3744
}
3845

3946
public Identifier getIdentifier() {
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package pulse.ui.components;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import static java.util.concurrent.Executors.newSingleThreadExecutor;
5+
import javax.swing.JComponent;
6+
import pulse.tasks.TaskManager;
7+
import pulse.tasks.logs.Log;
8+
import pulse.tasks.logs.LogEntry;
9+
import pulse.util.Descriptive;
10+
11+
public abstract class AbstractLogger implements Descriptive {
12+
13+
private final ExecutorService updateExecutor = newSingleThreadExecutor();
14+
15+
public synchronized void update() {
16+
var task = TaskManager.getManagerInstance().getSelectedTask();
17+
18+
if (task == null) {
19+
return;
20+
}
21+
22+
var log = task.getLog();
23+
24+
if (!log.isStarted()) {
25+
return;
26+
}
27+
28+
post(log.lastEntry());
29+
}
30+
31+
public ExecutorService getUpdateExecutor() {
32+
return updateExecutor;
33+
}
34+
35+
public synchronized void callUpdate() {
36+
updateExecutor.submit(() -> update());
37+
}
38+
39+
public abstract JComponent getGUIComponent();
40+
public abstract void printTimeTaken(Log log);
41+
public abstract void post(LogEntry logEntry);
42+
public abstract void post(String text);
43+
public abstract void postAll();
44+
public abstract void clear();
45+
public abstract boolean isEmpty();
46+
47+
@Override
48+
public String describe() {
49+
return "Log_" + TaskManager.getManagerInstance().getSelectedTask().getIdentifier().getValue();
50+
}
51+
52+
}

‎src/main/java/pulse/ui/components/LogPane.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/ui/components/LogPane.java
-136Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.