<commit_before>package io.appium.java_client.pagefactory.bys.builder;

import static com.google.common.base.Preconditions.checkNotNull;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;


public class ByAll extends org.openqa.selenium.support.pagefactory.ByAll {

    private List<By> bys;

    private Function<SearchContext, Optional<WebElement>> getSearchingFunction(By by) {
        return input -> {
            try {
                return input.findElement(by);
            } catch (NoSuchElementException e) {
                return Optional.empty();
            }
        };
    }

    /**
     * @param bys is a set of {@link org.openqa.selenium.By} which forms the all possible searching.
     */
    public ByAll(By[] bys) {
        super(bys);
        checkNotNull(bys);

        this.bys = Arrays.asList(bys);
        if (this.bys.isEmpty()) {
            throw new IllegalArgumentException("By array should not be empty");
        }
    }

    @Override
    public WebElement findElement(SearchContext context) {
        for (By by : bys) {
            Optional<WebElement> element = getSearchingFunction(by).apply(context);
            if (element.isPresent()) {
                return element.get();
            }
        }
        throw new NoSuchElementException("Cannot locate an element using " + toString());
    }
}<commit_msg>Fixes after review<commit_after>package io.appium.java_client.pagefactory.bys.builder;

import static com.google.common.base.Preconditions.checkNotNull;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;


public class ByAll extends org.openqa.selenium.support.pagefactory.ByAll {

    private final List<By> bys;

    private Function<SearchContext, Optional<WebElement>> getSearchingFunction(By by) {
        return input -> {
            try {
                return Optional.of(input.findElement(by));
            } catch (NoSuchElementException e) {
                return Optional.empty();
            }
        };
    }

    /**
     * @param bys is a set of {@link org.openqa.selenium.By} which forms the all possible searching.
     */
    public ByAll(By[] bys) {
        super(bys);
        checkNotNull(bys);

        this.bys = Arrays.asList(bys);
        if (this.bys.isEmpty()) {
            throw new IllegalArgumentException("By array should not be empty");
        }
    }

    @Override
    public WebElement findElement(SearchContext context) {
        return bys.stream()
                .map(by -> getSearchingFunction(by).apply(context))
                .filter(Optional::isPresent)
                .findFirst()
                .orElseThrow(() -> new NoSuchElementException("Cannot locate an element using " + toString()))
                .orElse(null);
    }
}
{'fraction_non_alphanumeric': 0.10643642072213501, 'fraction_numerical': 0.0, 'mean_word_length': 2.504950495049505, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405861', 'n_tokens_mistral': 928, 'n_tokens_neox': 882, 'n_words': 197}