@Test
  public void testBloomFilterPredicateValuesExisting() throws Exception {
    BloomFilter bloomFilter = new BloomFilter(TEST_VALUES.size() * 10, 0.01);

    for (Object o : TEST_VALUES.keySet()) {
      if (o instanceof Long) {
        bloomFilter.addLong((Long) o);
      } else if (o instanceof Integer) {
        bloomFilter.addLong((Integer) o);
      } else if (o instanceof String) {
        bloomFilter.addString((String) o);
      } else if (o instanceof BigDecimal) {
        bloomFilter.addString(o.toString());
      } else if (o instanceof Slice) {
        bloomFilter.addString(((Slice) o).toStringUtf8());
      } else if (o instanceof Timestamp) {
        bloomFilter.addLong(((Timestamp) o).getTime());
      } else if (o instanceof Double) {
        bloomFilter.addDouble((Double) o);
      } else {
        fail("Unsupported type " + o.getClass());
      }
    }

    for (Map.Entry<Object, Type> testValue : TEST_VALUES.entrySet()) {
      boolean matched = checkInBloomFilter(bloomFilter, testValue.getKey(), testValue.getValue());
      assertTrue(matched, "type " + testValue.getClass());
    }

    // test unsupported type: can be supported by ORC but is not implemented yet
    assertTrue(
        checkInBloomFilter(bloomFilter, new Date(), DATE),
        "unsupported type DATE should always return true");
  }
示例#2
0
  @Override
  public void marshal(
      final Object source,
      final HierarchicalStreamWriter writer,
      final MarshallingContext context) {
    final Map<?, ?> map = (Map<?, ?>) source;
    final String entryName = mapper().serializedClass(Map.Entry.class);
    for (final Map.Entry<?, ?> entry : map.entrySet()) {
      ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass());

      writeItem(entry.getKey(), context, writer);
      writeItem(entry.getValue(), context, writer);

      writer.endNode();
    }
  }
  static <K, V> void verify(Map<K, V> map, K k1, V v1, K k2, V v2) {
    map.put(k1, v1);
    map.put(k2, v2);

    Iterator<Map.Entry<K, V>> iter = map.entrySet().iterator();

    assertTrue(iter.hasNext());
    Map.Entry<K, V> first = iter.next();

    assertTrue(iter.hasNext());
    Map.Entry<K, V> second = iter.next();

    if (first == second) {
      // either IdentityHashMap or EnumMap
      System.err.println(map.getClass().getName() + " with entry: " + first.getClass().getName());
    }
  }