From 3aad8a604a3580f38a53d350daf90eb8fbd63686 Mon Sep 17 00:00:00 2001 From: chenzhangyue <15696756582@163.com> Date: Wed, 10 Apr 2024 17:40:40 +0800 Subject: [PATCH] =?UTF-8?q?:bookmark:=20=E7=89=88=E6=9C=AC=E5=8D=87?= =?UTF-8?q?=E7=BA=A7xml,=20javax.xml.bind.->=20jakarta.xml.bind.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luna/common/cache/SimpleGuavaCache.java | 9 ++-- .../java/com/luna/common/xml/JAXBUtil.java | 14 +++--- .../java/com/luna/common/xml/XmlUtil.java | 4 +- .../com/luna/common/utils/GuavaCacheTest.java | 46 ++++++++----------- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/luna/common/cache/SimpleGuavaCache.java b/src/main/java/com/luna/common/cache/SimpleGuavaCache.java index f067375b0..e040ebfae 100644 --- a/src/main/java/com/luna/common/cache/SimpleGuavaCache.java +++ b/src/main/java/com/luna/common/cache/SimpleGuavaCache.java @@ -5,9 +5,10 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import java.util.stream.Collectors; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import com.google.common.cache.*; import com.google.common.collect.ImmutableMap; @@ -66,7 +67,8 @@ public void put(K key, V value) { cache.put(key, value); } - public void invalidate(K... key) { + @SafeVarargs + public final void invalidate(K... key) { Arrays.stream(key).forEach(cache::invalidate); } @@ -102,7 +104,8 @@ public void refresh(K key) { cache.refresh(key); } - public ImmutableMap getAllPresent(K... keys) { + @SafeVarargs + public final ImmutableMap getAllPresent(K... keys) { return cache.getAllPresent(Arrays.stream(keys).distinct().collect(Collectors.toList())); } diff --git a/src/main/java/com/luna/common/xml/JAXBUtil.java b/src/main/java/com/luna/common/xml/JAXBUtil.java index 0d82a5696..e626c53a1 100644 --- a/src/main/java/com/luna/common/xml/JAXBUtil.java +++ b/src/main/java/com/luna/common/xml/JAXBUtil.java @@ -5,13 +5,13 @@ import java.io.StringWriter; import java.nio.charset.Charset; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.Marshaller; +import jakarta.xml.bind.Unmarshaller; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlElementWrapper; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlTransient; import com.luna.common.file.FileTools; import com.luna.common.io.IoUtil; diff --git a/src/main/java/com/luna/common/xml/XmlUtil.java b/src/main/java/com/luna/common/xml/XmlUtil.java index 27be03840..48940a7f0 100755 --- a/src/main/java/com/luna/common/xml/XmlUtil.java +++ b/src/main/java/com/luna/common/xml/XmlUtil.java @@ -5,8 +5,8 @@ import java.util.*; import javax.xml.XMLConstants; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.Unmarshaller; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.parsers.*; diff --git a/src/test/java/com/luna/common/utils/GuavaCacheTest.java b/src/test/java/com/luna/common/utils/GuavaCacheTest.java index ce914788e..28507de7c 100644 --- a/src/test/java/com/luna/common/utils/GuavaCacheTest.java +++ b/src/test/java/com/luna/common/utils/GuavaCacheTest.java @@ -1,13 +1,11 @@ package com.luna.common.utils; -import java.util.concurrent.Callable; - import com.google.common.cache.CacheLoader; import com.luna.common.cache.SimpleGuavaCache; public class GuavaCacheTest { - private static final SimpleGuavaCache cache = new SimpleGuavaCache(new CacheLoader() { + private static final SimpleGuavaCache cache = new SimpleGuavaCache<>(new CacheLoader() { public String load(String key) throws Exception { System.out.println("load data"); // 加载数据线程执行标志 Thread.sleep(1000); // 模拟加载时间 @@ -15,34 +13,26 @@ public String load(String key) throws Exception { } }); - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) { - new Thread(new Runnable() { - public void run() { - System.out.println("thread1"); - String value = cache.get("key", new Callable() { - public String call() throws Exception { - System.out.println("load1"); // 加载数据线程执行标志 - Thread.sleep(1000); // 模拟加载时间 - return "auto load by Callable"; - } - }); - System.out.println("thread1 " + value); - } + new Thread(() -> { + System.out.println("thread1"); + String value = cache.get("key", () -> { + System.out.println("load1"); // 加载数据线程执行标志 + Thread.sleep(1000); // 模拟加载时间 + return "auto load by Callable"; + }); + System.out.println("thread1 " + value); }).start(); - new Thread(new Runnable() { - public void run() { - System.out.println("thread2"); - String value = cache.get("key", new Callable() { - public String call() throws Exception { - System.out.println("load2"); // 加载数据线程执行标志 - Thread.sleep(1000); // 模拟加载时间 - return "auto load by Callable"; - } - }); - System.out.println("thread2 " + value); - } + new Thread(() -> { + System.out.println("thread2"); + String value = cache.get("key", () -> { + System.out.println("load2"); // 加载数据线程执行标志 + Thread.sleep(1000); // 模拟加载时间 + return "auto load by Callable"; + }); + System.out.println("thread2 " + value); }).start(); } } \ No newline at end of file