63 lines
2.9 KiB
Java
63 lines
2.9 KiB
Java
|
package com.huawei.hms.framework.common;
|
||
|
|
||
|
import java.util.regex.Pattern;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public class CheckParamUtils {
|
||
|
private static final String TAG = "CheckParamUtils";
|
||
|
private static final String IPV6_REGEX = "(^((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4}){1}|:))|(([0-9A-Fa-f]{1,4}:){6}((:[0-9A-Fa-f]{1,4}){1}|((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(([0-9A-Fa-f]{1,4}:){5}((:[0-9A-Fa-f]{1,4}){1,2}|:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(([0-9A-Fa-f]{1,4}:){4}((:[0-9A-Fa-f]{1,4}){1,3}|:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(([0-9A-Fa-f]{1,4}:){3}((:[0-9A-Fa-f]{1,4}){1,4}|:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(([0-9A-Fa-f]{1,4}:){2}((:[0-9A-Fa-f]{1,4}){1,5}|:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(([0-9A-Fa-f]{1,4}:){1}((:[0-9A-Fa-f]{1,4}){1,6}|:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:))|(:((:[0-9A-Fa-f]{1,4}){1,7}|(:[fF]{4}){0,1}:((22[0-3]|2[0-1][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})([.](25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|([0-9]){1,2})){3})|:)))$)";
|
||
|
private static Pattern ipv6Pattern = Pattern.compile(IPV6_REGEX);
|
||
|
|
||
|
public static <T> T checkNotNull(T t, String str) {
|
||
|
if (t != null) {
|
||
|
return t;
|
||
|
}
|
||
|
throw new NullPointerException(str);
|
||
|
}
|
||
|
|
||
|
public static int checkNumParam(int i, int i2, int i3, int i4, String str) {
|
||
|
if (i > i3 || i < i2) {
|
||
|
return i4;
|
||
|
}
|
||
|
Logger.d(TAG, str);
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
public static long checkNumParam(long j, long j2, long j3, long j4, String str) {
|
||
|
if (j > j3 || j < j2) {
|
||
|
return j4;
|
||
|
}
|
||
|
Logger.d(TAG, str);
|
||
|
return j;
|
||
|
}
|
||
|
|
||
|
public static void checkOffsetAndCount(long j, long j2, long j3) {
|
||
|
if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) {
|
||
|
throw new ArrayIndexOutOfBoundsException();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean isIpV4(String str) {
|
||
|
if (str == null || str.isEmpty() || str.length() > 15 || !str.replace(".", "").matches("[0-9]+")) {
|
||
|
return false;
|
||
|
}
|
||
|
String[] split = str.split("\\.");
|
||
|
if (split.length != 4) {
|
||
|
return false;
|
||
|
}
|
||
|
for (String str2 : split) {
|
||
|
if (str2.length() > 4 || Integer.parseInt(str2) > 255) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static boolean isIpV6(String str) {
|
||
|
if (str == null || str.isEmpty() || str.length() < 2 || str.length() > 39) {
|
||
|
return false;
|
||
|
}
|
||
|
return ipv6Pattern.matcher(str).matches();
|
||
|
}
|
||
|
}
|