Example #1
0
 private Cell6<Integer, String, Integer, Integer, Integer, Float> getSearchTable() {
   Cell6<Integer, String, Integer, Integer, Integer, Float> searchTable =
       new Cell6<Integer, String, Integer, Integer, Integer, Float>(
           SortedBytesInteger.getInstance(),
           SortedBytesString.getInstance(),
           SortedBytesUnsignedShort.getInstance(),
           SortedBytesUnsignedShort.getInstance(),
           SortedBytesInteger.getInstance(),
           SortedBytesFloat.getInstance());
   return searchTable;
 }
  public void testAddOnEmptySet() throws Exception {

    Cell3<String, Integer, Long> tc =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());

    tc.put("entry100", 0, 1111L);
    tc.put("entry100", 0, 1111L);
    tc.put("entry100", 0, 2222L);
    tc.put("entry100", 0, 3333L);
    tc.put("entry100", 0, 4444L);
    tc.put("entry100", 0, 5555L);
    tc.put("entry100", 1, 4444L);
    tc.put("entry100", 1, 4444L);
    tc.put("entry100", 1, 4444L);

    tc.put("entry101", 2, 9999L);
    tc.sort(new CellComparator.LongComparator<Integer>());

    Set<String> uniqueKeys = tc.getMap().keySet();

    // Test Parsing
    Cell3<String, Integer, Long> tcNewParsing =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());

    tcNewParsing.parseElements(tc.toBytes());
    assertEquals(2, tcNewParsing.getMap().size());

    for (String key : tcNewParsing.getMap().keySet()) {
      assertTrue(uniqueKeys.contains(key));
    }

    Iterator<Cell2<Integer, Long>> valItr = tcNewParsing.getMap().values().iterator();
    Cell2<Integer, Long> value = valItr.next();
    Collection<Integer> allKeys = value.keySet();
    Collection<Long> allVals = value.values();

    assertEquals(9, allKeys.size());
    assertTrue("[0, 0, 0, 0, 1, 1, 1, 0, 0]".equals(allKeys.toString()));
    assertEquals("[1111, 1111, 2222, 3333, 4444, 4444, 4444, 4444, 5555]", allVals.toString());

    value = valItr.next();
    value.parseElements();
    allKeys = value.keySet();
    allVals = value.values();

    assertEquals(1, allKeys.size());
    assertTrue("[2]".equals(allKeys.toString()));
    assertEquals("[9999]", allVals.toString());

    // Find Matching
    Cell3<String, Integer, Long> tcNewFinding =
        new Cell3<String, Integer, Long>(
            SortedBytesString.getInstance(),
            SortedBytesInteger.getInstance(),
            SortedBytesLong.getInstance());
    tcNewFinding.data = tc.toBytes();

    Collection<Cell2<Integer, Long>> all = tcNewFinding.values("entry100");
    for (Cell2<Integer, Long> cell2 : all) {
      cell2.parseElements();
      StringBuilder sb = new StringBuilder();
      for (CellKeyValue<Integer, Long> kv : cell2.getMap()) {
        sb.append(kv.key.toString() + "-" + kv.value.toString() + "|");
      }
      assertEquals(
          "0-1111|0-1111|0-2222|0-3333|1-4444|1-4444|1-4444|0-4444|0-5555|", sb.toString());
    }
  }
 public Cell2<Integer, Integer> createBlankTable() {
   return new Cell2<Integer, Integer>(
       SortedBytesInteger.getInstance(), SortedBytesInteger.getInstance());
 }