@Test public void convert() { Map<Tuple2<String, String>, Long> maps = new HashMap<>(); maps.put(Tuple2.of("f0", "f1"), 2L); maps.put(Tuple2.of("f0", "f2"), 3L); maps.put(Tuple2.of("f1", "f2"), 4L); maps.put(Tuple2.of("f2", "f3"), 5L); Crosstab crossTable = Crosstab.convert(maps); List<String> rowTags = crossTable.rowTags; List<String> colTags = crossTable.colTags; assertEquals(3, rowTags.size()); assertTrue(rowTags.contains("f0")); assertTrue(rowTags.contains("f1")); assertTrue(rowTags.contains("f2")); assertEquals(3.0, crossTable.data[rowTags.indexOf("f0")][colTags.indexOf("f2")], 10e-4); }
public static Crosstab convert(Map<Tuple2<String, String>, Long> maps) { Crosstab crosstab = new Crosstab(); Set<Tuple2<String, String>> sets = maps.keySet(); Set<String> rowTags = new HashSet<>(); Set<String> colTags = new HashSet<>(); for (Tuple2<String, String> tuple2 : sets) { rowTags.add(tuple2.f0); colTags.add(tuple2.f1); } crosstab.rowTags = new ArrayList<>(rowTags); crosstab.colTags = new ArrayList<>(colTags); int rowLen = crosstab.rowTags.size(); int colLen = crosstab.colTags.size(); crosstab.data = new long[rowLen][colLen]; for (Map.Entry<Tuple2<String, String>, Long> entry : maps.entrySet()) { int rowIdx = crosstab.rowTags.indexOf(entry.getKey().f0); int colIdx = crosstab.colTags.indexOf(entry.getKey().f1); crosstab.data[rowIdx][colIdx] = entry.getValue(); } return crosstab; }
Crosstab { public static Crosstab convert(Map<Tuple2<String, String>, Long> maps) { Crosstab crosstab = new Crosstab(); Set<Tuple2<String, String>> sets = maps.keySet(); Set<String> rowTags = new HashSet<>(); Set<String> colTags = new HashSet<>(); for (Tuple2<String, String> tuple2 : sets) { rowTags.add(tuple2.f0); colTags.add(tuple2.f1); } crosstab.rowTags = new ArrayList<>(rowTags); crosstab.colTags = new ArrayList<>(colTags); int rowLen = crosstab.rowTags.size(); int colLen = crosstab.colTags.size(); crosstab.data = new long[rowLen][colLen]; for (Map.Entry<Tuple2<String, String>, Long> entry : maps.entrySet()) { int rowIdx = crosstab.rowTags.indexOf(entry.getKey().f0); int colIdx = crosstab.colTags.indexOf(entry.getKey().f1); crosstab.data[rowIdx][colIdx] = entry.getValue(); } return crosstab; } }
Crosstab { public static Crosstab convert(Map<Tuple2<String, String>, Long> maps) { Crosstab crosstab = new Crosstab(); Set<Tuple2<String, String>> sets = maps.keySet(); Set<String> rowTags = new HashSet<>(); Set<String> colTags = new HashSet<>(); for (Tuple2<String, String> tuple2 : sets) { rowTags.add(tuple2.f0); colTags.add(tuple2.f1); } crosstab.rowTags = new ArrayList<>(rowTags); crosstab.colTags = new ArrayList<>(colTags); int rowLen = crosstab.rowTags.size(); int colLen = crosstab.colTags.size(); crosstab.data = new long[rowLen][colLen]; for (Map.Entry<Tuple2<String, String>, Long> entry : maps.entrySet()) { int rowIdx = crosstab.rowTags.indexOf(entry.getKey().f0); int colIdx = crosstab.colTags.indexOf(entry.getKey().f1); crosstab.data[rowIdx][colIdx] = entry.getValue(); } return crosstab; }  }
Crosstab { public static Crosstab convert(Map<Tuple2<String, String>, Long> maps) { Crosstab crosstab = new Crosstab(); Set<Tuple2<String, String>> sets = maps.keySet(); Set<String> rowTags = new HashSet<>(); Set<String> colTags = new HashSet<>(); for (Tuple2<String, String> tuple2 : sets) { rowTags.add(tuple2.f0); colTags.add(tuple2.f1); } crosstab.rowTags = new ArrayList<>(rowTags); crosstab.colTags = new ArrayList<>(colTags); int rowLen = crosstab.rowTags.size(); int colLen = crosstab.colTags.size(); crosstab.data = new long[rowLen][colLen]; for (Map.Entry<Tuple2<String, String>, Long> entry : maps.entrySet()) { int rowIdx = crosstab.rowTags.indexOf(entry.getKey().f0); int colIdx = crosstab.colTags.indexOf(entry.getKey().f1); crosstab.data[rowIdx][colIdx] = entry.getValue(); } return crosstab; }  static Crosstab convert(Map<Tuple2<String, String>, Long> maps); static Crosstab merge(Crosstab left, Crosstab right); double[] rowSum(); double[] colSum(); double sum(); }
Crosstab { public static Crosstab convert(Map<Tuple2<String, String>, Long> maps) { Crosstab crosstab = new Crosstab(); Set<Tuple2<String, String>> sets = maps.keySet(); Set<String> rowTags = new HashSet<>(); Set<String> colTags = new HashSet<>(); for (Tuple2<String, String> tuple2 : sets) { rowTags.add(tuple2.f0); colTags.add(tuple2.f1); } crosstab.rowTags = new ArrayList<>(rowTags); crosstab.colTags = new ArrayList<>(colTags); int rowLen = crosstab.rowTags.size(); int colLen = crosstab.colTags.size(); crosstab.data = new long[rowLen][colLen]; for (Map.Entry<Tuple2<String, String>, Long> entry : maps.entrySet()) { int rowIdx = crosstab.rowTags.indexOf(entry.getKey().f0); int colIdx = crosstab.colTags.indexOf(entry.getKey().f1); crosstab.data[rowIdx][colIdx] = entry.getValue(); } return crosstab; }  static Crosstab convert(Map<Tuple2<String, String>, Long> maps); static Crosstab merge(Crosstab left, Crosstab right); double[] rowSum(); double[] colSum(); double sum(); public List<String> colTags; public List<String> rowTags; public long[][] data; }