001package gudusoft.gsqlparser.pp2.layout;
002
003/**
004 * Decides which of two competing layout writes to the same token-gap property
005 * wins, by priority.
006 *
007 * <h2>Precedence (deterministic)</h2>
008 *
009 * <ol>
010 *   <li>A write with a strictly higher {@link LayoutRule#priority()} always
011 *       wins over a lower-priority write, regardless of registration order.</li>
012 *   <li>On equal priority, the <b>later-applied</b> write wins. Because
013 *       {@link LayoutRulePipeline} applies rules in registration order, this
014 *       means a later-registered rule of equal priority overrides an earlier
015 *       one. This is implemented as {@code accept = incoming >= current}.</li>
016 * </ol>
017 *
018 * <p>The resolver is stateless; {@link LayoutContext} keeps the per-property
019 * winning priority and consults this resolver on each requested write.
020 *
021 * <p>Plan reference: §7.3/S23, §7.4/S23.
022 */
023public final class LayoutConflictResolver {
024
025    /**
026     * Whether an incoming write at {@code incomingPriority} should overwrite the
027     * existing decision set at {@code currentPriority}. {@code currentPriority}
028     * is {@link Integer#MIN_VALUE} when the property is still undecided.
029     *
030     * @return {@code true} iff {@code incomingPriority >= currentPriority}
031     */
032    public boolean accept(int incomingPriority, int currentPriority) {
033        return incomingPriority >= currentPriority;
034    }
035}