/** Tests if these attributes contain an attribute with this key. @param key case-sensitive key to check for @return true if key exists, false otherwise */ public boolean hasKey(String key) { return indexOfKey(key) != NotFound; }
/** Get an attribute value by key. @param key the (case-sensitive) attribute key @return the attribute value if set; or empty string if not set (or a boolean attribute). @see #hasKey(String) */ public String get(String key) { int i = indexOfKey(key); return i == NotFound ? EmptyString : checkNotNull(vals[i]); }
/** Remove an attribute by key. <b>Case sensitive.</b> @param key attribute key to remove */ public void remove(String key) { int i = indexOfKey(key); if (i != NotFound) remove(i); }
/** Set the attribute value. @param val the new attribute value; must not be null */ public String setValue(String val) { String oldVal = parent.get(this.key); if (parent != null) { int i = parent.indexOfKey(this.key); if (i != Attributes.NotFound) parent.vals[i] = val; } this.val = val; return oldVal; }
/** * Set a new attribute, or replace an existing one by key. * @param key case sensitive attribute key * @param value attribute value * @return these attributes, for chaining */ public Attributes put(String key, String value) { int i = indexOfKey(key); if (i != NotFound) vals[i] = value; else add(key, value); return this; }
/** Set the attribute key; case is preserved. @param key the new key; must not be null */ public void setKey(String key) { Validate.notNull(key); key = key.trim(); Validate.notEmpty(key); // trimming could potentially make empty, so validate here if (parent != null) { int i = parent.indexOfKey(this.key); if (i != Attributes.NotFound) parent.keys[i] = key; } this.key = key; }