Refactored to remove multiple calls of getSourceTexts() api (#1137)

pull/1138/head
Harikrishna 1 year ago committed by GitHub
parent 622ed5a17f
commit a911104076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<String> 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<String> 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());
}
}

Loading…
Cancel
Save