@Test public void computeKey() { assertEquals(0, statistics.computeMapKey(0, 0, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(4, statistics.computeMapKey(0, 4, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(5, statistics.computeMapKey(1, 0, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(6, statistics.computeMapKey(1, 1, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(10, statistics.computeMapKey(2, 0, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(14, statistics.computeMapKey(2, 4, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(15, statistics.computeMapKey(3, 0, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(16, statistics.computeMapKey(3, 1, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); assertEquals(29, statistics.computeMapKey(5, 4, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT)); }
short computeMapKey(int key1, int key2, String key3) { if (key1 > MAX_KEY_1) { throw new IllegalArgumentException("key1 must be 0-" + MAX_KEY_1 + "; not " + key1 + "."); } if (key2 > MAX_KEY_2) { throw new IllegalArgumentException("key2 must be 0-" + MAX_KEY_2 + "; not " + key2 + "."); } if (! STAT_SHIP_COUNT.equals(key3)) { throw new IllegalArgumentException("key3 '" + key3 + "' is not supported."); } final int d1 = MAX_KEY_2 + 1; return (short) (key2 + key1*d1); }
ShipTypeAndSizeStatisticData implements StatisticData, ThreeKeyMap { short computeMapKey(int key1, int key2, String key3) { if (key1 > MAX_KEY_1) { throw new IllegalArgumentException("key1 must be 0-" + MAX_KEY_1 + "; not " + key1 + "."); } if (key2 > MAX_KEY_2) { throw new IllegalArgumentException("key2 must be 0-" + MAX_KEY_2 + "; not " + key2 + "."); } if (! STAT_SHIP_COUNT.equals(key3)) { throw new IllegalArgumentException("key3 '" + key3 + "' is not supported."); } final int d1 = MAX_KEY_2 + 1; return (short) (key2 + key1*d1); } }
ShipTypeAndSizeStatisticData implements StatisticData, ThreeKeyMap { short computeMapKey(int key1, int key2, String key3) { if (key1 > MAX_KEY_1) { throw new IllegalArgumentException("key1 must be 0-" + MAX_KEY_1 + "; not " + key1 + "."); } if (key2 > MAX_KEY_2) { throw new IllegalArgumentException("key2 must be 0-" + MAX_KEY_2 + "; not " + key2 + "."); } if (! STAT_SHIP_COUNT.equals(key3)) { throw new IllegalArgumentException("key3 '" + key3 + "' is not supported."); } final int d1 = MAX_KEY_2 + 1; return (short) (key2 + key1*d1); } protected  ShipTypeAndSizeStatisticData(int maxKey1, int maxKey2, int maxNumKey3); }
ShipTypeAndSizeStatisticData implements StatisticData, ThreeKeyMap { short computeMapKey(int key1, int key2, String key3) { if (key1 > MAX_KEY_1) { throw new IllegalArgumentException("key1 must be 0-" + MAX_KEY_1 + "; not " + key1 + "."); } if (key2 > MAX_KEY_2) { throw new IllegalArgumentException("key2 must be 0-" + MAX_KEY_2 + "; not " + key2 + "."); } if (! STAT_SHIP_COUNT.equals(key3)) { throw new IllegalArgumentException("key3 '" + key3 + "' is not supported."); } final int d1 = MAX_KEY_2 + 1; return (short) (key2 + key1*d1); } protected  ShipTypeAndSizeStatisticData(int maxKey1, int maxKey2, int maxNumKey3); static ShipTypeAndSizeStatisticData create(); @Override @SuppressWarnings("unused") String getMeaningOfKey1(); @Override @SuppressWarnings("unused") String getMeaningOfKey2(); @Override @SuppressWarnings("unused") String getMeaningOfKey3(); @Override String getStatisticName(); @Override String getStatisticDataType(); @Override TreeMap<Integer, TreeMap<Integer, HashMap<String, Integer>>> getData(); @Override void incrementValue(int key1, int key2, String key3); @Override void setValue(int key1, int key2, String key3, int value); @Override Integer getValue(int key1, int key2, String key3); @Override int getSumFor(String key3); }
ShipTypeAndSizeStatisticData implements StatisticData, ThreeKeyMap { short computeMapKey(int key1, int key2, String key3) { if (key1 > MAX_KEY_1) { throw new IllegalArgumentException("key1 must be 0-" + MAX_KEY_1 + "; not " + key1 + "."); } if (key2 > MAX_KEY_2) { throw new IllegalArgumentException("key2 must be 0-" + MAX_KEY_2 + "; not " + key2 + "."); } if (! STAT_SHIP_COUNT.equals(key3)) { throw new IllegalArgumentException("key3 '" + key3 + "' is not supported."); } final int d1 = MAX_KEY_2 + 1; return (short) (key2 + key1*d1); } protected  ShipTypeAndSizeStatisticData(int maxKey1, int maxKey2, int maxNumKey3); static ShipTypeAndSizeStatisticData create(); @Override @SuppressWarnings("unused") String getMeaningOfKey1(); @Override @SuppressWarnings("unused") String getMeaningOfKey2(); @Override @SuppressWarnings("unused") String getMeaningOfKey3(); @Override String getStatisticName(); @Override String getStatisticDataType(); @Override TreeMap<Integer, TreeMap<Integer, HashMap<String, Integer>>> getData(); @Override void incrementValue(int key1, int key2, String key3); @Override void setValue(int key1, int key2, String key3, int value); @Override Integer getValue(int key1, int key2, String key3); @Override int getSumFor(String key3); static final String STAT_SHIP_COUNT; }