mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-14 10:15:08 +08:00
消灭不规范代码(由sonatype检测出来的)
This commit is contained in:
@@ -11,12 +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.
|
||||
*/
|
||||
protected static final String EMPTY_ARRAY[] = new String[0];
|
||||
private static final String[] EMPTY_ARRAY = new String[0];
|
||||
|
||||
// ------------------------------ WxSession
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
/**
|
||||
@@ -71,20 +71,23 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
|
||||
if (!isValidInternal())
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionImpl.getAttribute.ise"));
|
||||
}
|
||||
|
||||
if (name == null) return null;
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (this.attributes.get(name));
|
||||
return this.attributes.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
if (!isValidInternal())
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionImpl.getAttributeNames.ise"));
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise"));
|
||||
}
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
names.addAll(this.attributes.keySet());
|
||||
@@ -94,9 +97,9 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
// Name cannot be null
|
||||
if (name == null)
|
||||
throw new IllegalArgumentException
|
||||
(sm.getString("sessionImpl.setAttribute.namenull"));
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull"));
|
||||
}
|
||||
|
||||
// Null value is the same as removeAttribute()
|
||||
if (value == null) {
|
||||
@@ -105,9 +108,9 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
}
|
||||
|
||||
// Validate our current state
|
||||
if (!isValidInternal())
|
||||
throw new IllegalStateException(sm.getString(
|
||||
"sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
}
|
||||
|
||||
this.attributes.put(name, value);
|
||||
|
||||
@@ -121,8 +124,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (!isValidInternal())
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionImpl.invalidate.ise"));
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise"));
|
||||
|
||||
// Cause this session to expire
|
||||
expire();
|
||||
@@ -131,12 +133,11 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public WxSession getSession() {
|
||||
|
||||
if (this.facade == null) {
|
||||
this.facade = new StandardSessionFacade(this);
|
||||
}
|
||||
return (this.facade);
|
||||
|
||||
return this.facade;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,12 +186,14 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public String getIdInternal() {
|
||||
return (this.id);
|
||||
return this.id;
|
||||
}
|
||||
|
||||
protected void removeAttributeInternal(String name) {
|
||||
// Avoid NPE
|
||||
if (name == null) return;
|
||||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove this attribute from our collection
|
||||
this.attributes.remove(name);
|
||||
@@ -202,19 +205,22 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
// Check to see if session has already been invalidated.
|
||||
// Do not check expiring at this point as expire should not return until
|
||||
// isValid is false
|
||||
if (!this.isValid)
|
||||
if (!this.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
// Check again, now we are inside the sync so this code only runs once
|
||||
// Double check locking - isValid needs to be volatile
|
||||
// The check of expiring is to ensure that an infinite loop is not
|
||||
// entered as per bug 56339
|
||||
if (this.expiring || !this.isValid)
|
||||
if (this.expiring || !this.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.manager == null)
|
||||
if (this.manager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark this session as "being expired"
|
||||
this.expiring = true;
|
||||
@@ -230,9 +236,9 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
this.expiring = false;
|
||||
|
||||
// Unbind any objects associated with this session
|
||||
String keys[] = keys();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
removeAttributeInternal(keys[i]);
|
||||
String[] keys = keys();
|
||||
for (String key : keys) {
|
||||
removeAttributeInternal(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,13 +279,15 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
if ((this.id != null) && (this.manager != null))
|
||||
if ((this.id != null) && (this.manager != null)) {
|
||||
this.manager.remove(this);
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
|
||||
if (this.manager != null)
|
||||
if (this.manager != null) {
|
||||
this.manager.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,21 +303,41 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof StandardSession)) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof StandardSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StandardSession session = (StandardSession) o;
|
||||
|
||||
if (this.creationTime != session.creationTime) return false;
|
||||
if (this.expiring != session.expiring) return false;
|
||||
if (this.isValid != session.isValid) return false;
|
||||
if (this.maxInactiveInterval != session.maxInactiveInterval) return false;
|
||||
if (this.thisAccessedTime != session.thisAccessedTime) return false;
|
||||
if (this.accessCount.get() != session.accessCount.get()) return false;
|
||||
if (!this.attributes.equals(session.attributes)) return false;
|
||||
if (!this.facade.equals(session.facade)) return false;
|
||||
if (!this.id.equals(session.id)) return false;
|
||||
return this.manager.equals(session.manager);
|
||||
if (this.creationTime != session.creationTime) {
|
||||
return false;
|
||||
}
|
||||
if (this.expiring != session.expiring) {
|
||||
return false;
|
||||
}
|
||||
if (this.isValid != session.isValid) {
|
||||
return false;
|
||||
}
|
||||
if (this.maxInactiveInterval != session.maxInactiveInterval) {
|
||||
return false;
|
||||
}
|
||||
if (this.thisAccessedTime != session.thisAccessedTime) {
|
||||
return false;
|
||||
}
|
||||
if (this.accessCount.get() != session.accessCount.get()) {
|
||||
return false;
|
||||
}
|
||||
if (!this.attributes.equals(session.attributes)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.facade.equals(session.facade)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.id.equals(session.id) && this.manager.equals(session.manager);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user