Record Class CssSpecificity
java.lang.Object
java.lang.Record
dev.jcputney.mjml.css.CssSpecificity
- Record Components:
a- the number of ID selectorsb- the number of class, attribute, and pseudo-class selectorsc- the number of type and pseudo-element selectors
- All Implemented Interfaces:
Comparable<CssSpecificity>
public record CssSpecificity(int a, int b, int c)
extends Record
implements Comparable<CssSpecificity>
CSS specificity as an (a, b, c) tuple where:
- a = number of ID selectors
- b = number of class, attribute, and pseudo-class selectors
- c = number of type and pseudo-element selectors
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CssSpecificityRepresents CSS specificity of zero, defined as (0, 0, 0). -
Constructor Summary
ConstructorsConstructorDescriptionCssSpecificity(int a, int b, int c) Creates an instance of aCssSpecificityrecord class. -
Method Summary
Modifier and TypeMethodDescriptioninta()Returns the value of thearecord component.add(CssSpecificity other) Adds two specificity values together (used for compound selectors).intb()Returns the value of thebrecord component.intc()Returns the value of thecrecord component.intcompareTo(CssSpecificity other) Compares this CSS specificity with another based on the specificity values (a, b, c).final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.toString()Returns a string representation of the CSS specificity as a tuple (a, b, c).
-
Field Details
-
ZERO
Represents CSS specificity of zero, defined as (0, 0, 0). This is typically used to indicate the absence of any selector specificity.
-
-
Constructor Details
-
CssSpecificity
-
-
Method Details
-
add
Adds two specificity values together (used for compound selectors).- Parameters:
other- the specificity to add to this one- Returns:
- new specificity with each component summed
-
compareTo
Compares this CSS specificity with another based on the specificity values (a, b, c). The comparison is performed in order of significance: first by `a` (ID selectors), then by `b` (class, attribute, and pseudo-class selectors), and finally by `c` (type and pseudo-element selectors).- Specified by:
compareToin interfaceComparable<CssSpecificity>- Parameters:
other- the other CssSpecificity object to compare with this instance- Returns:
- a negative integer, zero, or a positive integer as this specificity is less than, equal to, or greater than the specified specificity
-
toString
Returns a string representation of the CSS specificity as a tuple (a, b, c). -
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
a
-
b
-
c
-