All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.codecraft.xsoup.CombiningXElements Maven / Gradle / Ivy

There is a newer version: 0.3.7
Show newest version
package us.codecraft.xsoup;

import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author [email protected]
 */
public class CombiningXElements implements XElements {

    private List elementsList;

    public CombiningXElements(List elementsList) {
        this.elementsList = elementsList;
    }

    public CombiningXElements(XElements... elementsList) {
        this.elementsList = Arrays.asList(elementsList);
    }

    @Override
    public String get() {
        for (XElements xElements : elementsList) {
            String result = xElements.get();
            if (result != null) {
                return result;
            }
        }
        return null;
    }

    @Override
    public List list() {
        List results = new ArrayList();
        for (XElements xElements : elementsList) {
            results.addAll(xElements.list());
        }
        return results;
    }

    @Override
    public Elements getElements() {
        Elements elements = new Elements();
        for (XElements xElements : elementsList) {
            elements.addAll(xElements.getElements());
        }
        return elements;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy