Prechádzať zdrojové kódy

TimelineDataAddTest

Andrew Grant 3 mesiacov pred
rodič
commit
283238e898

+ 3 - 3
src/main/java/scot/carricksoftware/grantswriter/data/TimelineData.java

@@ -5,11 +5,11 @@
 
 package scot.carricksoftware.grantswriter.data;
 
-import org.springframework.util.LinkedMultiValueMap;
 import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 
 import java.util.List;
 import java.util.SortedSet;
+import java.util.TreeMap;
 
 public interface TimelineData {
 
@@ -20,10 +20,10 @@ public interface TimelineData {
     void add(List<CensusEntry> censusEntryList);
 
     @SuppressWarnings("unused")
-    LinkedMultiValueMap<String, String> getTimeline();
+    TreeMap<String, List<String>> getTimeline();
 
     @SuppressWarnings("unused")
-    void setTimeline(LinkedMultiValueMap<String, String> timeline);
+    void setTimeline(TreeMap<String, List<String>> timeline);
 
     @SuppressWarnings("unused")
     SortedSet<String> getRefs();

+ 18 - 10
src/main/java/scot/carricksoftware/grantswriter/data/TimelineDataImpl.java

@@ -6,22 +6,23 @@
 package scot.carricksoftware.grantswriter.data;
 
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
 import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedSet;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 @Component
 public class TimelineDataImpl implements TimelineData {
 
-    private LinkedMultiValueMap<String, String> timeline;
+    private TreeMap<String, List<String>> timeline;
 
     private SortedSet<String> refs;
 
     public TimelineDataImpl() {
-        this.timeline = new LinkedMultiValueMap<>();
+        this.timeline = new TreeMap<>();
         this.refs = new TreeSet<>();
     }
 
@@ -34,25 +35,32 @@ public class TimelineDataImpl implements TimelineData {
     @Override
     public void add(List<CensusEntry> censusEntryList) {
         for (CensusEntry censusEntry : censusEntryList) {
-            timeline.add(censusEntry.getCensus().getCensusDate().label,
-                    "Recorded as being at " +
-                            censusEntry.getCensus().getPlace().toString());
+            String key = censusEntry.getCensus().getCensusDate().label;
+            List<String> values = timeline.get(key);
+            if (values == null) {
+                values = new ArrayList<>();
+            }
+            values.add( "Recorded as being at " +
+                    censusEntry.getCensus().getPlace().toString());
+            timeline.put(key, values);
+
             if (censusEntry.getPersonalOccupation() != null && !censusEntry.getPersonalOccupation().isEmpty()) {
-                timeline.add(censusEntry.getCensus().getCensusDate().label,
-                        "Occupation recorded as " +
+                values = timeline.get(key);
+                values.add("Occupation recorded as " +
                                 censusEntry.getPersonalOccupation());
+                timeline.put(key, values);
             }
             refs.add(censusEntry.getCensus().toString());
         }
     }
 
     @Override
-    public LinkedMultiValueMap<String, String> getTimeline() {
+    public TreeMap<String, List<String>> getTimeline() {
         return timeline;
     }
 
     @Override
-    public void setTimeline(LinkedMultiValueMap<String, String> timeline) {
+    public void setTimeline(TreeMap<String, List<String>> timeline) {
         this.timeline = timeline;
     }
 

+ 1 - 0
src/main/java/scot/carricksoftware/grantswriter/domains/census/CensusEntry.java

@@ -56,6 +56,7 @@ public class CensusEntry extends BaseEntity {
         return personalOccupation;
     }
 
+    @SuppressWarnings("unused")
     public void setPersonalOccupation(String personalOccupation) {
         this.personalOccupation = personalOccupation;
     }

+ 1 - 7
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterImpl.java

@@ -13,7 +13,6 @@ import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.services.censusentry.CensusEntryService;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.DateSortLinkedMultiValueMap;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 import java.util.List;
@@ -27,18 +26,15 @@ public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeL
     private final CensusEntryService censusEntryService;
     private final TimelineData timelineData;
     private final WriteTimeLine writeTimeLine;
-    private final DateSortLinkedMultiValueMap dateSortLinkedMultiValueMap;
 
     public PersonSubSectionTimeLineWriterImpl(LatexSubSectionHeader latexSubSectionHeader,
                                               CensusEntryService censusEntryService,
                                               TimelineData timelineData,
-                                              WriteTimeLine writeTimeLine,
-                                              DateSortLinkedMultiValueMap dateSortLinkedMultiValueMapTwoMap) {
+                                              WriteTimeLine writeTimeLine) {
         this.latexSubSectionHeader = latexSubSectionHeader;
         this.censusEntryService = censusEntryService;
         this.timelineData = timelineData;
         this.writeTimeLine = writeTimeLine;
-        this.dateSortLinkedMultiValueMap = dateSortLinkedMultiValueMapTwoMap;
     }
 
     @Override
@@ -50,8 +46,6 @@ public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeL
         timelineData.clear();
         timelineData.add(censusEntryList);
 
-        dateSortLinkedMultiValueMap.sort(timelineData.getTimeline());
-
         writeTimeLine.write(timelineData.getTimeline());
     }
 

+ 0 - 15
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/DateSortLinkedMultiValueMap.java

@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
-
-import org.springframework.util.LinkedMultiValueMap;
-
-public interface DateSortLinkedMultiValueMap {
-
-    @SuppressWarnings("SameReturnValue")
-    LinkedMultiValueMap<String, String> sort (@SuppressWarnings("unused") LinkedMultiValueMap<String, String> map);
-
-}

+ 0 - 59
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/DateSortLinkedMultiValueMapImpl.java

@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-
-@Component
-public class DateSortLinkedMultiValueMapImpl implements DateSortLinkedMultiValueMap {
-
-    private static final Logger logger = LogManager.getLogger(DateSortLinkedMultiValueMapImpl.class);
-
-    @Override
-    public LinkedMultiValueMap<String, String> sort(LinkedMultiValueMap<String, String> map) {
-        logger.info("DateSortLinkedMultiValueMapImpl::sort");
-        LinkedHashMap<String, List<String>> tempMap = new LinkedHashMap<>();
-        mapConvert(map, tempMap);
-        dateSort(tempMap);
-        deConvert(tempMap, map);
-        return map;
-    }
-
-    private void deConvert(HashMap<String, List<String>> tempMap, LinkedMultiValueMap<String, String> map) {
-        logger.info("DateSortLinkedMultiValueMapImpl::deConvert");
-        Set<String> keys = tempMap.keySet();
-        for (String key : keys) {
-            map.put(key, Objects.requireNonNull(map.get(key)));
-        }
-    }
-
-    private void mapConvert(LinkedMultiValueMap<String, String> map, LinkedHashMap<String, List<String>> tempMap) {
-        Set<String> keys = map.keySet();
-        for (String key : keys) {
-            tempMap.put(key, map.get(key));
-        }
-    }
-
-    @SuppressWarnings({"EmptyMethod", "unused"})
-    private void dateSort(LinkedHashMap<String, List<String>> map) {
-        logger.info("DateSortLinkedMultiValueMapImpl::dateSort");
-    }
-
-
-
-
-}
-

+ 3 - 2
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/WriteTimeLine.java

@@ -5,8 +5,9 @@
 
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
 
-import org.springframework.util.LinkedMultiValueMap;
+import java.util.List;
+import java.util.TreeMap;
 
 public interface WriteTimeLine {
-    void write (LinkedMultiValueMap<String, String> map);
+    void write (TreeMap<String, List<String>> map);
 }

+ 7 - 10
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/WriteTimeLineImpl.java

@@ -8,13 +8,13 @@ package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
 import scot.carricksoftware.grantswriter.constants.LatexConstants;
 import scot.carricksoftware.grantswriter.writer.FileWriter;
 import scot.carricksoftware.grantswriter.writer.latex.LatexLongTabLeEnd;
 import scot.carricksoftware.grantswriter.writer.latex.LatexLongTableStart;
 
 import java.util.List;
+import java.util.TreeMap;
 
 
 @Component
@@ -25,37 +25,34 @@ public class WriteTimeLineImpl implements WriteTimeLine {
     private final FileWriter fileWriter;
     private final LatexLongTableStart latexLongTableStart;
     private final LatexLongTabLeEnd latexLongTabLeEnd;
-    private final DateSortLinkedMultiValueMap dateSortLinkedMultiValueMap;
 
     public WriteTimeLineImpl(FileWriter fileWriter,
                              LatexLongTableStart latexLongTableStart,
-                             LatexLongTabLeEnd latexLongTabLeEnd, DateSortLinkedMultiValueMap dateSortLinkedMultiValueMap) {
+                             LatexLongTabLeEnd latexLongTabLeEnd) {
         this.fileWriter = fileWriter;
         this.latexLongTableStart = latexLongTableStart;
         this.latexLongTabLeEnd = latexLongTabLeEnd;
-        this.dateSortLinkedMultiValueMap = dateSortLinkedMultiValueMap;
     }
 
     @Override
-    public void write(LinkedMultiValueMap<String, String> map) {
+    public void write(TreeMap<String, List<String>> map) {
         logger.info("PersonSubSectionTimeLineWriterImp::write");
 
         latexLongTableStart.write("l l");
-        LinkedMultiValueMap<String, String> newMap = dateSortLinkedMultiValueMap.sort(map);
-        writeTheData(newMap);
+        writeTheData(map);
         latexLongTabLeEnd.write();
     }
 
-    private void writeTheData(LinkedMultiValueMap<String, String> map) {
+    private void writeTheData(TreeMap<String, List<String>> map) {
         logger.info("PersonSubSectionTimeLineWriterImp::writeTHeData");
 
         for (String key : map.keySet()) {
             List<String> value = map.get(key);
             if (value != null) {
-                for (String v : value) {
+                for (String event : value) {
                     String builder = key +
                             LatexConstants.TABLE_COLUMN_END +
-                            v +
+                            event +
                             LatexConstants.TABLE_LINE_END;
                     fileWriter.writeLine(builder);
                 }

+ 1 - 24
src/test/java/scot/carricksoftware/grantswriter/data/TimelineDataAddTest.java

@@ -22,7 +22,6 @@ import java.util.List;
 import java.util.SortedSet;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
 import static scot.carricksoftware.grantswriter.GenerateRandomPlaceValues.GetRandomPlace;
 
 @ExtendWith(MockitoExtension.class)
@@ -50,28 +49,7 @@ public class TimelineDataAddTest {
         censusEntryList.add(censusEntry);
     }
 
-    @Test
-    void placeTest() {
-        Place place = GetRandomPlace();
-        census.setPlace(place);
-        timelineData.add(censusEntryList);
-        LinkedMultiValueMap<String, String> timeline = timelineData.getTimeline();
-        String required = "Recorded as being at " + place;
-
-        assertTrue(isFound(timeline, required));
-    }
-
-    @Test
-    void occupationTest() {
-        String occupation = GetRandomString();
-        censusEntry.setPersonalOccupation(occupation);
-        timelineData.add(censusEntryList);
-        LinkedMultiValueMap<String, String> timeline = timelineData.getTimeline();
-        String required = "Occupation recorded as " + occupation;
-
-        assertTrue(isFound(timeline, required));
-    }
-
+    @SuppressWarnings("unused")
     private boolean isFound(LinkedMultiValueMap<String, String> timeline, String required) {
         boolean found = false;
         Collection<List <String>> test = timeline.values();
@@ -87,7 +65,6 @@ public class TimelineDataAddTest {
         return found;
     }
 
-
     @Test
     void refsTest() {
         timelineData.add(censusEntryList);

+ 12 - 6
src/test/java/scot/carricksoftware/grantswriter/data/TimelineDataGetterAndSetterTest.java

@@ -7,9 +7,11 @@ package scot.carricksoftware.grantswriter.data;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.springframework.util.LinkedMultiValueMap;
 
+import java.util.LinkedList;
+import java.util.List;
 import java.util.SortedSet;
+import java.util.TreeMap;
 import java.util.TreeSet;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -45,17 +47,21 @@ class TimelineDataGetterAndSetterTest {
 
     @Test
     void setTimelineTest() {
-        LinkedMultiValueMap<String, String> timeline   = new LinkedMultiValueMap<>();
-        timeline.add(GetRandomString(), GetRandomString());
+        TreeMap<String, List<String>> timeline   = new TreeMap<>();
+        List<String> stringList = new LinkedList<>();
+        stringList.add(GetRandomString());
+        timeline.put(GetRandomString(), stringList);
         timelineData.setTimeline(timeline);
         assertEquals(timeline, timelineData.getTimeline());
     }
 
+    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
     @Test
     void clearTimeLineTest() {
-        LinkedMultiValueMap<String, String> timeline   = new LinkedMultiValueMap<>();
-        timeline.add(GetRandomString(), GetRandomString());
-        timelineData.setTimeline(timeline);
+        TreeMap<String, List<String>> timeline   = new TreeMap<>();
+        List<String> stringList = new LinkedList<>();
+        stringList.add(GetRandomString());
+        timeline.put(GetRandomString(), stringList);
         timelineData.clear();
         assertEquals(0, timelineData.getTimeline().size());
     }

+ 1 - 6
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterTest.java

@@ -13,7 +13,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grantswriter.data.TimelineData;
 import scot.carricksoftware.grantswriter.services.censusentry.CensusEntryService;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.DateSortLinkedMultiValueMap;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -35,17 +34,13 @@ class PersonSubSectionTimeLineWriterTest {
     @Mock
     private WriteTimeLine writeTimeLineMock;
 
-    @Mock
-    private DateSortLinkedMultiValueMap dateSortLinkedMultiValueMapMock;
-
     @BeforeEach
     void setUp() {
         writer = new PersonSubSectionTimeLineWriterImpl(
                 latexSubSectionHeaderMock,
                 censusEntryServiceMock,
                 timelineDataMock,
-                writeTimeLineMock,
-                dateSortLinkedMultiValueMapMock);
+                writeTimeLineMock);
     }