diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java index 8775af10..1fb35f1a 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java @@ -3,6 +3,7 @@ package us.codecraft.webmagic.selector; import java.util.ArrayList; import java.util.List; + import org.apache.commons.collections4.CollectionUtils; /** @@ -55,11 +56,12 @@ public abstract class AbstractSelectable implements Selectable { @Override public String get() { - if (CollectionUtils.isNotEmpty(all())) { - return all().get(0); - } else { - return null; - } + List sourceTexts = all(); + if (CollectionUtils.isNotEmpty(sourceTexts)) { + return sourceTexts.get(0); + } + return null; + } @Override @@ -91,8 +93,9 @@ public abstract class AbstractSelectable implements Selectable { } public String getFirstSourceText() { - if (getSourceTexts() != null && getSourceTexts().size() > 0) { - return getSourceTexts().get(0); + List sourceTexts = getSourceTexts(); + if (CollectionUtils.isNotEmpty(sourceTexts)) { + return sourceTexts.get(0); } return null; } @@ -104,6 +107,6 @@ public abstract class AbstractSelectable implements Selectable { @Override public boolean match() { - return getSourceTexts() != null && getSourceTexts().size() > 0; + return CollectionUtils.isNotEmpty(getSourceTexts()); } }