mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add methods
This commit is contained in:
parent
96356cff62
commit
d690f4a2c4
@ -20,10 +20,10 @@ public interface BloomFilter extends Serializable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 在boolean的bitMap中增加一个字符串<br>
|
* 在boolean的bitMap中增加一个字符串<br>
|
||||||
* 如果存在就返回<code>false</code> .如果不存在.先增加这个字符串.再返回<code>true</code>
|
* 如果存在就返回{@code false} .如果不存在.先增加这个字符串.再返回{@code true}
|
||||||
*
|
*
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @return 是否加入成功,如果存在就返回<code>false</code> .如果不存在返回<code>true</code>
|
* @return 是否加入成功,如果存在就返回{@code false} .如果不存在返回{@code true}
|
||||||
*/
|
*/
|
||||||
boolean add(String str);
|
boolean add(String str);
|
||||||
}
|
}
|
@ -684,7 +684,7 @@ public class IoUtil extends NioUtil {
|
|||||||
* @return 内容
|
* @return 内容
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public static <T extends Collection<String>> T readLines(Reader reader, final T collection) throws IORuntimeException {
|
public static <T extends Collection<String>> T readLines(Reader reader, T collection) throws IORuntimeException {
|
||||||
readLines(reader, (LineHandler) collection::add);
|
readLines(reader, (LineHandler) collection::add);
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ public class CityHash {
|
|||||||
private static long hashLen0to16(byte[] byteArray) {
|
private static long hashLen0to16(byte[] byteArray) {
|
||||||
int len = byteArray.length;
|
int len = byteArray.length;
|
||||||
if (len >= 8) {
|
if (len >= 8) {
|
||||||
long mul = k2 + len * 2;
|
long mul = k2 + len * 2L;
|
||||||
long a = fetch64(byteArray, 0) + k2;
|
long a = fetch64(byteArray, 0) + k2;
|
||||||
long b = fetch64(byteArray, len - 8);
|
long b = fetch64(byteArray, len - 8);
|
||||||
long c = rotate(b, 37) * mul + a;
|
long c = rotate(b, 37) * mul + a;
|
||||||
@ -344,7 +344,7 @@ public class CityHash {
|
|||||||
// This probably works well for 16-byte strings as well, but it may be overkill in that case.
|
// This probably works well for 16-byte strings as well, but it may be overkill in that case.
|
||||||
private static long hashLen17to32(byte[] byteArray) {
|
private static long hashLen17to32(byte[] byteArray) {
|
||||||
int len = byteArray.length;
|
int len = byteArray.length;
|
||||||
long mul = k2 + len * 2;
|
long mul = k2 + len * 2L;
|
||||||
long a = fetch64(byteArray, 0) * k1;
|
long a = fetch64(byteArray, 0) * k1;
|
||||||
long b = fetch64(byteArray, 8);
|
long b = fetch64(byteArray, 8);
|
||||||
long c = fetch64(byteArray, len - 8) * mul;
|
long c = fetch64(byteArray, len - 8) * mul;
|
||||||
@ -355,7 +355,7 @@ public class CityHash {
|
|||||||
|
|
||||||
private static long hashLen33to64(byte[] byteArray) {
|
private static long hashLen33to64(byte[] byteArray) {
|
||||||
int len = byteArray.length;
|
int len = byteArray.length;
|
||||||
long mul = k2 + len * 2;
|
long mul = k2 + len * 2L;
|
||||||
long a = fetch64(byteArray, 0) * k2;
|
long a = fetch64(byteArray, 0) * k2;
|
||||||
long b = fetch64(byteArray, 8);
|
long b = fetch64(byteArray, 8);
|
||||||
long c = fetch64(byteArray, len - 24);
|
long c = fetch64(byteArray, len - 24);
|
||||||
|
19
hutool-core/src/main/java/cn/hutool/core/lang/hash/Hash.java
Normal file
19
hutool-core/src/main/java/cn/hutool/core/lang/hash/Hash.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package cn.hutool.core.lang.hash;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash计算接口
|
||||||
|
*
|
||||||
|
* @param <T> 被计算hash的对象类型
|
||||||
|
* @author looly
|
||||||
|
* @since 5.7.15
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface Hash<T> {
|
||||||
|
/**
|
||||||
|
* 计算Hash值
|
||||||
|
*
|
||||||
|
* @param t 对象
|
||||||
|
* @return hash
|
||||||
|
*/
|
||||||
|
Number hash(T t);
|
||||||
|
}
|
@ -8,7 +8,8 @@ package cn.hutool.core.lang.hash;
|
|||||||
* @since 5.2.5
|
* @since 5.2.5
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Hash128<T> {
|
public interface Hash128<T> extends Hash<T>{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算Hash值
|
* 计算Hash值
|
||||||
*
|
*
|
||||||
@ -16,4 +17,9 @@ public interface Hash128<T> {
|
|||||||
* @return hash
|
* @return hash
|
||||||
*/
|
*/
|
||||||
Number128 hash128(T t);
|
Number128 hash128(T t);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default Number hash(T t){
|
||||||
|
return hash128(t);
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ package cn.hutool.core.lang.hash;
|
|||||||
* @since 5.2.5
|
* @since 5.2.5
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Hash32<T> {
|
public interface Hash32<T> extends Hash<T>{
|
||||||
/**
|
/**
|
||||||
* 计算Hash值
|
* 计算Hash值
|
||||||
*
|
*
|
||||||
@ -16,4 +16,9 @@ public interface Hash32<T> {
|
|||||||
* @return hash
|
* @return hash
|
||||||
*/
|
*/
|
||||||
int hash32(T t);
|
int hash32(T t);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default Number hash(T t){
|
||||||
|
return hash32(t);
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ package cn.hutool.core.lang.hash;
|
|||||||
* @since 5.2.5
|
* @since 5.2.5
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Hash64<T> {
|
public interface Hash64<T> extends Hash<T>{
|
||||||
/**
|
/**
|
||||||
* 计算Hash值
|
* 计算Hash值
|
||||||
*
|
*
|
||||||
@ -16,4 +16,9 @@ public interface Hash64<T> {
|
|||||||
* @return hash
|
* @return hash
|
||||||
*/
|
*/
|
||||||
long hash64(T t);
|
long hash64(T t);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default Number hash(T t){
|
||||||
|
return hash64(t);
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,7 +6,8 @@ package cn.hutool.core.lang.hash;
|
|||||||
* @author hexiufeng
|
* @author hexiufeng
|
||||||
* @since 5.2.5
|
* @since 5.2.5
|
||||||
*/
|
*/
|
||||||
public class Number128 {
|
public class Number128 extends Number{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private long lowValue;
|
private long lowValue;
|
||||||
private long highValue;
|
private long highValue;
|
||||||
@ -41,4 +42,24 @@ public class Number128 {
|
|||||||
public long[] getLongArray() {
|
public long[] getLongArray() {
|
||||||
return new long[]{lowValue, highValue};
|
return new long[]{lowValue, highValue};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int intValue() {
|
||||||
|
return (int) longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long longValue() {
|
||||||
|
return this.lowValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float floatValue() {
|
||||||
|
return longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double doubleValue() {
|
||||||
|
return longValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user