1、结构图

2、SplittingIterator

抽象出模板方法,computeNext方法提供了解析分隔符的逻辑

protected String computeNext() {/** The returned string will be from the end of the last match to the beginning of the next* one. nextStart is the start position of the returned substring, while offset is the place* to start looking for a separator.*/int nextStart = offset;while (offset != -1) {int start = nextStart;int end;int separatorPosition = separatorStart(offset);if (separatorPosition == -1) {end = toSplit.length();offset = -1;} else {end = separatorPosition;offset = separatorEnd(separatorPosition);}if (offset == nextStart) {/** This occurs when some pattern has an empty match, even if it doesn't match the empty* string -- for example, if it requires lookahead or the like. The offset must be* increased to look for separators beyond this point, without changing the start position* of the next returned substring -- so nextStart stays the same.*/offset++;if (offset > toSplit.length()) {offset = -1;}continue;}while (start < end && trimmer.matches(toSplit.charAt(start))) {start++;}while (end > start && trimmer.matches(toSplit.charAt(end - 1))) {end--;}if (omitEmptyStrings && start == end) {// Don't include the (unused) separator in next split string.nextStart = offset;continue;}if (limit == 1) {// The limit has been reached, return the rest of the string as the// final item. This is tested after empty string removal so that// empty strings do not count towards the limit.end = toSplit.length();offset = -1;// Since we may have changed the end, we need to trim it again.while (end > start && trimmer.matches(toSplit.charAt(end - 1))) {end--;}} else {limit--;}return toSplit.subSequence(start, end).toString();}return endOfData();}

guava中的Splitter相关推荐

  1. guava中 graphs 六

    2019独角兽企业重金招聘Python工程师标准>>> guava中 graphs 六 介绍 guava的common.graph 是一个图类型结构的库,也就是实体和他们之间的关系的 ...

  2. Guava中针对集合的 filter和过滤功能

    Guava中针对集合的 filter和过滤功能 博客分类:  JAVA相关 在guava库中,自带了过滤器(filter)的功能,可以用来对collection 进行过滤,先看例子: Java代码   ...

  3. 简单分析Guava中RateLimiter中的令牌桶算法的实现

    为什么80%的码农都做不了架构师?>>>    令牌桶算法是网络流量整形(Traffic Shaping)和速率限制(Rate Limiting)中最常使用的一种算法.典型情况下,令 ...

  4. java令牌桶_简单分析Guava中RateLimiter中的令牌桶算法的实现

    令牌桶算法是网络流量整形(Traffic Shaping)和速率限制(Rate Limiting)中最常使用的一种算法.典型情况下,令牌桶算法用来控制发送到网络上的数据的数目,并允许突发数据的发送. ...

  5. Guava中基础工具类Joiner的使用字符串拼接方法 joiner.on

    Guava 中有一些基础的工具类,如下所列: 1,Joiner 类:根据给定的分隔符把字符串连接到一起.MapJoiner 执行相同的操作,但是针对 Map 的 key 和 value. 2,Spli ...

  6. Builder 模式在 Guava 中的应用

    在项目开发中,我们经常用到缓存.它可以非常有效地提高访问速度. 常用的缓存系统有 Redis.Memcache 等.但是,如果要缓存的数据比较少,我们完全没必要在项目中独立部署一套缓存系统.毕竟系统都 ...

  7. TCPMP中的Splitter机制

    Splitter在TCPMP中主要是通过InputThread线程和主线程中的Format_FillQueue()函数实现的. InputThread线程中主要通过调用Format_ReadInput ...

  8. guava中Multiset、HashMultiset使用分析

    guava包中提供了Multiset接口,这个接口没有实现java.util.Set接口,Set接口规定里面是不能够放入重复的元素,如果放入重复元素会被覆盖掉的:然而Multiset接口却是可以放入重 ...

  9. 才从Guava中明白了一件事:不可变特性与防御性编程

    一.面试常谈:String类与不可变特性 问:String类是可变的吗? 答:emm--由于String类的底层是final关键字修饰,因此它是不可变的. 问:它被设计为不可变的好处有哪些呢? 答: ...

最新文章

  1. React | Expected an assignment or function call and instead saw.....
  2. C# DirectX 开发2 - 定义一个矩阵和赋值
  3. git 上的pull request 是什么意思?
  4. java gsp_GSP序列模式分析算法
  5. CentOS 7.2安装Jenkins自动构建Git项目
  6. 14怎么敷铜不了_YEO护肤课堂:敷面膜有什么误区?我们应该如何选择面膜?
  7. Notepad++ 使用心得
  8. Vue引入vue-qr组件实现生成二维码,且实现在二维码中间加入logo图片功能
  9. linux安装CacheCloud
  10. java实现聊天室(websocket)
  11. 解决Shiro 加权限注解失效 或者报错 This subject is anonymous
  12. Sublime Text3 Mac版去掉自动更新和添加中文
  13. 泛泰binx和ota升级包下载工具Android版[2013.6.7提供源代码]
  14. chrome浏览器改为黑色背景
  15. 做好OKR目标管理,迈出高效协作的第一步
  16. Verilog HDL 快速入门
  17. 《Python编程从入门到实践 第二版》第十八章练习
  18. ESP32C3基于Arduino框架下的 ESP32 RainMaker开发示例教程
  19. PTA数据结构-07-图6 旅游规划
  20. 反arp攻击软件_技术干货透析中间人攻击

热门文章

  1. vue+webpack热替换
  2. 【模拟】谁拿了最多奖学金
  3. MAMP mac下启动Mysql
  4. 团队项目技术规格说明书---客户端
  5. Agent admitted failure to sign using the key
  6. 以下选项不是python文件读操作的是-以下选项中,不是Python中文件操作的相关函数是()...
  7. 研究生自学python好找工作么-学完Python好找工作吗?为什么有人学完找不到工作?...
  8. python这个软件学会能做什么工作-工作三年却被实习生抢了饭碗,学会Python到底有多吃香?...
  9. python新手项目-推荐:一个适合于Python新手的入门练手项目
  10. python代码案例详解-新手必学Python爬虫之Scrapy框架案例详解