我有以下类我想用作我正在实现的地图的值:
import java.util.ArrayList;
import java.util.List;
import net.openhft.chronicle.bytes.BytesMarshallable;
import org.apache.commons.lang3.tuple.Pair;
public class GlossesLexicalizations implements BytesMarshallable {
List<String> glosses = new ArrayList<String>();
List<Pair<String, POS.Tag>> lexicalizations = new ArrayList<Pair<String, POS.Tag>>();
public GlossesLexicalizations(){
}
public GlossesLexicalizations(List<String> g, List<Pair<String, POS.Tag>> l){
glosses = g;
lexicalizations = l;
}
public void setGlosses(List<String> l){
glosses = l;
}
public void setLexicalizations(List<Pair<String, POS.Tag>> l){
lexicalizations = l;
}
public List<String> getGlosses(){
return glosses;
}
public List<Pair<String, POS.Tag>> getLexicalizations(){
return lexicalizations;
}
}
我实现BytesMarshallable
了 ChronicleMap 可以使用它。
然后我创建数据库:
File file = new File("/home/sandor/Desktop/lexicalizations-and-glosses-map.bin");
String key = "bn:14232961n"; // example
List<String> glosses = bn.getGlosses(key, ULocale.US);
List<Pair<String, POS.Tag>> lexicalizations = bn.getLexicalizations(key, ULocale.US);
ChronicleMap<String, GlossesLexicalizations> lexicalizationGraph = ChronicleMap
.of(String.class, GlossesLexicalizations.class)
.name("lexicalizations-and-glosses")
.constantKeySizeBySample("bn:14271053n")
.entries(100) // poner number of entries + 15% extra
.createOrRecoverPersistedTo(file);
GlossesLexicalizations gl = new GlossesLexicalizations(glosses, lexicalizations);
lexicalizationGraph.put(key, gl);
lexicalizationGraph.close();
这给了我以下错误:
Value size in serialized form must be configured in ChronicleMap, at least approximately. Use builder.averageValue()/.constantValueSizeBySample()/.averageValueSize() methods to configure the size
我可以理解字符串的平均值大小,但是你为一个类做什么?