本文整理汇总了Java中com.google.common.collect.Sets.cartesianProduct方法的典型用法代码示例。如果您正苦于以下问题:Java Sets.cartesianProduct方法的具体用法?Java Sets.cartesianProduct怎么用?Java Sets.cartesianProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Sets
的用法示例。
在下文中一共展示了Sets.cartesianProduct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCartesianProduct
import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
* Sets.cartesianProduct doesn't allow sets that contain null, but we want null to mean
* "don't call the associated CacheBuilder method" - that is, get the default CacheBuilder
* behavior. This method wraps the elements in the input sets (which may contain null) as
* Optionals, calls Sets.cartesianProduct with those, then transforms the result to unwrap
* the Optionals.
*/
private Iterable<List<Object>> buildCartesianProduct(Set<?>... sets) {
List<Set<Optional<?>>> optionalSets = Lists.newArrayListWithExpectedSize(sets.length);
for (Set<?> set : sets) {
Set<Optional<?>> optionalSet =
Sets.newLinkedHashSet(Iterables.transform(set, NULLABLE_TO_OPTIONAL));
optionalSets.add(optionalSet);
}
Set<List<Optional<?>>> cartesianProduct = Sets.cartesianProduct(optionalSets);
return Iterables.transform(cartesianProduct,
new Function<List<Optional<?>>, List<Object>>() {
@Override public List<Object> apply(List<Optional<?>> objs) {
return Lists.transform(objs, OPTIONAL_TO_NULLABLE);
}
});
}