/** * Adds a string attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, String value) { addAttribute(new Attribute(name, value)); }
/** * Adds an int attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, int value) { addAttribute(new Attribute(name, value)); }
/** * Adds a float attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, float value) { addAttribute(new Attribute(name, value)); }
/** * Adds a boolean attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, boolean value) { addAttribute(new Attribute(name, value)); }
/** * Adds a long attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, long value) { addAttribute(new Attribute(name, value)); }
/** * Adds a short attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, short value) { addAttribute(new Attribute(name, value)); }
/** * Adds a byte attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, byte value) { addAttribute(new Attribute(name, value)); }
/** * Adds a double attribute. * * @param name The attribute name. * @param value The attribute value. * @throws IllegalArgumentException When {@code name} is invalid * or another attribute with same name already exists. */ public void addAttribute(String name, double value) { addAttribute(new Attribute(name, value)); }
/** * Creates an element by cloning another one. * <p> * Cloning is shallow.<br> * For deep cloning, use {@link #clone(boolean)}. * * @param other The element to clone. */ public Element(Element other) { this(null, other.getName()); for (int index = 0; index < other.getAttributesCount(); index++) { addAttribute(new Attribute(other.getAttributeAt(index))); } }
@Test public void testString() { final Attribute att = new Attribute(NAME, "SSS"); assertEquals("SSS", att.getValue()); }
@Test public void testShort() { final Attribute att = new Attribute(NAME, (short) 10); assertEquals((short) 10, att.getValueAsShort()); assertEquals("10", att.getValue()); }
@Test public void testLong() { final Attribute att = new Attribute(NAME, 10L); assertEquals(10L, att.getValueAsLong()); assertEquals("10", att.getValue()); }
@Test public void testByte() { final Attribute att = new Attribute(NAME, (byte) 10); assertEquals((byte) 10, att.getValueAsByte()); assertEquals("10", att.getValue()); }
@Test public void testBoolean() { final Attribute att = new Attribute(NAME, true); assertTrue(att.getValueAsBoolean()); assertEquals("true", att.getValue()); }
@Test public void testFloat() { final Attribute att = new Attribute(NAME, 10.0f); assertEquals(10.0f, att.getValueAsFloat(), 1.0e-10); assertEquals("10.0", att.getValue()); }
@Test public void testInteger() { final Attribute att = new Attribute(NAME, 10); assertEquals(10, att.getValueAsInt()); assertEquals("10", att.getValue()); }
@Test public void testDouble() { final Attribute att = new Attribute(NAME, 10.0); assertEquals(10.0, att.getValueAsDouble(), 1.0e-10); assertEquals("10.0", att.getValue()); }
@Test public void testEnum() { final Attribute att = new Attribute(NAME, Enum.A); assertEquals(Enum.A, att.getValueAsEnum(Enum.class)); assertEquals(Enum.A.name(), att.getValue()); } }