mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-29 01:18:36 +08:00 
			
		
		
		
	规范部分代码
This commit is contained in:
		| @ -5,9 +5,9 @@ | ||||
|  * The ASF licenses this file to You under the Apache License, Version 2.0 | ||||
|  * (the "License"); you may not use this file except in compliance with | ||||
|  * the License.  You may obtain a copy of the License at | ||||
|  *  | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  *  | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| @ -23,9 +23,6 @@ package me.chanjar.weixin.common.session; | ||||
|  * | ||||
|  * @author Craig R. McClanahan | ||||
|  */ | ||||
|  | ||||
| public class Constants { | ||||
|  | ||||
|   public static final String Package = "me.chanjar.weixin.common.session"; | ||||
|  | ||||
|   public static final String PACKAGE = "me.chanjar.weixin.common.session"; | ||||
| } | ||||
|  | ||||
| @ -11,13 +11,12 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|   /** | ||||
|    * The string manager for this package. | ||||
|    */ | ||||
|   protected static final StringManager sm = StringManager.getManager(Constants.Package); | ||||
|   protected static final StringManager SM = StringManager.getManager(Constants.PACKAGE); | ||||
|   /** | ||||
|    * Type array. | ||||
|    */ | ||||
|   private static final String[] EMPTY_ARRAY = new String[0]; | ||||
|  | ||||
|   // ------------------------------ WxSession | ||||
|   protected Map<String, Object> attributes = new ConcurrentHashMap<>(); | ||||
|   /** | ||||
|    * The session identifier of this Session. | ||||
| @ -73,7 +72,7 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|  | ||||
|     if (!isValidInternal()) { | ||||
|       throw new IllegalStateException | ||||
|         (sm.getString("sessionImpl.getAttribute.ise")); | ||||
|         (SM.getString("sessionImpl.getAttribute.ise")); | ||||
|     } | ||||
|  | ||||
|     if (name == null) { | ||||
| @ -86,7 +85,7 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|   @Override | ||||
|   public Enumeration<String> getAttributeNames() { | ||||
|     if (!isValidInternal()) { | ||||
|       throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise")); | ||||
|       throw new IllegalStateException(SM.getString("sessionImpl.getAttributeNames.ise")); | ||||
|     } | ||||
|  | ||||
|     Set<String> names = new HashSet<>(); | ||||
| @ -98,7 +97,7 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|   public void setAttribute(String name, Object value) { | ||||
|     // Name cannot be null | ||||
|     if (name == null) { | ||||
|       throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull")); | ||||
|       throw new IllegalArgumentException(SM.getString("sessionImpl.setAttribute.namenull")); | ||||
|     } | ||||
|  | ||||
|     // Null value is the same as removeAttribute() | ||||
| @ -109,7 +108,7 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|  | ||||
|     // Validate our current state | ||||
|     if (!isValidInternal()) { | ||||
|       throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal())); | ||||
|       throw new IllegalStateException(SM.getString("sessionImpl.setAttribute.ise", getIdInternal())); | ||||
|     } | ||||
|  | ||||
|     this.attributes.put(name, value); | ||||
| @ -123,8 +122,9 @@ public class StandardSession implements WxSession, InternalSession { | ||||
|  | ||||
|   @Override | ||||
|   public void invalidate() { | ||||
|     if (!isValidInternal()) | ||||
|       throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise")); | ||||
|     if (!isValidInternal()) { | ||||
|       throw new IllegalStateException(SM.getString("sessionImpl.invalidate.ise")); | ||||
|     } | ||||
|  | ||||
|     // Cause this session to expire | ||||
|     expire(); | ||||
|  | ||||
| @ -13,8 +13,7 @@ import java.util.concurrent.atomic.AtomicBoolean; | ||||
|  */ | ||||
| public class StandardSessionManager implements WxSessionManager, InternalSessionManager { | ||||
|  | ||||
|   protected static final StringManager sm = | ||||
|     StringManager.getManager(Constants.Package); | ||||
|   protected static final StringManager SM = StringManager.getManager(Constants.PACKAGE); | ||||
|   /** | ||||
|    * The descriptive name of this Manager implementation (for logging). | ||||
|    */ | ||||
| @ -82,7 +81,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | ||||
|   public WxSession getSession(String sessionId, boolean create) { | ||||
|     if (sessionId == null) { | ||||
|       throw new IllegalStateException | ||||
|         (sm.getString("sessionManagerImpl.getSession.ise")); | ||||
|         (SM.getString("sessionManagerImpl.getSession.ise")); | ||||
|     } | ||||
|  | ||||
|     InternalSession session = findSession(sessionId); | ||||
| @ -124,25 +123,24 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | ||||
|  | ||||
|   @Override | ||||
|   public InternalSession findSession(String id) { | ||||
|  | ||||
|     if (id == null) | ||||
|     if (id == null) { | ||||
|       return (null); | ||||
|     } | ||||
|     return this.sessions.get(id); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public InternalSession createSession(String sessionId) { | ||||
|     if (sessionId == null) { | ||||
|       throw new IllegalStateException | ||||
|         (sm.getString("sessionManagerImpl.createSession.ise")); | ||||
|         (SM.getString("sessionManagerImpl.createSession.ise")); | ||||
|     } | ||||
|  | ||||
|     if ((this.maxActiveSessions >= 0) && | ||||
|       (getActiveSessions() >= this.maxActiveSessions)) { | ||||
|       this.rejectedSessions++; | ||||
|       throw new TooManyActiveSessionsException( | ||||
|         sm.getString("sessionManagerImpl.createSession.tmase"), | ||||
|         SM.getString("sessionManagerImpl.createSession.tmase"), | ||||
|         this.maxActiveSessions); | ||||
|     } | ||||
|  | ||||
| @ -230,8 +228,9 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | ||||
|   @Override | ||||
|   public void backgroundProcess() { | ||||
|     this.count = (this.count + 1) % this.processExpiresFrequency; | ||||
|     if (this.count == 0) | ||||
|     if (this.count == 0) { | ||||
|       processExpires(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @ -243,16 +242,18 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | ||||
|     InternalSession sessions[] = findSessions(); | ||||
|     int expireHere = 0; | ||||
|  | ||||
|     if (this.log.isDebugEnabled()) | ||||
|     if (this.log.isDebugEnabled()) { | ||||
|       this.log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length); | ||||
|     for (int i = 0; i < sessions.length; i++) { | ||||
|       if (sessions[i] != null && !sessions[i].isValid()) { | ||||
|     } | ||||
|     for (InternalSession session : sessions) { | ||||
|       if (session != null && !session.isValid()) { | ||||
|         expireHere++; | ||||
|       } | ||||
|     } | ||||
|     long timeEnd = System.currentTimeMillis(); | ||||
|     if (this.log.isDebugEnabled()) | ||||
|     if (this.log.isDebugEnabled()) { | ||||
|       this.log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere); | ||||
|     } | ||||
|     this.processingTime += (timeEnd - timeNow); | ||||
|  | ||||
|   } | ||||
|  | ||||
| @ -28,10 +28,10 @@ import java.util.Random; | ||||
|  */ | ||||
| public class WxCryptUtil { | ||||
|  | ||||
|   private static final Base64 base64 = new Base64(); | ||||
|   private static final Base64 BASE64 = new Base64(); | ||||
|   private static final Charset CHARSET = StandardCharsets.UTF_8; | ||||
|  | ||||
|   private static final ThreadLocal<DocumentBuilder> builderLocal = new ThreadLocal<DocumentBuilder>() { | ||||
|   private static final ThreadLocal<DocumentBuilder> BUILDER_LOCAL = new ThreadLocal<DocumentBuilder>() { | ||||
|     @Override | ||||
|     protected DocumentBuilder initialValue() { | ||||
|       try { | ||||
| @ -65,7 +65,7 @@ public class WxCryptUtil { | ||||
|  | ||||
|   static String extractEncryptPart(String xml) { | ||||
|     try { | ||||
|       DocumentBuilder db = builderLocal.get(); | ||||
|       DocumentBuilder db = BUILDER_LOCAL.get(); | ||||
|       Document document = db.parse(new InputSource(new StringReader(xml))); | ||||
|  | ||||
|       Element root = document.getDocumentElement(); | ||||
| @ -192,7 +192,7 @@ public class WxCryptUtil { | ||||
|       byte[] encrypted = cipher.doFinal(unencrypted); | ||||
|  | ||||
|       // 使用BASE64对加密后的字符串进行编码 | ||||
|       return base64.encodeToString(encrypted); | ||||
|       return BASE64.encodeToString(encrypted); | ||||
|     } catch (Exception e) { | ||||
|       throw new RuntimeException(e); | ||||
|     } | ||||
|  | ||||
| @ -4,5 +4,16 @@ package me.chanjar.weixin.common.util.http; | ||||
|  * Created by ecoolper on 2017/4/28. | ||||
|  */ | ||||
| public enum HttpType { | ||||
|   JODD_HTTP, APACHE_HTTP, OK_HTTP; | ||||
|   /** | ||||
|    * jodd-http. | ||||
|    */ | ||||
|   JODD_HTTP, | ||||
|   /** | ||||
|    * apache httpclient. | ||||
|    */ | ||||
|   APACHE_HTTP, | ||||
|   /** | ||||
|    * okhttp. | ||||
|    */ | ||||
|   OK_HTTP | ||||
| } | ||||
|  | ||||
| @ -46,8 +46,7 @@ import java.util.*; | ||||
|  */ | ||||
| public class StringManager { | ||||
|  | ||||
|   private static final Map<String, Map<Locale, StringManager>> managers = | ||||
|     new Hashtable<>(); | ||||
|   private static final Map<String, Map<Locale, StringManager>> MANAGERS = new Hashtable<>(); | ||||
|   private static int LOCALE_CACHE_SIZE = 10; | ||||
|   /** | ||||
|    * The ResourceBundle for this StringManager. | ||||
| @ -118,16 +117,16 @@ public class StringManager { | ||||
|   public static final synchronized StringManager getManager( | ||||
|     String packageName, Locale locale) { | ||||
|  | ||||
|     Map<Locale, StringManager> map = managers.get(packageName); | ||||
|     Map<Locale, StringManager> map = MANAGERS.get(packageName); | ||||
|     if (map == null) { | ||||
|             /* | ||||
|              * Don't want the HashMap to be expanded beyond LOCALE_CACHE_SIZE. | ||||
|              * Expansion occurs when size() exceeds capacity. Therefore keep | ||||
|              * size at or below capacity. | ||||
|              * removeEldestEntry() executes after insertion therefore the test | ||||
|              * for removal needs to use one less than the maximum desired size | ||||
|              * | ||||
|              */ | ||||
|       /* | ||||
|        * Don't want the HashMap to be expanded beyond LOCALE_CACHE_SIZE. | ||||
|        * Expansion occurs when size() exceeds capacity. Therefore keep | ||||
|        * size at or below capacity. | ||||
|        * removeEldestEntry() executes after insertion therefore the test | ||||
|        * for removal needs to use one less than the maximum desired size | ||||
|        * | ||||
|        */ | ||||
|       map = new LinkedHashMap<Locale, StringManager>(LOCALE_CACHE_SIZE, 1, true) { | ||||
|         private static final long serialVersionUID = 1L; | ||||
|  | ||||
| @ -137,7 +136,7 @@ public class StringManager { | ||||
|           return size() > (LOCALE_CACHE_SIZE - 1); | ||||
|         } | ||||
|       }; | ||||
|       managers.put(packageName, map); | ||||
|       MANAGERS.put(packageName, map); | ||||
|     } | ||||
|  | ||||
|     StringManager mgr = map.get(locale); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang