1
我有一些番石榴漏斗的问题,我读了这篇文章https://code.google.com/p/guava-libraries/wiki/HashingExplained和其他人,但我不知道如何我可以使用漏斗,当我的类不仅包含原始类型。谷歌番石榴散列
Funnel<Person> personFunnel = new Funnel<Person>() {
@Override
public void funnel(Person person, PrimitiveSink into) {
into
.putInt(person.id)
.putString(person.firstName, Charsets.UTF_8)
.putString(person.lastName, Charsets.UTF_8)
.putInt(birthYear)
//.putObject(myObject,myObjectFunnel);I want to do something like this
}
};
后,我需要做这样的
HashFunction hf = Hashing.md5();
HashCode hc = hf.newHasher()
.putObject(person, personFunnel)
.hash();
PrimitiveSink类没有putObject方法,只有散列器类有它。 我可以将myObject转换为字节数组并使用putBytes方法,但可能有人知道更好的方法。
哦,真的很不错的主意,谢谢。 – Dominic