Class AttributesMap

    • Field Detail

      • STYLE_ATTR

        protected static final String STYLE_ATTR
        constant for style attribute name, We need to treat this attribute differently to consider HTML elements equal if they only differ in style rules order (in order of style rules inside style attribute value)
        See Also:
        Constant Field Values
      • CLASS_ATTR

        protected static final String CLASS_ATTR
        constant for class attribute name. We need to treat this attribute differently to consider HTML elements equal if they only differ in order of multiple CSS classes inside the class attribute value.
        See Also:
        Constant Field Values
      • NL_TAB_REGEXP

        protected static final String NL_TAB_REGEXP
        just a constant to use to ignore symbols that do not affect real attributes value
        See Also:
        Constant Field Values
    • Constructor Detail

      • AttributesMap

        public AttributesMap()
      • AttributesMap

        public AttributesMap​(Attributes attributes)
        This constructor converts all the attribute names to lower case.
        Parameters:
        attributes -
    • Method Detail

      • hasSameAttributes

        public boolean hasSameAttributes​(Attributes attributes)
        This method returns true if the given Attributes contains the same attributes as this map, with the same qualifications for "style" and "class" as specified in equals(Object).
      • equals

        public boolean equals​(Object obj)
        this method returns true, if two maps have the same set of keys and values assigned to these keys. Or if the difference is only in the "style" or "class" attributes values, which are however equivalent. For the "class" attribute that means the values consist of the same set of classes, but not necessarily in the same order, and for the "style" attribute that means that the values consist of the same rules (css property : value pairs) but without order consideration.
        Specified by:
        equals in interface Map<String,​String>
        Overrides:
        equals in class AbstractMap<String,​String>
      • equivalentStyles

        public static boolean equivalentStyles​(String style1,
                                               String style2)
        Checks if 2 values for "style" attribute of an HTML tag are equivalent (contain same CSS property : value pairs, but in different (or the same) order. Pairs are separated by semicolons and any amount of space, and names from values are separated by colon and any amount of space
        Parameters:
        style1 -
        style2 -
        Returns:
      • sameClassSet

        public static boolean sameClassSet​(String classSet1,
                                           String classSet2)
        Checks if 2 values for "class" attribute of an HTML tag are equivalent (contain same CSS class names, but in different (or same order) Ignores new line symbols and tabulation
        Example:
        <p class="styleName1 styleName2">
        is equivalent to
        <p class=" styleName1 styleName2 ">
        and to
        <p class="styleName2 styleName1">
        Parameters:
        classSet1 -
        classSet2 -
        Returns:
        true if the values are equivalent (including null values)
      • normalizeStyleString

        public static String normalizeStyleString​(String styleVal)
        The hashCode() method should correspond to equals method, so we need a way to get the styles attribute value in the same representation we use when we're comparing. We could use this method in comparison method, however the way comparison method is written now is much faster, because it can fail or succeed long before normalization is finished.
        Parameters:
        styleVal - - value of "style" attribute of an HTML tag.
        Returns:
        normalized representation of the provided value
      • normalizeClassString

        public static String normalizeClassString​(String classVal)
        The hashCode() method should correspond to equals method, so we need a way to get the class attribute value in the same representation we use when we're comparing. We could use this method in comparison method, however the way comparison method is written now is much faster, because it can fail or succeed long before normalization is finished.
        Parameters:
        classVal - - value of "class" attribute of an HTML tag.
        Returns:
        normalized representation of the provided value
      • main

        public static void main​(String[] args)