I have the following map definition where map.containsKey() clearly doesn't work:
ChronicleMapBuilder<String, String> cmBuilder = ChronicleMapBuilder.of(String.class, String.class);
cmBuilder.constantKeySizeBySample("abcde")
.averageValueSize(128)
.entries(1024)
.keyMarshaller(new MyStringMarshaller())
.valueMarshaller(new MyStringMarshaller());
Map myMap = cmBuilder.createPersistedTo(new File("/tmp/test-map"));
myMap.put("abc", "123");
System.out.println(myMap.containsKey("abc")); // prints false
...
public static class MyStringMarshaller implements BytesMarshaller<String> {
@Override
public void write(Bytes bytes, String str) {
bytes.writeUTF(str);
}
@Override
public String read(Bytes bytes) {
return read(bytes, null);
}
@Override
public String read(Bytes bytes, String str) {
return bytes.readUTF();
}
}
I use Chronicle Map 2.4.17 and it's too difficult to migrate to the version 3 in my project.
Right after putting the entry with the key "abc", the method containsKey() returns false for the key "abc". I'm confused why it wouldn't work. The String type is the default Java string that has correct hashCode() method.