package java.util;import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;/*** 集合层次结构的根接口,一个集合表示一组对象,称为元素* JDK不提供任何该接口的直接实现,JDK提供实现特定情况的子接口,Set,List** 所有通用Collection实现类通常需要通过一个间接实现Collection接口的子接口来实现,* 而且需要提供两个标准的构造函数,没有参数的构造函数(空参构造),创建一个空集合;* 以及包含Collection类型的单个参数的构造函数,使用与其参数相同的元素创建一个新集合。* @author  Josh Bloch* @author  Neal Gafter* @see     Set* @see     List* @see     Map* @see     SortedSet* @see     SortedMap* @see     HashSet* @see     TreeSet* @see     ArrayList* @see     LinkedList* @see     Vector* @see     Collections* @see     Arrays* @see     AbstractCollection* @since 1.2*/
public interface Collection<E> extends Iterable<E> {// 查询操作/*** 返回此集合中的元素数。如果这个集合 包含多于<tt> Integer.MAX_VALUE </ tt>的元素,返回 <tt> Integer.MAX_VALUE </ tt>。** @return 此集合中的元素数量*/int size();/*** 如果此集合不包含任何元素,则返回<tt> true </ tt>* @return <tt>true</tt> 如果此集合不包含任何元素*/boolean isEmpty();/**** 如果集合中包含至少一个指定对象,返回true* @param o 要测试其在此集合中的存在的元素* @return <tt>true</tt>  如果集合中包含该元素** @throws ClassCastException 如果指定元素的类型 与集合内元素类型不兼容* @throws NullPointerException 如果指定的元素为null且此 collection不允许null元素**/boolean contains(Object o);/*** 返回此集合中元素的迭代器。无法保证元素的返回顺序*(除非此集合是某个提供保证的类的实例)。** @return an <tt>Iterator</tt> 覆盖此集合中的元素*/Iterator<E> iterator();/*** 返回包含此集合中所有元素的数组。* 如果此集合对其迭代器返回的元素的顺序做出任何保证,则此方法必须以相同的顺序返回元素。** 返回的数组将是“安全的”,因为此集合不会保留对它的引用。* (换句话说,即使此集合由数组支持,此方法也必须分配新数组)。*  调用者因此可以自由修改返回的数组。** @return 包含此集合中所有元素的数组*/Object[] toArray();/*** 返回包含此集合中所有元素的数组;* 返回数组的运行时类型是指定数组的运行时类型。* 如果集合适合指定的数组,则返回元素到指定的数组中。* 否则,将使用指定数组的运行时类型和此集合的大小分配新数组。** 此集合适合指定的数组,如果有空余空间(即,数组的元素多于此集合),则紧跟集合结尾的数组中的元素将设置为<tt> null </ TT>。* (如果调用者知道此集合不包含任何<tt> null </ tt>元素,则此选项仅用于确定此集合的长度<i> </ i>。)** 如果此集合对其迭代器返回的元素的顺序做出任何保证,则此方法必须以相同的顺序返回元素。** @param <T> 包含集合的数组的运行时类型* @throws ArrayStoreException 如果指定数组的运行时类型不是此集合中每个元素的运行时类型的超类型* @throws NullPointerException 如果指定的数组为null*/<T> T[] toArray(T[] a);// 修改操作/*** 将元素e添加到集合中* 如果集合不允许重复元素,且集合中已经含有该元素,返回false* false-添加失败*/boolean add(E e);/*** 从该 collection 中移除指定元素的单个实例,如果集合中存在指定元素返回true。*/boolean remove(Object o);// 批量操作/*** 如果此 collection 包含指定 collection 中的所有元素,则返回 true。*/boolean containsAll(Collection<?> c);/*** 将指定 collection 中的所有元素都添加到此 collection 中*/boolean addAll(Collection<? extends E> c);/*** 移除此 collection 中那些也包含在指定 collection 中的所有元素(可选操作)。*/boolean removeAll(Collection<?> c);/**** 删除此集合中满足给定布尔值函数的所有元素。在迭代期间或通过布尔值函数抛出的错误或运行时异常被中继到调用者。* 默认使用迭代器进行删除元素** @param filter 一个布尔值函数,它返回{@code true}表示要删除的元素* @return {@code true} 如果删除了任何元素* @since 1.8*/default boolean removeIf(Predicate<? super E> filter) {Objects.requireNonNull(filter);boolean removed = false;final Iterator<E> each = iterator();while (each.hasNext()) {if (filter.test(each.next())) {each.remove();removed = true;}}return removed;}/**** 仅保留此集合中包含在指定集合中的元素。换句话说,从此集合中删除未包含在指定集合中的所有元素。*/boolean retainAll(Collection<?> c);/*** 移除此 collection 中的所有元素。*/void clear();// 比较和散列/***  比较此 collection 与指定对象是否相等。通过覆盖,实现list与list相等,set与set相等*/boolean equals(Object o);/*** 返回此 collection 的哈希码值。*/int hashCode();/**** Spliterator是一个可分割迭代器(splitable iterator),可以和iterator顺序遍历迭代器一起看。jdk1.8发布后,对于并行处理的能力大大增强,Spliterator就是为了并行遍历元素而设计的一个迭代器,jdk1.8中的集合框架中的数据结构都默认实现了spliterator** 在此集合中的元素上创建{@link Spliterator}。** 后续如果讲到了{@link Spliterator}再进行补充下面的三个方法*** Implementations should document characteristic values reported by the* spliterator.  Such characteristic values are not required to be reported* if the spliterator reports {@link Spliterator#SIZED} and this collection* contains no elements.** <p>The default implementation should be overridden by subclasses that* can return a more efficient spliterator.  In order to* preserve expected laziness behavior for the {@link #stream()} and* {@link #parallelStream()}} methods, spliterators should either have the* characteristic of {@code IMMUTABLE} or {@code CONCURRENT}, or be* <em><a href="Spliterator.html#binding">late-binding</a></em>.* If none of these is practical, the overriding class should describe the* spliterator's documented policy of binding and structural interference,* and should override the {@link #stream()} and {@link #parallelStream()}* methods to create streams using a {@code Supplier} of the spliterator,* as in:* <pre>{@code*     Stream<E> s = StreamSupport.stream(() -> spliterator(), spliteratorCharacteristics)* }</pre>* <p>These requirements ensure that streams produced by the* {@link #stream()} and {@link #parallelStream()} methods will reflect the* contents of the collection as of initiation of the terminal stream* operation.** @implSpec* The default implementation creates a* <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator* from the collections's {@code Iterator}.  The spliterator inherits the* <em>fail-fast</em> properties of the collection's iterator.* <p>* The created {@code Spliterator} reports {@link Spliterator#SIZED}.** @implNote* The created {@code Spliterator} additionally reports* {@link Spliterator#SUBSIZED}.** <p>If a spliterator covers no elements then the reporting of additional* characteristic values, beyond that of {@code SIZED} and {@code SUBSIZED},* does not aid clients to control, specialize or simplify computation.* However, this does enable shared use of an immutable and empty* spliterator instance (see {@link Spliterators#emptySpliterator()}) for* empty collections, and enables clients to determine if such a spliterator* covers no elements.** @return a {@code Spliterator} over the elements in this collection* @since 1.8*/@Overridedefault Spliterator<E> spliterator() {return Spliterators.spliterator(this, 0);}/*** Returns a sequential {@code Stream} with this collection as its source.** <p>This method should be overridden when the {@link #spliterator()}* method cannot return a spliterator that is {@code IMMUTABLE},* {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}* for details.)** @implSpec* The default implementation creates a sequential {@code Stream} from the* collection's {@code Spliterator}.** @return a sequential {@code Stream} over the elements in this collection* @since 1.8*/default Stream<E> stream() {return StreamSupport.stream(spliterator(), false);}/*** Returns a possibly parallel {@code Stream} with this collection as its* source.  It is allowable for this method to return a sequential stream.** <p>This method should be overridden when the {@link #spliterator()}* method cannot return a spliterator that is {@code IMMUTABLE},* {@code CONCURRENT}, or <em>late-binding</em>. (See {@link #spliterator()}* for details.)** @implSpec* The default implementation creates a parallel {@code Stream} from the* collection's {@code Spliterator}.** @return a possibly parallel {@code Stream} over the elements in this* collection* @since 1.8*/default Stream<E> parallelStream() {return StreamSupport.stream(spliterator(), true);}
}

