Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please see my solution below. The test file test1.txt you gave seems to have some special chars at beginning of file. </p> <p>.</p> <p><strong>Solution</strong></p> <pre><code>public class Test { public static void main(String[] args) throws IOException { Test test = new Test(); test.execute(); } private static String TYPE_XTSM = "XTSM"; private static String TYPE_XTS = "XTS"; private static String TYPE_XRX = "XRX"; private static String TYPE_XHAN = "XHAN"; private void execute() throws IOException { InputStream in = null; BufferedReader br = null; TreeMap&lt;Integer, TreeMap&lt;Integer, Integer&gt;&gt; xtsmMap = new TreeMap&lt;Integer, TreeMap&lt;Integer, Integer&gt;&gt;(); try { in = Test.class.getResourceAsStream("test1.txt"); br = new BufferedReader(new InputStreamReader(in)); String line; while ((line = br.readLine()) != null) { Record rec = new Record(line); processRecord(xtsmMap, rec); } } finally { if (br != null) { br.close(); } } printResults(xtsmMap); } private void processRecord( TreeMap&lt;Integer, TreeMap&lt;Integer, Integer&gt;&gt; xtsmMap, Record rec) { TreeMap&lt;Integer, Integer&gt; xtsMap; if (xtsmMap.containsKey(rec.getXtsm())) { xtsMap = xtsmMap.get(rec.getXtsm()); } else { xtsMap = new TreeMap&lt;Integer, Integer&gt;(); xtsmMap.put(Integer.valueOf(rec.getXtsm()), xtsMap); } if (xtsMap.containsKey(rec.getXts())) { Integer count = xtsMap.get(rec.getXts()); xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(count .intValue() + 1)); } else { xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(1)); } } private void printResults( TreeMap&lt;Integer, TreeMap&lt;Integer, Integer&gt;&gt; xtsmMap) { System.out.println("Type\t\tTotal"); Set&lt;Integer&gt; xtsmSet = xtsmMap.navigableKeySet(); for (Integer xtsm : xtsmSet) { TreeMap&lt;Integer, Integer&gt; xtsMap = xtsmMap.get(xtsm); Set&lt;Integer&gt; xtsSet = xtsMap.navigableKeySet(); for (Integer xts : xtsSet) { Integer count = xtsMap.get(xts); String outputLine = TYPE_XTSM + ":" + xtsm + "/" + TYPE_XTS + ":" + xts + "\t" + count; System.out.println(outputLine); } } } private static class Record { private Integer xtsm, xts, xrk, xhan; Record(String line) { StringTokenizer st = new StringTokenizer(line, "/"); while (st.hasMoreTokens()) { String token = st.nextToken(); String type = token.substring(0, token.indexOf(":")); String valueStr = token.substring(token.indexOf(":") + 1, token .length()); Integer value = Integer.valueOf(valueStr); if (TYPE_XTSM.equals(type)) { xtsm = value; } else if (TYPE_XTS.equals(type)) { xts = value; } else if (TYPE_XRX.equals(type)) { xrk = value; } else if (TYPE_XHAN.equals(type)) { xhan = value; } } } public Integer getXtsm() { return xtsm; } public Integer getXts() { return xts; } public Integer getXrk() { return xrk; } public Integer getXhan() { return xhan; } } } </code></pre> <p>.</p> <p><strong>Output</strong></p> <pre> Type Total XTSM:0/XTS:0 29 XTSM:0/XTS:1 29 XTSM:0/XTS:2 29 XTSM:1/XTS:0 29 XTSM:1/XTS:1 29 XTSM:1/XTS:2 29 XTSM:2/XTS:0 29 XTSM:2/XTS:1 29 XTSM:2/XTS:2 29 XTSM:3/XTS:0 14 XTSM:3/XTS:1 14 XTSM:3/XTS:2 14 XTSM:4/XTS:0 13 XTSM:4/XTS:1 13 XTSM:4/XTS:2 13 XTSM:5/XTS:0 14 XTSM:5/XTS:1 14 XTSM:5/XTS:2 14 XTSM:6/XTS:0 21 XTSM:6/XTS:1 21 XTSM:6/XTS:2 21 XTSM:7/XTS:0 29 XTSM:7/XTS:1 29 XTSM:7/XTS:2 29 XTSM:8/XTS:0 14 XTSM:8/XTS:1 21 XTSM:9/XTS:0 21 XTSM:9/XTS:1 21 XTSM:9/XTS:2 21 XTSM:10/XTS:0 14 XTSM:10/XTS:1 14 XTSM:10/XTS:2 14 XTSM:11/XTS:0 14 XTSM:11/XTS:1 14 XTSM:11/XTS:2 14 XTSM:12/XTS:0 14 XTSM:12/XTS:1 14 XTSM:12/XTS:2 14 XTSM:13/XTS:0 29 XTSM:13/XTS:1 29 XTSM:13/XTS:2 29 XTSM:14/XTS:0 29 XTSM:14/XTS:1 29 XTSM:15/XTS:0 29 XTSM:15/XTS:1 29 XTSM:15/XTS:2 29 XTSM:16/XTS:0 29 XTSM:16/XTS:1 29 XTSM:16/XTS:2 29 XTSM:17/XTS:0 29 XTSM:17/XTS:1 29 XTSM:17/XTS:2 29 XTSM:18/XTS:0 29 XTSM:18/XTS:1 29 XTSM:18/XTS:2 29 XTSM:19/XTS:0 29 XTSM:19/XTS:1 29 XTSM:19/XTS:2 29 XTSM:21/XTS:0 29 XTSM:21/XTS:1 29 XTSM:21/XTS:2 29 XTSM:22/XTS:0 29 XTSM:22/XTS:1 29 XTSM:22/XTS:2 29 XTSM:23/XTS:0 29 XTSM:23/XTS:1 29 XTSM:23/XTS:2 29 XTSM:24/XTS:0 29 XTSM:24/XTS:1 29 XTSM:24/XTS:2 29 XTSM:25/XTS:0 29 XTSM:25/XTS:1 29 XTSM:25/XTS:2 29 XTSM:26/XTS:0 14 XTSM:26/XTS:1 14 XTSM:26/XTS:2 14 XTSM:28/XTS:0 15 XTSM:28/XTS:1 15 XTSM:28/XTS:2 15 XTSM:29/XTS:0 13 XTSM:29/XTS:1 13 XTSM:29/XTS:2 13 XTSM:30/XTS:0 14 XTSM:30/XTS:1 14 XTSM:31/XTS:0 14 XTSM:31/XTS:1 13 XTSM:31/XTS:2 13 XTSM:32/XTS:0 13 XTSM:32/XTS:1 14 XTSM:32/XTS:2 13 XTSM:33/XTS:0 14 XTSM:33/XTS:1 14 XTSM:33/XTS:2 14 XTSM:34/XTS:0 14 XTSM:34/XTS:1 14 XTSM:34/XTS:2 14 XTSM:35/XTS:0 29 XTSM:35/XTS:1 29 XTSM:35/XTS:2 29 XTSM:36/XTS:0 29 XTSM:36/XTS:1 21 XTSM:36/XTS:2 21 XTSM:37/XTS:0 14 XTSM:37/XTS:1 14 XTSM:37/XTS:2 14 XTSM:38/XTS:0 14 XTSM:38/XTS:1 14 XTSM:38/XTS:2 14 XTSM:39/XTS:0 21 XTSM:39/XTS:1 21 XTSM:39/XTS:2 21 XTSM:40/XTS:0 29 XTSM:40/XTS:1 29 XTSM:40/XTS:2 7 XTSM:41/XTS:0 29 XTSM:41/XTS:1 29 XTSM:41/XTS:2 29 </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload