All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.core.text.finder.LengthFinder Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.core.text.finder;

import cn.hutool.core.lang.Assert;

/**
 * 固定长度查找器
* 给定一个长度,查找的位置为from + length,一般用于分段截取 * * @since 5.7.14 * @author looly */ public class LengthFinder extends TextFinder { private static final long serialVersionUID = 1L; private final int length; /** * 构造 * @param length 长度 */ public LengthFinder(int length) { Assert.isTrue(length > 0, "Length must be great than 0"); this.length = length; } @Override public int start(int from) { Assert.notNull(this.text, "Text to find must be not null!"); final int limit = getValidEndIndex(); int result; if(negative){ result = from - length; if(result > limit){ return result; } } else { result = from + length; if(result < limit){ return result; } } return -1; } @Override public int end(int start) { return start; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy