Author: jverhaeg(a)redhat.com
Date: 2008-06-02 15:54:56 -0400 (Mon, 02 Jun 2008)
New Revision: 229
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
Log:
DNA-94: Changed to throw IAE if name is null or empty
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-06-02
19:48:40 UTC (rev 228)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-06-02
19:54:56 UTC (rev 229)
@@ -2,7 +2,7 @@
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -31,117 +31,122 @@
/**
* A basic implementation of {@link Name}.
+ *
* @author Randall Hauch
+ * @author John Verhaeg
*/
@Immutable
public class BasicName implements Name {
- private final String namespaceUri;
- private final String localName;
- private final int hc;
+ private final String namespaceUri;
+ private final String localName;
+ private final int hc;
- public BasicName( String namespaceUri, String localName ) {
- this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
- this.localName = localName != null ? localName.trim() : "";
- this.hc = HashCode.compute(this.namespaceUri, this.localName);
- }
+ public BasicName( String namespaceUri,
+ String localName ) {
+ ArgCheck.isNotEmpty(localName, "localName");
+ this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
+ this.localName = localName != null ? localName.trim() : "";
+ this.hc = HashCode.compute(this.namespaceUri, this.localName);
+ }
- /**
- * {@inheritDoc}
- */
- public String getLocalName() {
- return this.localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return this.localName;
+ }
- /**
- * {@inheritDoc}
- */
- public String getNamespaceUri() {
- return this.namespaceUri;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return this.namespaceUri;
+ }
- /**
- * {@inheritDoc}
- */
- public String getString() {
- return getString(Path.DEFAULT_ENCODER);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(Path.DEFAULT_ENCODER);
+ }
- /**
- * {@inheritDoc}
- */
- public String getString( TextEncoder encoder ) {
- if (this.getNamespaceUri().length() == 0) {
- if (this.getLocalName().equals(Path.SELF)) return Path.SELF;
- if (this.getLocalName().equals(Path.PARENT)) return Path.PARENT;
- }
- if (encoder == null) encoder = Path.DEFAULT_ENCODER;
- return "{" + encoder.encode(this.namespaceUri) + "}" +
encoder.encode(this.localName);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ if (this.getNamespaceUri().length() == 0) {
+ if (this.getLocalName().equals(Path.SELF)) return Path.SELF;
+ if (this.getLocalName().equals(Path.PARENT)) return Path.PARENT;
+ }
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ return "{" + encoder.encode(this.namespaceUri) + "}" +
encoder.encode(this.localName);
+ }
- /**
- * {@inheritDoc}
- */
- public String getString( NamespaceRegistry namespaceRegistry ) {
- ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri,
true);
- if (prefix != null) {
- return prefix + ":" + this.localName;
- }
- return this.localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri, true);
+ if (prefix != null) {
+ return prefix + ":" + this.localName;
+ }
+ return this.localName;
+ }
- /**
- * {@inheritDoc}
- */
- public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder )
{
- ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri,
true);
- if (prefix != null && prefix.length() != 0) {
- return encoder.encode(prefix) + ":" +
encoder.encode(this.localName);
- }
- return this.localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry,
+ TextEncoder encoder ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri, true);
+ if (prefix != null && prefix.length() != 0) {
+ return encoder.encode(prefix) + ":" + encoder.encode(this.localName);
+ }
+ return this.localName;
+ }
- /**
- * {@inheritDoc}
- */
- public int compareTo( Name that ) {
- if (that == this) return 0;
- int diff = this.getNamespaceUri().compareTo(that.getNamespaceUri());
- if (diff != 0) return diff;
- diff = this.getLocalName().compareTo(that.getLocalName());
- return diff;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (that == this) return 0;
+ int diff = this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ if (diff != 0) return diff;
+ diff = this.getLocalName().compareTo(that.getLocalName());
+ return diff;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return this.hc;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return this.hc;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals( Object obj ) {
- if (obj == this) return true;
- if (obj instanceof Name) {
- Name that = (Name)obj;
- if (!this.getNamespaceUri().equals(that.getNamespaceUri())) return false;
- return this.getLocalName().equals(that.getLocalName());
- }
- return false;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getNamespaceUri().equals(that.getNamespaceUri())) return false;
+ return this.getLocalName().equals(that.getLocalName());
+ }
+ return false;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "{" + this.namespaceUri + "}" + this.localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "{" + this.namespaceUri + "}" + this.localName;
+ }
}
Show replies by date