Skip to content

Commit 5b80d66

Browse files
committed
Improve code perfomance (time complexity) and readability
1 parent 4e77739 commit 5b80d66

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ protected CollectorPipeline getCollectorPipeline() {
545545
public <T> T get(String url) {
546546
List<String> urls = WMCollections.newArrayList(url);
547547
List<T> resultItemses = getAll(urls);
548-
if (resultItemses != null && resultItemses.size() > 0) {
548+
if (resultItemses != null && !resultItemses.isEmpty()) {
549549
return resultItemses.get(0);
550550
} else {
551551
return null;

webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Selectable replace(String regex, String replacement) {
9191
}
9292

9393
public String getFirstSourceText() {
94-
if (getSourceTexts() != null && getSourceTexts().size() > 0) {
94+
if (getSourceTexts() != null && !getSourceTexts().isEmpty()) {
9595
return getSourceTexts().get(0);
9696
}
9797
return null;
@@ -104,6 +104,6 @@ public String toString() {
104104

105105
@Override
106106
public boolean match() {
107-
return getSourceTexts() != null && getSourceTexts().size() > 0;
107+
return getSourceTexts() != null && !getSourceTexts().isEmpty();
108108
}
109109
}

0 commit comments

Comments
 (0)