Collection源码阅读相关推荐

  1. java collection源码_jdk源码阅读Collection实例分析

    jdk源码阅读Collection详解 见过一句夸张的话,叫做"没有阅读过jdk源码的人不算学过java".从今天起开始精读源码.而适合精读的源码无非就是java.io,.util ...

  2. 转-OpenJDK源码阅读导航跟编译

    OpenJDK源码阅读导航 OpenJDK源码阅读导航 博客分类: Virtual Machine HotSpot VM Java OpenJDK openjdk 这是链接帖.主体内容都在各链接中.  ...

  3. collection 源码

    转自:http://blog.csdn.net/longlong2015/article/details/48174421 http://blog.csdn.net/mra__s__/article/ ...

  4. surefire 拉起 junit 单元测试类 源码阅读(一)

    根据surefire 拉起Junit单元测试类 输出的报错日志 跟踪执行过程: 日志1: java.lang.reflect.InvocationTargetExceptionat sun.refle ...

  5. mybatis源码阅读(二):mybatis初始化上

    转载自  mybatis源码阅读(二):mybatis初始化上 1.初始化入口 //Mybatis 通过SqlSessionFactory获取SqlSession, 然后才能通过SqlSession与 ...

  6. 源码 状态机_[源码阅读] 阿里SOFA服务注册中心MetaServer(1)

    [源码阅读] 阿里SOFA服务注册中心MetaServer(1) 0x00 摘要 0x01 服务注册中心 1.1 服务注册中心简介 1.2 SOFARegistry 总体架构 1.3 为什么要分层 0 ...

  7. Mybatis源码阅读(三):结果集映射3.2 —— 嵌套映射

    *************************************优雅的分割线 ********************************** 分享一波:程序员赚外快-必看的巅峰干货 如 ...

  8. focal loss dice loss源码_0815——W2V的TF源码阅读

    昨天开始看text matching的一个很好的资源,有文献有讲解有代码 今天看了DRCN的网络结构部分,代码部分还在进行中... 贴上原作者的地址: 文本匹配模型之DRCN - Welcome to ...

  9. Soul网关源码阅读(九)插件配置加载初探

    Soul网关源码阅读(九)插件配置加载初探 简介     今日来探索一下插件的初始化,及相关的配置的加载 源码Debug 插件初始化     首先来到我们非常熟悉的插件链调用的类: SoulWebHa ...

