Skip to content

Commit

Permalink
Update javadoc and code refinement for AbstractRule
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Zhao <[email protected]>

(cherry picked from commit df84b6b)
  • Loading branch information
sczyh30 committed Dec 25, 2018
1 parent 3bd6bcc commit 59f0d36
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.alibaba.csp.sentinel.slots.block;

/***
/**
* Abstract rule entity.
*
* @author youji.zj
* @author Eric Zhao
*/
Expand All @@ -29,10 +31,11 @@ public abstract class AbstractRule implements Rule {
/**
* <p>
* Application name that will be limited by origin.
* Multiple application name can be separated with comma (',').
* The default limitApp is {@code default}, which means allowing all origin apps.
* </p>
* <p>
* For authority rules, multiple origin name can be separated with comma (',').
* </p>
* <p>The default limitApp is `default`, which means allowing all origin apps.</p>
* <p>For example: limitApp = `appA,appB` will limit requests from appA and appB.</p>
*/
private String limitApp;

Expand Down Expand Up @@ -68,8 +71,6 @@ public boolean equals(Object o) {
if (resource != null ? !resource.equals(that.resource) : that.resource != null) {
return false;
}
// if (limitApp != null ? !limitApp.equals(that.limitApp) :
// that.limitApp != null) { return false; }
if (!limitAppEquals(limitApp, that.limitApp)) {
return false;
}
Expand All @@ -78,12 +79,12 @@ public boolean equals(Object o) {

private boolean limitAppEquals(String str1, String str2) {
if ("".equals(str1)) {
return "default".equals(str2);
} else if ("default".equals(str1)) {
return RuleConstant.LIMIT_APP_DEFAULT.equals(str2);
} else if (RuleConstant.LIMIT_APP_DEFAULT.equals(str1)) {
return "".equals(str2) || str2 == null || str1.equals(str2);
}
if (str1 == null) {
return str2 == null || "default".equals(str2);
return str2 == null || RuleConstant.LIMIT_APP_DEFAULT.equals(str2);
}
return str1.equals(str2);
}
Expand All @@ -95,8 +96,7 @@ public <T extends AbstractRule> T as(Class<T> clazz) {
@Override
public int hashCode() {
int result = resource != null ? resource.hashCode() : 0;
// result = 31 * result + (limitApp != null ? limitApp.hashCode() : 0);
if (!("".equals(limitApp) || "default".equals(limitApp) || limitApp == null)) {
if (!("".equals(limitApp) || RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp) || limitApp == null)) {
result = 31 * result + limitApp.hashCode();
}
return result;
Expand Down

0 comments on commit 59f0d36

Please sign in to comment.