max<T extends FVariantConstraint> static method
T
max<T extends FVariantConstraint>(
- T a,
- T b
Returns the more specific of two constraints.
Specificity is determined tier-by-tier from highest to lowest. At each tier, the constraint with more operands
wins. This means a compound constraint with two tier-2 operands beats one with only one tier-2 operand, even if
the latter has additional lower-tier operands. Typically platform < interaction < semantic.
max(hovered, disabled); // disabled (tier 2 > tier 1)
max(disabled.and(selected), disabled.and(hovered)); // disabled & selected (2 tier-2 operands > 1 tier-2 + 1 tier-1)
If all tiers have equal counts, ties are broken by total operand count, then lexicographically by sorted operand names.
max(hovered, hovered.and(focused)); // hovered & focused (2 > 1)
max(hovered.and(focused), focused.and(pressed)); // focused & hovered ("focused" < "pressed")
Implementation
static T max<T extends FVariantConstraint>(T a, T b) {
const maxTiers = 3;
final operandsA = <String>[];
final operandsB = <String>[];
final tiersA = List.filled(maxTiers, 0);
final tiersB = List.filled(maxTiers, 0);
a._accept(operandsA, tiersA);
b._accept(operandsB, tiersB);
// Compare tier-by-tier from highest to lowest.
for (var tier = maxTiers - 1; tier >= 0; tier--) {
if (tiersA[tier] != tiersB[tier]) {
return tiersA[tier] > tiersB[tier] ? a : b;
}
}
// Fall back to total operand count.
if (operandsA.length != operandsB.length) {
return operandsA.length > operandsB.length ? a : b;
}
// Fall back to lexicographic comparison.
operandsA.sort();
operandsB.sort();
return operandsA.join().compareTo(operandsB.join()) <= 0 ? a : b;
}