Package org.jsoup.nodes
Class Attributes
- java.lang.Object
-
- org.jsoup.nodes.Attributes
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Iterable<Attribute>
public class Attributes extends java.lang.Object implements java.lang.Iterable<Attribute>, java.lang.Cloneable
The attributes of an Element.Attributes are treated as a map: there can be only one value associated with an attribute key/name.
Attribute name and value comparisons are generally case sensitive. By default for HTML, attribute names are normalized to lower-case on parsing. That means you should use lower-case strings when referring to attributes by name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAttributes.Dataset
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringdataPrefixprivate static java.lang.String[]Emptyprivate static java.lang.StringEmptyStringprivate static intGrowthFactorprivate static intInitialCapacity(package private) java.lang.String[]keys(package private) static intNotFoundprivate intsize(package private) java.lang.String[]vals
-
Constructor Summary
Constructors Constructor Description Attributes()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadd(java.lang.String key, java.lang.String value)voidaddAll(Attributes incoming)Add all the attributes from the incoming set to this set.java.util.List<Attribute>asList()Get the attributes as a List, for iteration.private voidcheckCapacity(int minNewSize)(package private) static java.lang.StringcheckNotNull(java.lang.String val)Attributesclone()private static java.lang.String[]copyOf(java.lang.String[] orig, int size)private static java.lang.StringdataKey(java.lang.String key)java.util.Map<java.lang.String,java.lang.String>dataset()Retrieves a filtered view of attributes that are HTML5 custom data attributes; that is, attributes with keys starting withdata-.booleanequals(java.lang.Object o)Checks if these attributes are equal to another set of attributes, by comparing the two setsjava.lang.Stringget(java.lang.String key)Get an attribute value by key.java.lang.StringgetIgnoreCase(java.lang.String key)Get an attribute's value by case-insensitive keyinthashCode()Calculates the hashcode of these attributes, by iterating all attributes and summing their hashcodes.booleanhasKey(java.lang.String key)Tests if these attributes contain an attribute with this key.booleanhasKeyIgnoreCase(java.lang.String key)Tests if these attributes contain an attribute with this key.java.lang.Stringhtml()Get the HTML representation of these attributes.(package private) voidhtml(java.lang.Appendable accum, Document.OutputSettings out)(package private) intindexOfKey(java.lang.String key)private intindexOfKeyIgnoreCase(java.lang.String key)java.util.Iterator<Attribute>iterator()voidnormalize()Internal method.Attributesput(java.lang.String key, boolean value)Set a new boolean attribute, remove attribute if value is false.Attributesput(java.lang.String key, java.lang.String value)Set a new attribute, or replace an existing one by key.Attributesput(Attribute attribute)Set a new attribute, or replace an existing one by key.(package private) voidputIgnoreCase(java.lang.String key, java.lang.String value)private voidremove(int index)voidremove(java.lang.String key)Remove an attribute by key.voidremoveIgnoreCase(java.lang.String key)Remove an attribute by key.intsize()Get the number of attributes in this set.java.lang.StringtoString()
-
-
-
Field Detail
-
dataPrefix
protected static final java.lang.String dataPrefix
- See Also:
- Constant Field Values
-
InitialCapacity
private static final int InitialCapacity
- See Also:
- Constant Field Values
-
GrowthFactor
private static final int GrowthFactor
- See Also:
- Constant Field Values
-
Empty
private static final java.lang.String[] Empty
-
NotFound
static final int NotFound
- See Also:
- Constant Field Values
-
EmptyString
private static final java.lang.String EmptyString
- See Also:
- Constant Field Values
-
size
private int size
-
keys
java.lang.String[] keys
-
vals
java.lang.String[] vals
-
-
Method Detail
-
checkCapacity
private void checkCapacity(int minNewSize)
-
copyOf
private static java.lang.String[] copyOf(java.lang.String[] orig, int size)
-
indexOfKey
int indexOfKey(java.lang.String key)
-
indexOfKeyIgnoreCase
private int indexOfKeyIgnoreCase(java.lang.String key)
-
checkNotNull
static java.lang.String checkNotNull(java.lang.String val)
-
get
public java.lang.String get(java.lang.String key)
Get an attribute value by key.- Parameters:
key- the (case-sensitive) attribute key- Returns:
- the attribute value if set; or empty string if not set (or a boolean attribute).
- See Also:
hasKey(String)
-
getIgnoreCase
public java.lang.String getIgnoreCase(java.lang.String key)
Get an attribute's value by case-insensitive key- Parameters:
key- the attribute name- Returns:
- the first matching attribute value if set; or empty string if not set (ora boolean attribute).
-
add
private void add(java.lang.String key, java.lang.String value)
-
put
public Attributes put(java.lang.String key, java.lang.String value)
Set a new attribute, or replace an existing one by key.- Parameters:
key- case sensitive attribute keyvalue- attribute value- Returns:
- these attributes, for chaining
-
putIgnoreCase
void putIgnoreCase(java.lang.String key, java.lang.String value)
-
put
public Attributes put(java.lang.String key, boolean value)
Set a new boolean attribute, remove attribute if value is false.- Parameters:
key- case insensitive attribute keyvalue- attribute value- Returns:
- these attributes, for chaining
-
put
public Attributes put(Attribute attribute)
Set a new attribute, or replace an existing one by key.- Parameters:
attribute- attribute with case sensitive key- Returns:
- these attributes, for chaining
-
remove
private void remove(int index)
-
remove
public void remove(java.lang.String key)
Remove an attribute by key. Case sensitive.- Parameters:
key- attribute key to remove
-
removeIgnoreCase
public void removeIgnoreCase(java.lang.String key)
Remove an attribute by key. Case insensitive.- Parameters:
key- attribute key to remove
-
hasKey
public boolean hasKey(java.lang.String key)
Tests if these attributes contain an attribute with this key.- Parameters:
key- case-sensitive key to check for- Returns:
- true if key exists, false otherwise
-
hasKeyIgnoreCase
public boolean hasKeyIgnoreCase(java.lang.String key)
Tests if these attributes contain an attribute with this key.- Parameters:
key- key to check for- Returns:
- true if key exists, false otherwise
-
size
public int size()
Get the number of attributes in this set.- Returns:
- size
-
addAll
public void addAll(Attributes incoming)
Add all the attributes from the incoming set to this set.- Parameters:
incoming- attributes to add to these attributes.
-
iterator
public java.util.Iterator<Attribute> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Attribute>
-
asList
public java.util.List<Attribute> asList()
Get the attributes as a List, for iteration.- Returns:
- an view of the attributes as an unmodifialbe List.
-
dataset
public java.util.Map<java.lang.String,java.lang.String> dataset()
Retrieves a filtered view of attributes that are HTML5 custom data attributes; that is, attributes with keys starting withdata-.- Returns:
- map of custom data attributes.
-
html
public java.lang.String html()
Get the HTML representation of these attributes.- Returns:
- HTML
- Throws:
SerializationException- if the HTML representation of the attributes cannot be constructed.
-
html
final void html(java.lang.Appendable accum, Document.OutputSettings out) throws java.io.IOException- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Checks if these attributes are equal to another set of attributes, by comparing the two sets- Overrides:
equalsin classjava.lang.Object- Parameters:
o- attributes to compare with- Returns:
- if both sets of attributes have the same content
-
hashCode
public int hashCode()
Calculates the hashcode of these attributes, by iterating all attributes and summing their hashcodes.- Overrides:
hashCodein classjava.lang.Object- Returns:
- calculated hashcode
-
clone
public Attributes clone()
- Overrides:
clonein classjava.lang.Object
-
normalize
public void normalize()
Internal method. Lowercases all keys.
-
dataKey
private static java.lang.String dataKey(java.lang.String key)
-
-