public boolean hasAttribute(String key) { return _attributes.hasAttribute(key); }
public boolean hasAttribute(final String key) { return attributes.hasAttribute(key); }
/** * Gets the value at the specified key as a float * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, the value's {@link Number#floatValue()}. If it is not * a number, its {@link Object#toString()} is called and the result is parsed as a float. * If the key doesn't exist, defaultValue. * @throws CantCoerceException if the key exists, but the value is not a float and can't be * converted to one */ public float getAsFloat(final String key, final float defaultValue) { if (!(hasAttribute(key))) { return defaultValue; } else { return getAsFloat(key); } }
/** * Gets the value at the specified key as a long * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, the value's {@link Number#longValue()}. If it's not a * number, its {@link Object#toString()} is called and the result is parsed as a long. If * the key doesn't exist, defaultValue. * @throws CantCoerceException if the key exists, but the value is not a long and can't be * converted to one */ public long getAsLong(final String key, final long defaultValue) { if (!(hasAttribute(key))) { return defaultValue; } else { return getAsLong(key); } }
/** * Gets the value at the specified key as an integer * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, the value's {@link Number#intValue()}. If it is not a * number, its {@link Object#toString()} is called and the result is parsed as an integer. * If the key does not exist, defaultValue. * @throws CantCoerceException if the key exists, but the value is not an integer and can't be * converted to one */ public int getAsInt(final String key, final int defaultValue) { if (!(hasAttribute(key))) { return defaultValue; } else { return getAsInt(key); } }
/** * Gets the value at the specified key as a boolean * @param key the key of the value * @param defaultValue the value to return if the specified key doesn't exist * @return If the value is a {@link Boolean}, it is returned. If its {@link Object#toString()} * matches the words "true" or "false", one of those values is returned. If the key * doesn't exist, the specified default value is returned. * @throws CantCoerceException if the key exists, but the value is not a boolean and can't be * converted to one */ public boolean getAsBoolean(final String key, final boolean defaultValue) { if (!hasAttribute(key)) { return defaultValue; } else { return getAsBoolean(key); } }
/** * Gets the value at the specified key as a byte * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, its byte value is returned. Otherwise, its * {@link Object#toString()} is called and the result is passed to * {@link Byte#parseByte(String)}. If the key doesn't exist, the specified default value * is returned. * @throws CantCoerceException if the key exists, but the value is not a byte and can't be * converted to one */ public byte getAsByte(final String key, final byte defaultValue) { if (hasAttribute(key)) { return getAsByte(key); } else { return defaultValue; } }
/** * Gets the value at the specified key as a short * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, the value's {@link Number#shortValue()}. If the value * is not a number, its {@link Object#toString()} is called and the result is parsed as a * short. If the key doesn't exist, defaultValue. * @throws AttributeUndefinedException if the key doesn't exist * @throws CantCoerceException if the key exists, but the value is not a short and can't be * converted to one */ public short getAsShort(final String key, final short defaultValue) { if (!(hasAttribute(key))) { return defaultValue; } else { return getAsShort(key); } }
/** * Gets the value at the specified key as a character * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Character}, the value. If it is a {@link String} and is of * length 1, the character of the string. If the value doesn't exist, defaultValue. * @throws AttributeUndefinedException if the key doesn't exist * @throws CantCoerceException if the key exists, but the value is not a character and can't be * converted to one */ public char getAsChar(final String key, final char defaultValue) { if (!hasAttribute(key)) { return defaultValue; } else { return getAsChar(key); } }
/** * Gets the value at the specified key as a double * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, the value's {@link Number#doubleValue()}. If it is * not a number, its {@link Object#toString()} is called and the result is parsed as a * double. If the key doesn't exist, defaultValue. * @throws CantCoerceException if the key exists, but the value is not a double and can't be * converted to one */ public double getAsDouble(final String key, final double defaultValue) { if (!(hasAttribute(key))) { return defaultValue; } else { return getAsDouble(key); } }
/** * Gets the value of a key * @param key the key to find * @return the value at the specified key * @throws AttributeUndefinedException if the key doesn't exist */ public Object get(final String key) { if (this.hasAttribute(key)) { AttributeHolder attribute = attributes.get(key); return (attribute == null) ? attribute : attribute.getValue(); } throw new AttributeUndefinedException(key); }