最新文章

  1. centos主题设置
  2. ITK:两条曲线上所有点之间的平均距离
  3. 在业务层实现校验请求参数
  4. 计算机u打字,win7电脑打字打不出来怎么办
  5. 浅谈离线化方案的探索,跨容器
  6. MySQL优化索引及优化汉字模糊查询语句
  7. PHP三种字符串界定符的区别
  8. SGU 176 Flow construction(有上下限的最小流)
  9. 前端面试-webpack篇
  10. SpringBoot技术点细解
  11. jvisualvm使用
  12. smb协议讲解_SMB/CIFS协议解析一概述
  13. 华为网络配置(DHCP)
  14. 人身三流指什么_什么是三流明星
  15. 如何对镶嵌数据集进行色彩平衡
  16. solicit报文_DHCPv6原理与配置
  17. C++ 多个指针指向同一个对象
  18. DW怎么把两个html放在一起,用Dreamweaver怎么制作网页
  19. DNS域名解析服务(正向解析)
  20. 前端(微信小程序为例)

热门文章

  1. 开源应用架构之asterisk
  2. 专家观点:你必须了解的嵌入式Linux特性
  3. python十条建议_十条建议帮你提高Python编程效率
  4. 数字时钟设计verilog_数字IC设计基本概念之创建时钟
  5. 【转】linx 设备名字来由 sd sr sg st
  6. 【转】数据库软考笔记(一)第一章 计算机硬件基础知识笔记总结
  7. 第十节:委托和事件(2)(泛型委托、Func和Action、事件及与委托的比较)
  8. [你必须知道的.NET]第十九回:对象创建始末(下)
  9. vb.net datagridview数据批量导入sql_【自学C#】|| 笔记 44 ComboBox:组合框控件数据绑定...
  10. Spark(idea)操作mysql进行查询和插入 (代码+理解)