Class AttributesMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,String>
-
- org.outerj.daisy.diff.html.dom.helper.AttributesMap
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,String>
public class AttributesMap extends HashMap<String,String>
Map is used to store DOM tag attribute names and values. This map pays no attention to sequence of attributes.- See Also:
- Serialized Form
-
-
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
Fields Modifier and Type Field 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 valueprotected 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 Summary
Constructors Constructor Description AttributesMap()
AttributesMap(Attributes attributes)
This constructor converts all the attribute names to lower case.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 givenAttributes
contains the same attributes as this map, with the same qualifications for "style" and "class" as specified inequals(Object)
.static void
main(String[] args)
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 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
-
SPACE
protected static final String SPACE
just a constant to use in processing attribute.- 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 givenAttributes
contains the same attributes as this map, with the same qualifications for "style" and "class" as specified inequals(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.
-
hashCode
public int hashCode()
-
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)
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
public 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. 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)
-
-