eclipse 隐藏项目

Eclipse Collections是一个开放源代码Java Collections框架。 请参阅博客末尾的资源以获取有关该框架的更多信息。 在此博客中,我将演示该框架的五个鲜为人知的功能。

  1. distinct() :要在List获得唯一项时,获取它们的典型方法是将List添加到Set 。 但是,您将失去原始顺序,并最终导致哈希表的顺序无法预测。 有时,您需要保留访问独特元素的顺序。 我们为此用例开发了distinct() 。 当您在Eclipse Collections MutableList上调用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收藏列表,你可以使用ListAdapterListIterate得到相同的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);
    }
  2. 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());
    }
  3. 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);
    }
  4. 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);
    }
  5. as VS to命名约定:在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收藏品的隐藏宝藏相关推荐

  1. eclipse使用教程_Eclipse系列的隐藏宝藏– 2019年版

    eclipse使用教程 Eclipse Collections是一个开放源代码Java Collections框架. 在此博客中,我将演示该框架的五个鲜为人知的功能. 我在去年的Java Advent ...

  2. eclipse 隐藏项目_前5个有用的隐藏Eclipse功能

    eclipse 隐藏项目 Eclipse是野兽. 仅凭其力量才能超越其神秘感的设备. 有人将其称为连续体跨功能器 . 其他人则称它为透湿器 . 是的,它是如此之大,需要花费数年才能掌握. 然后,您的经 ...

  3. eclipse项目如何变成web项目_Eclipse中将Java项目转换成Web项目的方法

    前言: 用Eclipse开发项目的时候,把一个Web项目导入到Eclipse里会变成了一个java工程,将无法在Tomcat中进行部署运行. 方法: 1.找到.project文件,找到里面的标签,查看 ...

  4. eclipse导出项目源码_eclipse怎么导出源码

    那不太容易了,在eclipse里新建一个web项目,它就有src目录,把它复制进去就行了.当然如果它是eclipse项目的话,直接导入就行了.它会自动编译的 . eclipse打开并运行一个已经写好的 ...

  5. php如何隐藏入口文件,PHP怎样隐藏入口文件

    这次给大家带来PHP怎样隐藏入口文件,PHP隐藏入口文件的注意事项有哪些,下面就是实战案例,一起来看一下. 第一步:开启apache重写模块 重启apache LoadModule rewrite_m ...

  6. cad2010怎么隐藏标注尺寸,cad2007怎么隐藏标注尺寸

    1.CAD2007怎么隐藏所有的标注尺寸? 1.在"查看器"菜单面板中隐藏的工具有"线宽"."测量"."文本"三种工具, ...

  7. 案例分享:Qt多通道数据采集系统(通道配置、电压转换、采样频率、通道补偿值、定时采集、导出excel和图表、自动XY轴、隐藏XY轴、实时隐藏显示通道)

    若该文为原创文章,转载请注明原文出处 本文章博客地址:https://blog.csdn.net/qq21497936/article/details/110941614 长期持续带来更多项目与技术分 ...

  8. Eclipse导入项目: No projects are found to import

    Eclipse导入项目: No projects are found to import  如果发导入工程import的时候,出现"No projects are found to impo ...

  9. Oracle加入Eclipse MicroProfile项目

    Oracle在决定将Java EE技术的管理权移交给开源Eclipse基金会并创建EE4J项目之后,现在加入了Eclipse MicroProfile项目. \\ MicroProfile是企业级Ja ...

最新文章

  1. 软件开发经验总结(五)读源代码的艺术
  2. 在桌面应用程序与Web应用程序之间该如何选择
  3. python库_计算机二级教程 Python语言程序设计,第10章python第三方库概览
  4. 【Ubuntu-ROS】ubuntu16.04(18.04)ROS安装配置与卸载
  5. 王炸!Azure云助力.NET6现高光时刻(VS2022实战尝鲜)
  6. vue 自定义 移动端筛选条件
  7. angular自带的一些api_Angular API
  8. javascript HTMLMediaElement
  9. sql2005 脚本中给字段写说明
  10. Retrofit之OkhttpCall执行原理详解
  11. 北京无人驾驶路测进入“主驾无人”阶段
  12. x80hd装linux,平板垃圾佬 篇五:台电也能打十个!x80hd双系统8寸的身体2G+32G的心胸~...
  13. 完美解决idea Maven Cannot reconnect
  14. eclipse:解决 The word is not correctly spelled问题
  15. c语言西南交通大学出版社答案,西南交通大学C++上机实验答案
  16. Centos安装google浏览器01
  17. Kafka: Consumer
  18. 一个Java 程序的主方法_java application程序中,每一个类中,必有一个主方法main()方法。...
  19. 二维码名片的格式 - vcard
  20. 树莓派指定挂载点挂载移动硬盘

热门文章

  1. ZF 0017-192 4161 111 063
  2. 西游记:抒发人性的幻想喜剧
  3. IP地址与网络上的其他系统有冲突的解决办法:
  4. 7.14-学姐学开车.c++
  5. 百度搜索留痕推广资源整理如何收录排名的?
  6. 排序算法:插入排序(Python)
  7. Python中单引号、双引号和三引号作用及区别
  8. 文件无法删除,需要管理员权限
  9. sql server 空间数据(geometry类型)创建、查询、空间分析和计算
  10. 使用Notepad++配置C/C++开发环境(笔记)