Class AttributesMap
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
String>
Map is used to store DOM tag attribute names and values.
This map pays no attention to sequence of attributes.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
constant for class attribute name.protected static final String
just a constant to use to ignore symbols that do not affect real attributes valueprotected static final String
just a constant to use in processing attribute.protected static final String
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) -
Constructor Summary
ConstructorsConstructorDescriptionAttributesMap
(Attributes attributes) This constructor converts all the attribute names to lower case. -
Method Summary
Modifier and TypeMethodDescriptionboolean
this method returns true, if two maps have the same set of keys and values assigned to these keys.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.int
hashCode()
boolean
hasSameAttributes
(Attributes attributes) This method returns true if the givenAttributes
contains the same attributes as this map, with the same qualifications for "style" and "class" as specified inequals(Object)
.static void
static String
normalizeClassString
(String classVal) ThehashCode()
method should correspond toequals
method, so we need a way to get the class attribute value in the same representation we use when we're comparing.static String
normalizeStyleString
(String styleVal) ThehashCode()
method should correspond toequals
method, so we need a way to get the styles attribute value in the same representation we use when we're comparing.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">
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
toString
-
Field Details
-
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:
-
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:
-
SPACE
just a constant to use in processing attribute.- See Also:
-
NL_TAB_REGEXP
just a constant to use to ignore symbols that do not affect real attributes value- See Also:
-
-
Constructor Details
-
AttributesMap
public AttributesMap() -
AttributesMap
This constructor converts all the attribute names to lower case.- Parameters:
attributes
-
-
-
Method Details
-
hasSameAttributes
This method returns true if the givenAttributes
contains the same attributes as this map, with the same qualifications for "style" and "class" as specified inequals(Object)
. -
equals
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. -
hashCode
public int hashCode() -
equivalentStyles
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
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
ThehashCode()
method should correspond toequals
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
ThehashCode()
method should correspond toequals
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
-