MultiAttributeCollection extends MultiAttributeProvider implements AttributeCollection { @Override public boolean renameAttribute(String oldname, String newname) { final boolean b = this.runProviderEvents.getAndSet(false); try { boolean changed = false; final ManyValueAttributeValue currentValue = new ManyValueAttributeValue(); for (final AttributeProvider c : containers()) { assign(currentValue, c.getAttribute(oldname)); if (c instanceof AttributeCollection) { changed = ((AttributeCollection) c).renameAttribute(oldname, newname) || changed; } } if (changed) { final AttributeValue cValue = canonize(currentValue); this.cache.remove(oldname); this.cache.remove(newname); if (this.names != null) { this.names.remove(oldname); this.names.add(newname); } fireAttributeChange(new AttributeChangeEvent(this, Type.RENAME, oldname, cValue, newname, cValue)); } return changed; } finally { this.runProviderEvents.set(b); } }  @Pure @Override synchronized boolean isEventFirable(); @Override synchronized void setEventFirable(boolean isFirable); @Override MultiAttributeCollection clone(); @Override boolean addAttributeContainer(AttributeProvider container); @Override boolean removeAttributeContainer(AttributeProvider container); @Override void addAttributeChangeListener(AttributeChangeListener listener); @Override void removeAttributeChangeListener(AttributeChangeListener listener); @Override void flush(); @Override boolean removeAllAttributes(); @Override boolean removeAttribute(String name); @Override boolean renameAttribute(String oldname, String newname); @Override boolean renameAttribute(String oldname, String newname, boolean overwrite); @Override void addAttributes(AttributeProvider content); @Override void addAttributes(Map<String, Object> content); @Override void setAttributes(AttributeProvider content); @Override void setAttributes(Map<String, Object> content); @Override Attribute setAttribute(String name, AttributeValue value); @Override Attribute setAttribute(String name, boolean value); @Override Attribute setAttribute(String name, int value); @Override Attribute setAttribute(String name, long value); @Override Attribute setAttribute(String name, float value); @Override Attribute setAttribute(String name, double value); @Override Attribute setAttribute(String name, String value); @Override Attribute setAttribute(String name, InetAddress value); @Override Attribute setAttribute(String name, InetSocketAddress value); @Override Attribute setAttribute(String name, Enum<?> value); @Override Attribute setAttribute(String name, Class<?> value); @Override Attribute setAttribute(String name, UUID value); @Override Attribute setAttribute(String name, URL value); @Override Attribute setAttribute(String name, URI value); @Override Attribute setAttribute(String name, Date value); @Override Attribute setAttribute(Attribute value); @Override Attribute setAttributeType(String name, AttributeType type);  }
@Test public void renameAttributeStringString() throws Exception { assertTrue(this.provider.renameAttribute("A", "ZZZ")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); assertFalse(this.provider.renameAttribute("TOTOZZZ", "A")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); assertFalse(this.provider.renameAttribute("TOTOZZZ", "A")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); }
@Test public void renameAttributeStringStringBoolean() throws Exception { assertTrue(this.provider.renameAttribute("A", "ZZZ")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); assertFalse(this.provider.renameAttribute("TOTOZZZ", "A")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); assertFalse(this.provider.renameAttribute("TOTOZZZ", "A")); assertEquals(5, this.subprovider1.getAttributeCount()); assertEquals(5, this.subprovider2.getAttributeCount()); assertEquals(6, this.subprovider3.getAttributeCount()); assertEquals(2, this.subcontainer4.getAttributeCount()); assertEquals(10, this.provider.getAttributeCount()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("C", new URL("http: new AttributeImpl("E", new URL("http: new AttributeImpl("Z1", "Z1") ), this.subprovider1.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", true), new AttributeImpl("B", 1), new AttributeImpl("D", "abc"), new AttributeImpl("E", 1), new AttributeImpl("Z2", "Z2") ), this.subprovider2.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("ZZZ", false), new AttributeImpl("B", 1.), new AttributeImpl("C", new URL("http: new AttributeImpl("D", "abc"), new AttributeImpl("E", true), new AttributeImpl("Z3", "Z3") ), this.subprovider3.getAllAttributes()); assertEpsilonEquals(Arrays.asList( new AttributeImpl("A", true), new AttributeImpl("Z4", "Z4") ), this.subcontainer4.getAllAttributes()); assertEpsilonEquals(Arrays.asList( makeUninitialized("ZZZ", AttributeType.BOOLEAN), makeUninitialized("A", AttributeType.BOOLEAN), makeUninitialized("B", AttributeType.INTEGER), makeUninitialized("C", AttributeType.URL), makeUninitialized("D", AttributeType.STRING), makeUninitialized("E", AttributeType.OBJECT), makeUninitialized("Z1", AttributeType.STRING), makeUninitialized("Z2", AttributeType.STRING), makeUninitialized("Z3", AttributeType.STRING), makeUninitialized("Z4", AttributeType.STRING) ), this.provider.getAllAttributes()); }