Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/main/java/de/doubleslash/keeptime/view/ProjectReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static de.doubleslash.keeptime.view.ReportController.NOTE_DELIMETER;

import java.lang.invoke.MethodHandles;
import java.util.StringJoiner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,35 +29,23 @@ public class ProjectReport {
/** The slf4j-logger for this class. */
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private int numberOfNotes;
private final StringJoiner sb;

private final int size;

private final StringBuilder sb;

public ProjectReport(final int size) {
this.size = size;
this.sb = new StringBuilder(2 * 1024);
public ProjectReport() {
this.sb = new StringJoiner(NOTE_DELIMETER);
}

public void appendToWorkNotes(final String currentWorkNote) {
this.numberOfNotes++;

if (!currentWorkNote.isEmpty()) {
if (this.numberOfNotes > 1) {
this.sb.append(NOTE_DELIMETER);
}
this.sb.append(currentWorkNote.trim());
this.sb.add(currentWorkNote.trim());
} else {
LOG.debug("Skipping empty note.");
}
}

public int getNumberOfNotes() {
return this.numberOfNotes;
}

public String getNotes() {
return this.sb.toString();
return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private Button createCopyProjectButton(final List<Work> projectWork) {

final EventHandler<ActionEvent> eventListener = actionEvent -> {
LOG.debug("Copy to Clipboard clicked.");
final ProjectReport pr = new ProjectReport(projectWork.size());
final ProjectReport pr = new ProjectReport();
for (int j = 0; j < projectWork.size(); j++) {
final Work work = projectWork.get(j);
final String currentWorkNote = work.getNotes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.lang.invoke.MethodHandles;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -38,20 +37,20 @@ public class ProjectReportTest {

@BeforeEach
void setUp() {
this.uut = new ProjectReport(3);
this.uut = new ProjectReport();
}

@Test
public void testAppendToWorkNotes() {
this.uut.appendToWorkNotes("note 1 ");
public void testAppendToWorkNotes_EmptyNoteAtStart() {
this.uut.appendToWorkNotes(EMPTY_NOTE);
this.uut.appendToWorkNotes("note 1 ");
this.uut.appendToWorkNotes("note 2 ");
final String expected = "note 1; note 2";
assertEquals(expected, this.uut.getNotes());
}

@Test
public void testAppendToWorkNotesAddNumberOfNotes() {
public void testAppendToWorkNotes_EmptyNoteInTheMiddle() {
this.uut.appendToWorkNotes("note 1 ");
this.uut.appendToWorkNotes(EMPTY_NOTE);
this.uut.appendToWorkNotes("note 2 ");
Expand All @@ -60,8 +59,8 @@ public void testAppendToWorkNotesAddNumberOfNotes() {
}

@Test
public void testAppendToWorkNotesAddNumberOfNotes_2() {
this.uut = new ProjectReport(3);
public void testAppendToWorkNotes_NoEmptyNote() {
this.uut = new ProjectReport();
this.uut.appendToWorkNotes("note 1");
this.uut.appendToWorkNotes("note 2");
this.uut.appendToWorkNotes("note 3");
Expand All @@ -70,8 +69,8 @@ public void testAppendToWorkNotesAddNumberOfNotes_2() {
}

@Test
public void testAppendToWorkNotesAddNumberOfNotes_EmptyNotesAtTheEnd() {
this.uut = new ProjectReport(4);
public void testAppendToWorkNotes_EmptyNotesAtTheEnd() {
this.uut = new ProjectReport();
this.uut.appendToWorkNotes("note 1");
this.uut.appendToWorkNotes("note 2");
this.uut.appendToWorkNotes(EMPTY_NOTE);
Expand Down