This commit is contained in:
Looly 2022-03-28 13:49:33 +08:00
parent f69d49593b
commit 78f5e94652
7 changed files with 39 additions and 20 deletions

View File

@ -2,19 +2,21 @@ package cn.hutool.bloomfilter;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.HashUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.BitSet;
/**
* BloomFilter实现方式2此方式使用BitSet存储<br>
* Hash算法的使用使用固定顺序只需指定个数即可
* @author loolly
*
* @author loolly
*/
public class BitSetBloomFilter implements BloomFilter{
public class BitSetBloomFilter implements BloomFilter {
private static final long serialVersionUID = 1L;
private final BitSet bitSet;
@ -36,25 +38,39 @@ public class BitSetBloomFilter implements BloomFilter{
this.bitSet = new BitSet(this.bitSetSize);
}
/**
* 通过文件初始化过滤器.
*
* @param path 文件路径
* @param charsetName 字符集
* @throws IOException IO异常
* @deprecated 请使用 {@link #init(String, Charset)}
*/
@Deprecated
public void init(String path, String charsetName) throws IOException {
init(path, CharsetUtil.charset(charsetName));
}
/**
* 通过文件初始化过滤器.
*
* @param path 文件路径
* @param charset 字符集
* @throws IOException IO异常
* @since 5.8.0
*/
public void init(String path, String charset) throws IOException {
public void init(String path, Charset charset) throws IOException {
BufferedReader reader = FileUtil.getReader(path, charset);
try {
String line;
while(true) {
while (true) {
line = reader.readLine();
if(line == null) {
if (line == null) {
break;
}
this.add(line);
}
}finally {
} finally {
IoUtil.close(reader);
}
}
@ -75,6 +91,7 @@ public class BitSetBloomFilter implements BloomFilter{
/**
* 判定是否包含指定字符串
*
* @param str 字符串
* @return 是否包含存在误差
*/
@ -107,7 +124,7 @@ public class BitSetBloomFilter implements BloomFilter{
*/
public static int[] createHashes(String str, int hashNumber) {
int[] result = new int[hashNumber];
for(int i = 0; i < hashNumber; i++) {
for (int i = 0; i < hashNumber; i++) {
result[i] = hash(str, i);
}
@ -116,6 +133,7 @@ public class BitSetBloomFilter implements BloomFilter{
/**
* 计算Hash值
*
* @param str 被计算Hash的字符串
* @param k Hash算法序号
* @return Hash值

View File

@ -137,7 +137,8 @@ public class CronPattern {
}
/**
* 返回匹配到的下一个时间
* 返回匹配到的下一个时间<br>
* TODO 周定义后结果错误需改进
*
* @param calendar 时间
* @return 匹配到的下一个时间

View File

@ -56,7 +56,7 @@ public class VelocityTemplate extends AbstractTemplate implements Serializable {
if(null == charset) {
loadEncoding();
}
render(bindingMap, IoUtil.getWriter(out, this.charset));
render(bindingMap, IoUtil.getWriter(out, CharsetUtil.charset(this.charset)));
}
/**

View File

@ -1,6 +1,7 @@
package cn.hutool.json.test.bean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.HashMap;
import java.util.Map;
@ -10,6 +11,7 @@ import java.util.Map;
* @version 创建时间2017年9月13日 下午5:16:32
* 类说明
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class PerfectEvaluationProductResVo extends ProductResBase {
private static final long serialVersionUID = 1L;

View File

@ -3,9 +3,10 @@ package cn.hutool.json.xml;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.json.XML;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Test;
import org.hamcrest.CoreMatchers;
public class XMLTest {
@ -15,7 +16,7 @@ public class XMLTest {
.set("aaa", "你好")
.set("键2", "test");
final String s = JSONUtil.toXmlStr(put);
Assert.assertThat(s, CoreMatchers.anyOf(CoreMatchers.is("<aaa>你好</aaa><键2>test</键2>"), CoreMatchers.is("<键2>test</键2><aaa>你好</aaa>")));
MatcherAssert.assertThat(s, CoreMatchers.anyOf(CoreMatchers.is("<aaa>你好</aaa><键2>test</键2>"), CoreMatchers.is("<键2>test</键2><aaa>你好</aaa>")));
}
@Test

View File

@ -58,7 +58,6 @@ public class NullCell implements Cell {
return this.row;
}
@Override
public void setCellType(CellType cellType) {
throw new UnsupportedOperationException("Can not set any thing to null cell!");
}

View File

@ -11,8 +11,8 @@ import cn.hutool.poi.excel.sax.handler.RowHandler;
import cn.hutool.poi.exceptions.POIException;
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.ooxml.util.SAXHelper;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.util.XMLHelper;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.xml.sax.ContentHandler;
@ -168,9 +168,7 @@ public class ExcelSaxUtil {
public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws DependencyException, POIException, IORuntimeException {
XMLReader xmlReader;
try {
// xmlReader = XMLReaderFactory.createXMLReader();
//noinspection deprecation
xmlReader = SAXHelper.newXMLReader();
xmlReader = XMLHelper.newXMLReader();
} catch (SAXException | ParserConfigurationException e) {
if (e.getMessage().contains("org.apache.xerces.parsers.SAXParser")) {
throw new DependencyException(e, "You need to add 'xerces:xercesImpl' to your project and version >= 2.11.0");