public class Attributes extends java.lang.Object implements java.lang.Iterable<Attribute>, java.lang.Cloneable
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.
Modifier and Type | Class and Description |
---|---|
private static class |
Attributes.Dataset |
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
dataPrefix |
private static java.lang.String[] |
Empty |
private static java.lang.String |
EmptyString |
private static int |
GrowthFactor |
private static int |
InitialCapacity |
(package private) static char |
InternalPrefix |
(package private) java.lang.String[] |
keys |
(package private) static int |
NotFound |
private int |
size |
(package private) java.lang.String[] |
vals |
Constructor and Description |
---|
Attributes() |
Modifier and Type | Method and Description |
---|---|
Attributes |
add(java.lang.String key,
java.lang.String value)
Adds a new attribute.
|
void |
addAll(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 void |
checkCapacity(int minNewSize) |
(package private) static java.lang.String |
checkNotNull(java.lang.String val) |
Attributes |
clone() |
private static java.lang.String[] |
copyOf(java.lang.String[] orig,
int size) |
private static java.lang.String |
dataKey(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 with
data- . |
int |
deduplicate(ParseSettings settings)
Internal method.
|
boolean |
equals(java.lang.Object o)
Checks if these attributes are equal to another set of attributes, by comparing the two sets
|
java.lang.String |
get(java.lang.String key)
Get an attribute value by key.
|
java.lang.String |
getIgnoreCase(java.lang.String key)
Get an attribute's value by case-insensitive key
|
boolean |
hasDeclaredValueForKey(java.lang.String key)
Check if these attributes contain an attribute with a value for this key.
|
boolean |
hasDeclaredValueForKeyIgnoreCase(java.lang.String key)
Check if these attributes contain an attribute with a value for this key.
|
int |
hashCode()
Calculates the hashcode of these attributes, by iterating all attributes and summing their hashcodes.
|
boolean |
hasKey(java.lang.String key)
Tests if these attributes contain an attribute with this key.
|
boolean |
hasKeyIgnoreCase(java.lang.String key)
Tests if these attributes contain an attribute with this key.
|
java.lang.String |
html()
Get the HTML representation of these attributes.
|
(package private) void |
html(java.lang.Appendable accum,
Document.OutputSettings out) |
(package private) int |
indexOfKey(java.lang.String key) |
private int |
indexOfKeyIgnoreCase(java.lang.String key) |
(package private) static java.lang.String |
internalKey(java.lang.String key) |
boolean |
isEmpty()
Test if this Attributes list is empty (size==0).
|
private boolean |
isInternalKey(java.lang.String key) |
java.util.Iterator<Attribute> |
iterator() |
void |
normalize()
Internal method.
|
Attributes |
put(Attribute attribute)
Set a new attribute, or replace an existing one by key.
|
Attributes |
put(java.lang.String key,
boolean value)
Set a new boolean attribute, remove attribute if value is false.
|
Attributes |
put(java.lang.String key,
java.lang.String value)
Set a new attribute, or replace an existing one by key.
|
(package private) void |
putIgnoreCase(java.lang.String key,
java.lang.String value) |
private void |
remove(int index) |
void |
remove(java.lang.String key)
Remove an attribute by key.
|
void |
removeIgnoreCase(java.lang.String key)
Remove an attribute by key.
|
int |
size()
Get the number of attributes in this set.
|
java.lang.String |
toString() |
protected static final java.lang.String dataPrefix
static final char InternalPrefix
private static final int InitialCapacity
private static final int GrowthFactor
private static final java.lang.String[] Empty
static final int NotFound
private static final java.lang.String EmptyString
private int size
java.lang.String[] keys
java.lang.String[] vals
private void checkCapacity(int minNewSize)
private static java.lang.String[] copyOf(java.lang.String[] orig, int size)
int indexOfKey(java.lang.String key)
private int indexOfKeyIgnoreCase(java.lang.String key)
static java.lang.String checkNotNull(java.lang.String val)
public java.lang.String get(java.lang.String key)
key
- the (case-sensitive) attribute keyhasKey(String)
public java.lang.String getIgnoreCase(java.lang.String key)
key
- the attribute namepublic Attributes add(java.lang.String key, java.lang.String value)
put(String, String)
public Attributes put(java.lang.String key, java.lang.String value)
key
- case sensitive attribute key (not null)value
- attribute value (may be null, to set a boolean attribute)void putIgnoreCase(java.lang.String key, java.lang.String value)
public Attributes put(java.lang.String key, boolean value)
key
- case insensitive attribute keyvalue
- attribute valuepublic Attributes put(Attribute attribute)
attribute
- attribute with case sensitive keyprivate void remove(int index)
public void remove(java.lang.String key)
key
- attribute key to removepublic void removeIgnoreCase(java.lang.String key)
key
- attribute key to removepublic boolean hasKey(java.lang.String key)
key
- case-sensitive key to check forpublic boolean hasKeyIgnoreCase(java.lang.String key)
key
- key to check forpublic boolean hasDeclaredValueForKey(java.lang.String key)
key
- key to check forpublic boolean hasDeclaredValueForKeyIgnoreCase(java.lang.String key)
key
- case-insensitive key to check forpublic int size()
public boolean isEmpty()
public void addAll(Attributes incoming)
incoming
- attributes to add to these attributes.public java.util.Iterator<Attribute> iterator()
iterator
in interface java.lang.Iterable<Attribute>
public java.util.List<Attribute> asList()
public java.util.Map<java.lang.String,java.lang.String> dataset()
data-
.public java.lang.String html()
final void html(java.lang.Appendable accum, Document.OutputSettings out) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- attributes to compare withpublic int hashCode()
hashCode
in class java.lang.Object
public Attributes clone()
clone
in class java.lang.Object
public void normalize()
public int deduplicate(ParseSettings settings)
settings
- case sensitivityprivate static java.lang.String dataKey(java.lang.String key)
static java.lang.String internalKey(java.lang.String key)
private boolean isInternalKey(java.lang.String key)