From c635d78b479510ebe2556a420948effcd30a0731 Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期六, 21 十二月 2024 18:40:43 +0800 Subject: [PATCH] 新建德森项目分支 --- zy-asrs-framework/src/main/java/com/zy/asrs/framework/common/Cache.java | 144 ++++++++++++++++++++++++------------------------ 1 files changed, 72 insertions(+), 72 deletions(-) diff --git a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/common/Cache.java b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/common/Cache.java index 1497359..151c9eb 100644 --- a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/common/Cache.java +++ b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/common/Cache.java @@ -1,72 +1,72 @@ -package com.zy.asrs.framework.common; - -import com.zy.asrs.framework.exception.ApplicationException; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Supplier; - -/** - * 缂撳瓨 - * - */ -public class Cache { - - private Map<String,Object> caches=new ConcurrentHashMap<>(); - - @SuppressWarnings("unchecked") - public <T>T get(Class<T> prototype) { - return (T) get(prototype.getName()); - } - - public Object get(String key) { - return get(key,true); - } - - @SuppressWarnings("unchecked") - public <T>T get(String key,Supplier<T> func){ - if(!hasKey(key)) { - put(key,func.get()); - } - return (T)get(key); - } - - public Object get(String key,boolean exist) { - if(exist) { - if(!hasKey(key)) { - throw new ApplicationException(this+"-鎵句笉鍒扮紦瀛樺璞�:"+key); - } - } - return caches.get(key); - } - - public Cache put(Object value) { - String key=value.getClass().getName(); - put(key,value); - return this; - } - - public Cache put(String key,Object value) { - put(key, value,true); - return this; - } - - public Cache put(String key,Object value,boolean exist) { - if(exist) { - if(hasKey(key)) { - throw new ApplicationException(this+"-缂撳瓨"+key+"宸插瓨鍦�"); - } - } - caches.put(key, value); - return this; - } - - public boolean hasKey(Class<?> prototype) { - return hasKey(prototype.getName()); - } - - public boolean hasKey(String key) { - return caches.containsKey(key); - } - -} +package com.zy.asrs.framework.common; + +import com.zy.asrs.framework.exception.ApplicationException; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; + +/** + * 缂撳瓨 + * + */ +public class Cache { + + private Map<String,Object> caches=new ConcurrentHashMap<>(); + + @SuppressWarnings("unchecked") + public <T>T get(Class<T> prototype) { + return (T) get(prototype.getName()); + } + + public Object get(String key) { + return get(key,true); + } + + @SuppressWarnings("unchecked") + public <T>T get(String key,Supplier<T> func){ + if(!hasKey(key)) { + put(key,func.get()); + } + return (T)get(key); + } + + public Object get(String key,boolean exist) { + if(exist) { + if(!hasKey(key)) { + throw new ApplicationException(this+"-鎵句笉鍒扮紦瀛樺璞�:"+key); + } + } + return caches.get(key); + } + + public Cache put(Object value) { + String key=value.getClass().getName(); + put(key,value); + return this; + } + + public Cache put(String key,Object value) { + put(key, value,true); + return this; + } + + public Cache put(String key,Object value,boolean exist) { + if(exist) { + if(hasKey(key)) { + throw new ApplicationException(this+"-缂撳瓨"+key+"宸插瓨鍦�"); + } + } + caches.put(key, value); + return this; + } + + public boolean hasKey(Class<?> prototype) { + return hasKey(prototype.getName()); + } + + public boolean hasKey(String key) { + return caches.containsKey(key); + } + +} -- Gitblit v1.9.1