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

io.magentys.cinnamon.webdriver.collections.ElementListCache Maven / Gradle / Ivy

package io.magentys.cinnamon.webdriver.collections;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import java.util.List;

class ElementListCache {

    private final ElementLocator elementLocator;
    private List cachedElements;

    public ElementListCache(final ElementLocator locator, List elements) {
        this.elementLocator = locator;
        setElements(elements);
    }

    public synchronized List getElements() {
        if (cachedElements == null) {
            setElements(elementLocator.findElements());
        }
        invalidateCache();
        return cachedElements;
    }

    public synchronized void setElements(List cachedElements) {
        this.cachedElements = cachedElements;
    }

    private void invalidateCache() {
        List elements = elementLocator.findElements();
        if (elements.size() != cachedElements.size()) {
            setElements(elements);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy