eclipse 隐藏项目_Eclipse收藏品的隐藏宝藏
eclipse 隐藏项目
Eclipse Collections是一个开放源代码Java Collections框架。 请参阅博客末尾的资源以获取有关该框架的更多信息。 在此博客中,我将演示该框架的五个鲜为人知的功能。
distinct()
:要在List
获得唯一项时,获取它们的典型方法是将List
添加到Set
。 但是,您将失去原始顺序,并最终导致哈希表的顺序无法预测。 有时,您需要保留访问独特元素的顺序。 我们为此用例开发了distinct()
。 当您在Eclipse CollectionsMutableList
上调用distinct()
时,结果是一个唯一元素List
。@Test public void distinct() {MutableList<Integer> integers = Lists.mutable.with(1, 2, 2, 3, 3, 3, 4, 4, 4, 4);Assert.assertEquals(Lists.mutable.with(1, 2, 3, 4), integers.distinct()); }
如果你不能你原来的转换
List
到Eclipse收藏列表,你可以使用ListAdapter
或ListIterate
得到相同的API。@Test public void distinctNonEclipseCollectionsList() {List<Integer> integersLinkedList = new LinkedList<>(integers);Assert.assertEquals(Lists.mutable.with(1, 2, 3, 4),ListAdapter.adapt(integersLinkedList).distinct());Assert.assertEquals(Lists.mutable.with(1, 2, 3, 4),ListIterate.distinct(integersLinkedList)); }
如果您需要
distinct()
来进行惰性评估,那么它也可以在我们的LazyIterable
中使用。@Test public void distinctAsLazy() {MutableList<String> distinctStrings = integers.asLazy().distinct().collect(String::valueOf).toList();Assert.assertEquals(Lists.mutable.with("1", "2", "3", "4"),distinctStrings); }
partition()
:当您要基于谓词在一次通过中选择和拒绝元素时,可以使用partition()
@Test public void partition() {MutableList<Integer> integers = Lists.mutable.with(1, 2, 3, 4, 5, 6, 7, 8, 9);PartitionMutableList<Integer> evenOddPartition = integers.partition(each -> each % 2 == 0);Assert.assertEquals(Lists.mutable.with(2, 4, 6, 8),evenOddPartition.getSelected());Assert.assertEquals(Lists.mutable.with(1, 3, 5, 7, 9),evenOddPartition.getRejected()); }
如果您不能使用Eclipse Collections接口,则可以始终使用我们的适配器包装您的集合,或使用我们的静态实用程序
Iterate
获取相同的API。@Test public void partition() {List<Integer> integerList = new ArrayList<>(integers);PartitionMutableList<Integer> evenOddUsingAdapter =ListAdapter.adapt(integerList).partition(each -> each % 2 == 0);Assert.assertEquals(Lists.mutable.with(2, 4, 6, 8),evenOddUsingAdapter.getSelected());Assert.assertEquals(Lists.mutable.with(1, 3, 5, 7, 9),evenOddUsingAdapter.getRejected());PartitionIterable<Integer> evenOddUsingIterate =Iterate.partition(integerList,each -> each % 2 == 0);Assert.assertEquals(Lists.mutable.with(2, 4, 6, 8),evenOddUsingIterate.getSelected());Assert.assertEquals(Lists.mutable.with(1, 3, 5, 7, 9),evenOddUsingIterate.getRejected()); }
selectInstancesOf()
:如果要过滤并仅返回特定类的实例,则可以使用selectInstancesOf()。@Test public void selectInstancesOf() {MutableList<Number> numbers = Lists.mutable.with(1.0, 2, 3.0, 4.0, 5);MutableList<Integer> integers = numbers.selectInstancesOf(Integer.class);Assert.assertEquals(Lists.mutable.with(2, 5), integers); }
如果您不能使用Eclipse Collections接口,则可以始终使用我们的适配器包装您的集合,或使用我们的静态实用程序
Iterate
获取相同的API。@Test public void selectInstancesOf() {List<Number> numberList = new ArrayList<>(numbers);MutableList<Integer> integersUsingAdapter = ListAdapter.adapt(numberList).selectInstancesOf(Integer.class);Assert.assertEquals(Lists.mutable.with(2, 5), integersUsingAdapter);Collection<Integer> integersUsingIterate = Iterate.selectInstancesOf(numberList, Integer.class);Assert.assertEquals(Lists.mutable.with(2, 5), integersUsingIterate); }
chunk()
:如果您想将可迭代对象划分为特定大小的多个可迭代对象,则可以使用chunk()
。@Test public void chunk() {MutableList<Integer> integers = Lists.mutable.with(1, 2, 3, 4, 5);MutableList<MutableList<Integer>> expectedChunked =Lists.mutable.with(Lists.mutable.with(1, 2),Lists.mutable.with(3, 4),Lists.mutable.with(5));Assert.assertEquals(expectedChunked, integers.chunk(2)); }
如果您不能使用Eclipse Collections接口,则可以始终使用我们的适配器包装您的集合,或使用我们的静态实用程序
Iterate
获取相同的API。@Test public void chunk() {List<Integer> integerList = new ArrayList<>(integers);RichIterable<RichIterable<Integer>> chunkUsingAdapter =ListAdapter.adapt(integerList).chunk(2);Assert.assertEquals(expectedChunked,chunkUsingAdapter);RichIterable<RichIterable<Integer>> chunkUsingIterate = Iterate.chunk(integerList, 2);Assert.assertEquals(expectedChunked,chunkUsingIterate); }
as
VSto
命名约定:在Eclipse集合,我们尽量按照就像这个所描述的共同约定博客以单词开始。在Eclipse的集合,方法“为”始终以恒定的时间,创造常数垃圾。 通常,这意味着返回包装器对象。 一些例子:asUnmodifiable()
–返回引发变异方法的集合包装器asSynchronized()
–返回在委派之前获取锁定的集合包装器asLazy()
–通过推迟非终止操作的评估并仅在遇到终止操作时进行评估,返回支持延迟评估的包装器asReversed()
–返回列表周围的延迟包装器,当强制执行计算时,列表以相反顺序迭代asParallel()
(Beta) –返回支持并行执行的惰性包装器
在Eclipse Collections中,以“ to”开头的方法可能会花费更多时间并产生更多垃圾。 大多数情况下,这意味着要在线性时间内创建一个新集合。 在排序集合的情况下,它增长为O(n log n)。 一些例子:
toList()
–始终创建一个新副本,即使在列表上调用时也是如此toSet()
,toBag()
,toStack()
,toMap()
,toArray()
– O(n)在时间和内存上toSortedList()
,toSortedListBy()
,toSortedSet()
,toSortedSetBy()
,toSortedMap()
– O(n log n)时间toImmutable()
–可变集合的O(n)时间toReversed()
-同asReversed()
但将有急于评价toString()
–是的,它计数为&#55357;&#56898;
摘要:
在这个博客中,我解释了Eclipse集合中鲜为人知的一些特性,这些特性包括distinct(),partition(),selectInstancesOf(),chunk()以及as ()vs to ()方法命名约定。
希望您发现该信息丰富。 如果您以前没有使用过Eclipse Collections,请尝试一下。 下面的资源很少。 确保向我们展示您的支持,并在我们的GitHub存储库上加注星号
Eclipse Collections资源:
Eclipse Collections附带了List , Set和Map自己的实现。 它还具有其他数据结构,例如Multimap , Bag和整个Primitive Collections层次结构。 我们的每个集合都有一个丰富的API,可用于通常需要的迭代模式。
翻译自: https://www.javacodegeeks.com/2018/12/hidden-treasures-eclipse-collections.html
eclipse 隐藏项目
eclipse 隐藏项目_Eclipse收藏品的隐藏宝藏相关推荐
- eclipse使用教程_Eclipse系列的隐藏宝藏– 2019年版
eclipse使用教程 Eclipse Collections是一个开放源代码Java Collections框架. 在此博客中,我将演示该框架的五个鲜为人知的功能. 我在去年的Java Advent ...
- eclipse 隐藏项目_前5个有用的隐藏Eclipse功能
eclipse 隐藏项目 Eclipse是野兽. 仅凭其力量才能超越其神秘感的设备. 有人将其称为连续体跨功能器 . 其他人则称它为透湿器 . 是的,它是如此之大,需要花费数年才能掌握. 然后,您的经 ...
- eclipse项目如何变成web项目_Eclipse中将Java项目转换成Web项目的方法
前言: 用Eclipse开发项目的时候,把一个Web项目导入到Eclipse里会变成了一个java工程,将无法在Tomcat中进行部署运行. 方法: 1.找到.project文件,找到里面的标签,查看 ...
- eclipse导出项目源码_eclipse怎么导出源码
那不太容易了,在eclipse里新建一个web项目,它就有src目录,把它复制进去就行了.当然如果它是eclipse项目的话,直接导入就行了.它会自动编译的 . eclipse打开并运行一个已经写好的 ...
- php如何隐藏入口文件,PHP怎样隐藏入口文件
这次给大家带来PHP怎样隐藏入口文件,PHP隐藏入口文件的注意事项有哪些,下面就是实战案例,一起来看一下. 第一步:开启apache重写模块 重启apache LoadModule rewrite_m ...
- cad2010怎么隐藏标注尺寸,cad2007怎么隐藏标注尺寸
1.CAD2007怎么隐藏所有的标注尺寸? 1.在"查看器"菜单面板中隐藏的工具有"线宽"."测量"."文本"三种工具, ...
- 案例分享:Qt多通道数据采集系统(通道配置、电压转换、采样频率、通道补偿值、定时采集、导出excel和图表、自动XY轴、隐藏XY轴、实时隐藏显示通道)
若该文为原创文章,转载请注明原文出处 本文章博客地址:https://blog.csdn.net/qq21497936/article/details/110941614 长期持续带来更多项目与技术分 ...
- Eclipse导入项目: No projects are found to import
Eclipse导入项目: No projects are found to import 如果发导入工程import的时候,出现"No projects are found to impo ...
- Oracle加入Eclipse MicroProfile项目
Oracle在决定将Java EE技术的管理权移交给开源Eclipse基金会并创建EE4J项目之后,现在加入了Eclipse MicroProfile项目. \\ MicroProfile是企业级Ja ...
最新文章
- 软件开发经验总结(五)读源代码的艺术
- 在桌面应用程序与Web应用程序之间该如何选择
- python库_计算机二级教程 Python语言程序设计,第10章python第三方库概览
- 【Ubuntu-ROS】ubuntu16.04(18.04)ROS安装配置与卸载
- 王炸!Azure云助力.NET6现高光时刻(VS2022实战尝鲜)
- vue 自定义 移动端筛选条件
- angular自带的一些api_Angular API
- javascript HTMLMediaElement
- sql2005 脚本中给字段写说明
- Retrofit之OkhttpCall执行原理详解
- 北京无人驾驶路测进入“主驾无人”阶段
- x80hd装linux,平板垃圾佬 篇五:台电也能打十个!x80hd双系统8寸的身体2G+32G的心胸~...
- 完美解决idea Maven Cannot reconnect
- eclipse:解决 The word is not correctly spelled问题
- c语言西南交通大学出版社答案,西南交通大学C++上机实验答案
- Centos安装google浏览器01
- Kafka: Consumer
- 一个Java 程序的主方法_java application程序中,每一个类中,必有一个主方法main()方法。...
- 二维码名片的格式 - vcard
- 树莓派指定挂载点挂载移动硬盘