From d6b30c4ff98d42f12c555fed2eb6717d735c660f Mon Sep 17 00:00:00 2001 From: DamonHD Date: Tue, 28 May 2024 13:09:11 +0100 Subject: [PATCH] getColsMap() --- .../statsHouse/feedHits/data/FeedStatus.java | 19 +++++++++++++++++++ .../localtest/feedHits/TestDataRead.java | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java b/javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java index c366382..9259890 100644 --- a/javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java +++ b/javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java @@ -19,7 +19,10 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Objects; /**Single feed status record, for by-hour or by-User-Agent forms, immutable. @@ -114,4 +117,20 @@ public String extractUA() if("\"-\"".equals(index)) { return(""); } return(index.substring(1, index.length()-1)); } + + /**Return cols values as a Map from the keys in colTypes to (non-negative) Integer values; never null. + * The key order is the same as in colTypes. + *

+ * The return value is immutable. + * @return + */ + public Map getColsMap() + { + final int nCols = cols.size(); + final LinkedHashMap m = new LinkedHashMap<>(nCols); + final String[] keys = colTypes.split(":"); + for(int i = 0; i < nCols; ++i) + { m.put(keys[i], cols.get(i)); } + return(Collections.unmodifiableMap(m)); + } } diff --git a/test/javasrc/localtest/feedHits/TestDataRead.java b/test/javasrc/localtest/feedHits/TestDataRead.java index 6420c9f..2fedcc9 100644 --- a/test/javasrc/localtest/feedHits/TestDataRead.java +++ b/test/javasrc/localtest/feedHits/TestDataRead.java @@ -50,7 +50,12 @@ public static void testParseOfSampleALLFeedStatus() assertEquals(12857, fs.hits()); assertEquals(71404021, fs.bytes()); assertEquals("200:304:406:429:SH", fs.colTypes()); - // TODO: cols content + assertEquals("200", fs.getColsMap().keySet().iterator().next()); + assertEquals(2987, fs.getColsMap().get("200").intValue()); + assertEquals(1993, fs.getColsMap().get("304").intValue()); + assertEquals(359, fs.getColsMap().get("406").intValue()); + assertEquals(7476, fs.getColsMap().get("429").intValue()); + assertEquals(5129, fs.getColsMap().get("SH").intValue()); assertEquals("ALL", fs.index()); assertFalse(fs.isUA()); assertNull(fs.extractUA());