LocalProperties.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:presto 作者:
/**
 * Attempt to match the desired properties to a sequence of known properties.
 * <p>
 * Returns a list of the same length as the original. Entries are:
 * - Optional.empty(): the property was satisfied completely
 * - non-empty: the (simplified) property that was not satisfied
 */
public static <T> List<Optional<LocalProperty<T>>> match(List<LocalProperty<T>> actuals, List<LocalProperty<T>> desired)
{
    // After normalizing actuals, each symbol should only appear once
    PeekingIterator<LocalProperty<T>> actualIterator = peekingIterator(normalizeAndPrune(actuals).iterator());

    Set<T> constants = new HashSet<>();
    boolean consumeMoreActuals = true;
    List<Optional<LocalProperty<T>>> result = new ArrayList<>(desired.size());
    for (LocalProperty<T> desiredProperty : desired) {
        while (consumeMoreActuals && actualIterator.hasNext() && desiredProperty.isSimplifiedBy(actualIterator.peek())) {
            constants.addAll(actualIterator.next().getColumns());
        }
        Optional<LocalProperty<T>> simplifiedDesired = desiredProperty.withConstants(constants);
        consumeMoreActuals &= !simplifiedDesired.isPresent(); // Only continue processing actuals if all previous desired properties were fully satisfied
        result.add(simplifiedDesired);
    }
    return result;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号