Java中嵌套集合/结构的类型安全展平 [英] Type-safe flattening of nested collections/structures in Java

查看:266
本文介绍了Java中嵌套集合/结构的类型安全展平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中平铺任何深度嵌套的集合/结构某种类型T的元素,最好使用

I would like to flatten arbitrary deeply nested collections/structures of elements of some type T in Java, optimally with


  • 只有实时视图而不是复制的集合;

  • 不仅处理集合,而且还包括迭代器,任意维数T的数组,Iterable和所有这些结构任意混合和嵌套;

  • 静态类型安全。

这?

Guava 似乎只处理一个嵌套级别,即 Collection< Collection< T>> --flatten - > T>

Guava seems to only handle one nesting level, i.e. Collection<Collection<T>> --flatten--> Collection<T>.

lambdaj 看起来很有前途:我可以用 on() asIterator() flattenIterator()这个?以静态类型安全的方式?

lambdaj looks promising: can I somehow combine on(), asIterator() and flattenIterator() to achieve this? In a statically type-safe manner?

推荐答案

Guava可能最终支持这个:

Guava will probably support this eventually :

http:/ /code.google.com/p/guava-libraries/issues/detail?id=174

(最简单的方法是从底部阅读因为对它的思考已经在其一生中改变了几次。)

(It might be easiest to read that from the bottom up, since the thinking on it has shifted a few times over its lifetime.)

这篇关于Java中嵌套集合/结构的类型安全展平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