mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
f69d49593b
commit
78f5e94652
@ -2,19 +2,21 @@ package cn.hutool.bloomfilter;
|
|||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.HashUtil;
|
import cn.hutool.core.util.HashUtil;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BloomFilter实现方式2,此方式使用BitSet存储。<br>
|
* BloomFilter实现方式2,此方式使用BitSet存储。<br>
|
||||||
* Hash算法的使用使用固定顺序,只需指定个数即可
|
* Hash算法的使用使用固定顺序,只需指定个数即可
|
||||||
* @author loolly
|
|
||||||
*
|
*
|
||||||
|
* @author loolly
|
||||||
*/
|
*/
|
||||||
public class BitSetBloomFilter implements BloomFilter{
|
public class BitSetBloomFilter implements BloomFilter {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final BitSet bitSet;
|
private final BitSet bitSet;
|
||||||
@ -36,25 +38,39 @@ public class BitSetBloomFilter implements BloomFilter{
|
|||||||
this.bitSet = new BitSet(this.bitSetSize);
|
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 path 文件路径
|
||||||
* @param charset 字符集
|
* @param charset 字符集
|
||||||
* @throws IOException IO异常
|
* @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);
|
BufferedReader reader = FileUtil.getReader(path, charset);
|
||||||
try {
|
try {
|
||||||
String line;
|
String line;
|
||||||
while(true) {
|
while (true) {
|
||||||
line = reader.readLine();
|
line = reader.readLine();
|
||||||
if(line == null) {
|
if (line == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.add(line);
|
this.add(line);
|
||||||
}
|
}
|
||||||
}finally {
|
} finally {
|
||||||
IoUtil.close(reader);
|
IoUtil.close(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,6 +91,7 @@ public class BitSetBloomFilter implements BloomFilter{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 判定是否包含指定字符串
|
* 判定是否包含指定字符串
|
||||||
|
*
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @return 是否包含,存在误差
|
* @return 是否包含,存在误差
|
||||||
*/
|
*/
|
||||||
@ -107,7 +124,7 @@ public class BitSetBloomFilter implements BloomFilter{
|
|||||||
*/
|
*/
|
||||||
public static int[] createHashes(String str, int hashNumber) {
|
public static int[] createHashes(String str, int hashNumber) {
|
||||||
int[] result = new 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);
|
result[i] = hash(str, i);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -116,6 +133,7 @@ public class BitSetBloomFilter implements BloomFilter{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算Hash值
|
* 计算Hash值
|
||||||
|
*
|
||||||
* @param str 被计算Hash的字符串
|
* @param str 被计算Hash的字符串
|
||||||
* @param k Hash算法序号
|
* @param k Hash算法序号
|
||||||
* @return Hash值
|
* @return Hash值
|
||||||
|
@ -137,7 +137,8 @@ public class CronPattern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回匹配到的下一个时间
|
* 返回匹配到的下一个时间<br>
|
||||||
|
* TODO 周定义后,结果错误,需改进
|
||||||
*
|
*
|
||||||
* @param calendar 时间
|
* @param calendar 时间
|
||||||
* @return 匹配到的下一个时间
|
* @return 匹配到的下一个时间
|
||||||
|
@ -56,7 +56,7 @@ public class VelocityTemplate extends AbstractTemplate implements Serializable {
|
|||||||
if(null == charset) {
|
if(null == charset) {
|
||||||
loadEncoding();
|
loadEncoding();
|
||||||
}
|
}
|
||||||
render(bindingMap, IoUtil.getWriter(out, this.charset));
|
render(bindingMap, IoUtil.getWriter(out, CharsetUtil.charset(this.charset)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.json.test.bean;
|
package cn.hutool.json.test.bean;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -10,6 +11,7 @@ import java.util.Map;
|
|||||||
* @version 创建时间:2017年9月13日 下午5:16:32
|
* @version 创建时间:2017年9月13日 下午5:16:32
|
||||||
* 类说明
|
* 类说明
|
||||||
*/
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class PerfectEvaluationProductResVo extends ProductResBase {
|
public class PerfectEvaluationProductResVo extends ProductResBase {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
@ -3,9 +3,10 @@ package cn.hutool.json.xml;
|
|||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.hutool.json.XML;
|
import cn.hutool.json.XML;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
|
import org.hamcrest.MatcherAssert;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
|
|
||||||
public class XMLTest {
|
public class XMLTest {
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ public class XMLTest {
|
|||||||
.set("aaa", "你好")
|
.set("aaa", "你好")
|
||||||
.set("键2", "test");
|
.set("键2", "test");
|
||||||
final String s = JSONUtil.toXmlStr(put);
|
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
|
@Test
|
||||||
|
@ -58,7 +58,6 @@ public class NullCell implements Cell {
|
|||||||
return this.row;
|
return this.row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCellType(CellType cellType) {
|
public void setCellType(CellType cellType) {
|
||||||
throw new UnsupportedOperationException("Can not set any thing to null cell!");
|
throw new UnsupportedOperationException("Can not set any thing to null cell!");
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ import cn.hutool.poi.excel.sax.handler.RowHandler;
|
|||||||
import cn.hutool.poi.exceptions.POIException;
|
import cn.hutool.poi.exceptions.POIException;
|
||||||
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
|
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
|
||||||
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
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.ss.usermodel.DataFormatter;
|
||||||
|
import org.apache.poi.util.XMLHelper;
|
||||||
import org.apache.poi.xssf.model.SharedStrings;
|
import org.apache.poi.xssf.model.SharedStrings;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
import org.xml.sax.ContentHandler;
|
import org.xml.sax.ContentHandler;
|
||||||
@ -168,9 +168,7 @@ public class ExcelSaxUtil {
|
|||||||
public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws DependencyException, POIException, IORuntimeException {
|
public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws DependencyException, POIException, IORuntimeException {
|
||||||
XMLReader xmlReader;
|
XMLReader xmlReader;
|
||||||
try {
|
try {
|
||||||
// xmlReader = XMLReaderFactory.createXMLReader();
|
xmlReader = XMLHelper.newXMLReader();
|
||||||
//noinspection deprecation
|
|
||||||
xmlReader = SAXHelper.newXMLReader();
|
|
||||||
} catch (SAXException | ParserConfigurationException e) {
|
} catch (SAXException | ParserConfigurationException e) {
|
||||||
if (e.getMessage().contains("org.apache.xerces.parsers.SAXParser")) {
|
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");
|
throw new DependencyException(e, "You need to add 'xerces:xercesImpl' to your project and version >= 2.11.0");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user