Skip to content

Commit

Permalink
getColsMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHD committed May 28, 2024
1 parent 99a1231 commit d6b30c4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <code>colTypes</code> to (non-negative) Integer values; never null.
* The key order is the same as in <code>colTypes</code>.
* <p>
* The return value is immutable.
* @return
*/
public Map<String, Integer> getColsMap()
{
final int nCols = cols.size();
final LinkedHashMap<String, Integer> 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));
}
}
7 changes: 6 additions & 1 deletion test/javasrc/localtest/feedHits/TestDataRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d6b30c4

Please sign in to comment.