public class AttributesMap extends HashMap<String,String>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected static String |
CLASS_ATTR
constant for class attribute name.
|
protected static String |
NL_TAB_REGEXP
just a constant to use to ignore symbols that
do not affect real attributes value
|
protected static String |
SPACE
just a constant to use in processing attribute.
|
protected static 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)
|
| Constructor and Description |
|---|
AttributesMap() |
AttributesMap(Attributes attributes)
This constructor converts all the attribute names to lower case.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
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 given
Attributes contains the same
attributes as this map, with the same qualifications for "style" and "class"
as specified in equals(Object). |
static void |
main(String[] args) |
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. |
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. |
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"> |
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuestoStringprotected static final String STYLE_ATTR
protected static final String CLASS_ATTR
protected static final String SPACE
protected static final String NL_TAB_REGEXP
public AttributesMap()
public AttributesMap(Attributes attributes)
attributes - public boolean hasSameAttributes(Attributes attributes)
Attributes contains the same
attributes as this map, with the same qualifications for "style" and "class"
as specified in equals(Object).public boolean equals(Object obj)
public int hashCode()
public static boolean equivalentStyles(String style1, String style2)
style1 - style2 - public static boolean sameClassSet(String classSet1, String classSet2)
<p class="styleName1 styleName2"><p class=" styleName1 styleName2 "><p class="styleName2 styleName1">classSet1 - classSet2 - public static String normalizeStyleString(String styleVal)
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.styleVal - - value of "style" attribute of an HTML tag.public static String normalizeClassString(String classVal)
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.classVal - - value of "class" attribute of an HTML tag.public static void main(String[] args)
Copyright © 2022. All rights reserved.