add methods

This commit is contained in:
Looly 2021-10-20 23:56:39 +08:00
parent 96356cff62
commit d690f4a2c4
8 changed files with 70 additions and 14 deletions

View File

@ -20,10 +20,10 @@ public interface BloomFilter extends Serializable{
/**
* 在boolean的bitMap中增加一个字符串<br>
* 如果存在就返回<code>false</code> .如果不存在.先增加这个字符串.再返回<code>true</code>
* 如果存在就返回{@code false} .如果不存在.先增加这个字符串.再返回{@code true}
*
* @param str 字符串
* @return 是否加入成功如果存在就返回<code>false</code> .如果不存在返回<code>true</code>
* @return 是否加入成功如果存在就返回{@code false} .如果不存在返回{@code true}
*/
boolean add(String str);
}
}

View File

@ -684,7 +684,7 @@ public class IoUtil extends NioUtil {
* @return 内容
* @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);
return collection;
}

View File

@ -318,7 +318,7 @@ public class CityHash {
private static long hashLen0to16(byte[] byteArray) {
int len = byteArray.length;
if (len >= 8) {
long mul = k2 + len * 2;
long mul = k2 + len * 2L;
long a = fetch64(byteArray, 0) + k2;
long b = fetch64(byteArray, len - 8);
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.
private static long hashLen17to32(byte[] byteArray) {
int len = byteArray.length;
long mul = k2 + len * 2;
long mul = k2 + len * 2L;
long a = fetch64(byteArray, 0) * k1;
long b = fetch64(byteArray, 8);
long c = fetch64(byteArray, len - 8) * mul;
@ -355,7 +355,7 @@ public class CityHash {
private static long hashLen33to64(byte[] byteArray) {
int len = byteArray.length;
long mul = k2 + len * 2;
long mul = k2 + len * 2L;
long a = fetch64(byteArray, 0) * k2;
long b = fetch64(byteArray, 8);
long c = fetch64(byteArray, len - 24);

View 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);
}

View File

@ -8,7 +8,8 @@ package cn.hutool.core.lang.hash;
* @since 5.2.5
*/
@FunctionalInterface
public interface Hash128<T> {
public interface Hash128<T> extends Hash<T>{
/**
* 计算Hash值
*
@ -16,4 +17,9 @@ public interface Hash128<T> {
* @return hash
*/
Number128 hash128(T t);
}
@Override
default Number hash(T t){
return hash128(t);
}
}

View File

@ -8,7 +8,7 @@ package cn.hutool.core.lang.hash;
* @since 5.2.5
*/
@FunctionalInterface
public interface Hash32<T> {
public interface Hash32<T> extends Hash<T>{
/**
* 计算Hash值
*
@ -16,4 +16,9 @@ public interface Hash32<T> {
* @return hash
*/
int hash32(T t);
}
@Override
default Number hash(T t){
return hash32(t);
}
}

View File

@ -8,7 +8,7 @@ package cn.hutool.core.lang.hash;
* @since 5.2.5
*/
@FunctionalInterface
public interface Hash64<T> {
public interface Hash64<T> extends Hash<T>{
/**
* 计算Hash值
*
@ -16,4 +16,9 @@ public interface Hash64<T> {
* @return hash
*/
long hash64(T t);
}
@Override
default Number hash(T t){
return hash64(t);
}
}

View File

@ -6,7 +6,8 @@ package cn.hutool.core.lang.hash;
* @author hexiufeng
* @since 5.2.5
*/
public class Number128 {
public class Number128 extends Number{
private static final long serialVersionUID = 1L;
private long lowValue;
private long highValue;
@ -41,4 +42,24 @@ public class Number128 {
public long[] getLongArray() {
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();
}
}