From 511fb8f41e138ca4a723ae6203aa872f4995daaf Mon Sep 17 00:00:00 2001 From: "DESKTOP-C3M45P4\\dengdan" Date: Sun, 5 Apr 2026 18:10:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=A5=BF=E6=B8=B8=E7=9A=84to?= =?UTF-8?q?olsutil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ljsd/jieling/util/ToolsUtil.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/ToolsUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/util/ToolsUtil.java index c40351dab..964d8b536 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/ToolsUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/ToolsUtil.java @@ -86,6 +86,11 @@ public class ToolsUtil { return timeLong + TimeUtils.DAY * dayOut; } + /** + * 获取随机数 + * @param array 数组 + * @return 随机数 + */ public static int getRandomInt(int[] array){ int sum = Arrays.stream(array).sum(); @@ -102,9 +107,6 @@ public class ToolsUtil { break; } } - -// System.out.println("Random Value: " + randomValue); -// System.out.println("Start Index: " + startIndex); return startIndex; } @@ -148,6 +150,27 @@ public class ToolsUtil { return object; } + /** + * map转二维数组 + */ + public static long[][] getTwoArrayLong(Map map) { + long[][] object = null; + if (map != null && !map.isEmpty()) { + int size = map.size(); + object = new long[size][2]; + + Iterator> iterator = map.entrySet().iterator(); + for (int i = 0; i < size; i++) { + Map.Entry entry = iterator.next(); + long key = entry.getKey(); + long value = entry.getValue(); + object[i][0] = key; + object[i][1] = value; + } + } + return object; + } + public static int findKeyWithMaxValueLessThanB(Map a, int b) { int maxKey = -1; int maxValue = Integer.MIN_VALUE; @@ -205,6 +228,14 @@ public class ToolsUtil { return -1; // 如果没有找到匹配的元素,则返回 -1 } + public static int getPackId(int id){ + return 100000 + id; + } + + public static int getOriginId(int id){ + return id % 100000; + } + /** * type 需要小于10 */ @@ -212,10 +243,6 @@ public class ToolsUtil { return type * 100000 + id; } - public static int getOriginId(int id){ - return id % 100000; - } - public static int[] getOriginIds(int id){ int[] result = new int[2]; result[0] = Integer.parseInt(String.valueOf(String.valueOf(id).charAt(0)));