[英]Guava Maps.difference with wildcard
I want to use Guava's Maps.difference
in java 11 to verify data from Json String which I mapped into a Map.我想在 java 11 中使用番石榴的Maps.difference
来验证来自 Json 字符串的数据,我将其映射到 Map。
What I have after a call (with different uid each time):通话后我有什么(每次都有不同的 uid):
{"uid":"31a340bc-e5ed-440c-8726-34c54dea902a","name":"Jean"}
I want to verify that uid is correctly generated and name is "Jean" using a pattern like this:我想使用如下模式验证 uid 是否正确生成并且名称为“Jean”:
{"uid":"*","name":"Jean"}
Of course Maps.difference
returns a difference in uid value...当然Maps.difference
返回 uid 值的差异......
Is it possible to specify a wildcard in my verifying pattern so that Maps.difference
returns no differences?是否可以在我的验证模式中指定一个通配符,以便Maps.difference
不返回差异?
Thanks in advance.提前致谢。
Assuming you mean Guava's Maps.difference
: yes, use the difference(left, right, valueEquivalence)
overload :假设你的意思是番石榴的Maps.difference
:是的,使用difference(left, right, valueEquivalence)
重载:
Maps.difference(left, right, new Equivalence<String>() {
@Override public boolean doEquivalent(String a, String b) {
return "*".equals(a) || "*".equals(b) || Objects.equals(a, b);
}
// You have to hash all strings to the same thing because you
// don't know if the current item is a "*", or its corresponding
// item is a "*". But actually it doesn't matter, because I don't
// think it's invoked in difference.
@Override public int doHash(String s) { return 0; }
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.