Author: ngn
Date: Sun Aug  9 20:09:04 2009
New Revision: 802577

URL: http://svn.apache.org/viewvc?rev=802577&view=rev
Log:
Add toString()

Modified:
    
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/addressing/EntityImpl.java

Modified: 
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/addressing/EntityImpl.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/addressing/EntityImpl.java?rev=802577&r1=802576&r2=802577&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/addressing/EntityImpl.java
 (original)
+++ 
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/addressing/EntityImpl.java
 Sun Aug  9 20:09:04 2009
@@ -32,87 +32,96 @@
 public class EntityImpl implements Entity {
 
     public static final String CHAR_AT = "@";
+
     public static final String CHAR_SLASH = "/";
 
-       private String node;
-       private String domain;
-       private String resource;
+    private String node;
+
+    private String domain;
+
+    private String resource;
 
     protected String fullyQualifiedCached = null;
+
     protected Entity bareEntityCached = null;
 
     public static EntityImpl parse(String entity) throws EntityFormatException 
{
-               String node = null;
-               String domain;
-               String resource = null;
-               if (entity == null)
-                       throw new EntityFormatException("entity must not be 
NULL");
-
-               if (entity.contains(CHAR_AT)) {
-                       String[] parts = entity.split(CHAR_AT);
-                       if (parts.length != 2)
-                               throw new EntityFormatException(
-                                               "entity must be of format 
n...@domain/resource");
-                       node = parts[0];
-                       node = NodePrep.prepare(node);
-                       entity = parts[1];
-               }
-               domain = entity;
-               if (entity.contains(CHAR_SLASH)) {
-                       int indexOfSlash = entity.indexOf(CHAR_SLASH);
-                       domain = entity.substring(0, indexOfSlash);
-                       resource = entity.substring(indexOfSlash+1);
-                       resource = ResourcePrep.prepare(resource);
-               }
-               return new EntityImpl(node, domain, resource);
-       }
-
-       public EntityImpl(String node, String domain, String resource) {
-               this.node = node;
-               this.domain = domain;
-               this.resource = resource;
-       }
-
-       public EntityImpl(Entity bareId, String resource) {
-               this.node = bareId.getNode();
-               this.domain = bareId.getDomain();
-               this.resource = resource;
-       }
-
-       public String getNode() {
-               return node;
-       }
-
-       public String getDomain() {
-               return domain;
-       }
-
-       public String getResource() {
-               return resource;
-       }
+        String node = null;
+        String domain;
+        String resource = null;
+        if (entity == null)
+            throw new EntityFormatException("entity must not be NULL");
+
+        if (entity.contains(CHAR_AT)) {
+            String[] parts = entity.split(CHAR_AT);
+            if (parts.length != 2)
+                throw new EntityFormatException(
+                        "entity must be of format n...@domain/resource");
+            node = parts[0];
+            node = NodePrep.prepare(node);
+            entity = parts[1];
+        }
+        domain = entity;
+        if (entity.contains(CHAR_SLASH)) {
+            int indexOfSlash = entity.indexOf(CHAR_SLASH);
+            domain = entity.substring(0, indexOfSlash);
+            resource = entity.substring(indexOfSlash + 1);
+            resource = ResourcePrep.prepare(resource);
+        }
+        return new EntityImpl(node, domain, resource);
+    }
 
-       public String getFullQualifiedName() {
-        if (fullyQualifiedCached == null) fullyQualifiedCached = 
buildEntityString(node, domain, resource);
+    public EntityImpl(String node, String domain, String resource) {
+        this.node = node;
+        this.domain = domain;
+        this.resource = resource;
+    }
+
+    public EntityImpl(Entity bareId, String resource) {
+        this.node = bareId.getNode();
+        this.domain = bareId.getDomain();
+        this.resource = resource;
+    }
+
+    public String getNode() {
+        return node;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public String getResource() {
+        return resource;
+    }
+
+    public String getFullQualifiedName() {
+        if (fullyQualifiedCached == null)
+            fullyQualifiedCached = buildEntityString(node, domain, resource);
         return fullyQualifiedCached;
-       }
+    }
 
     private String buildEntityString(String node, String domain, String 
resource) {
         StringBuilder buffer = new StringBuilder();
-        if (isNodeSet()) buffer.append(node).append(CHAR_AT);
+        if (isNodeSet())
+            buffer.append(node).append(CHAR_AT);
         buffer.append(domain);
-        if (isResourceSet()) buffer.append(CHAR_SLASH).append(resource);
+        if (isResourceSet())
+            buffer.append(CHAR_SLASH).append(resource);
         return buffer.toString();
     }
 
     public Entity getBareJID() {
-        if (!isResourceSet()) return this; // this _is_ a bare id
-        if (bareEntityCached == null) bareEntityCached = new EntityImpl(node, 
domain, null);
+        if (!isResourceSet())
+            return this; // this _is_ a bare id
+        if (bareEntityCached == null)
+            bareEntityCached = new EntityImpl(node, domain, null);
         return bareEntityCached;
-       }
+    }
 
     public String getCanonicalizedName() {
-               return null;
-       }
+        return null;
+    }
 
     public boolean isNodeSet() {
         return node != null && !"".equals(node);
@@ -122,41 +131,47 @@
         return resource != null && !"".equals(resource);
     }
 
-
     @Override
     public boolean equals(Object o) {
-               if (this == o)
-                       return true;
-               if (o == null || !(o instanceof Entity))
-                       return false;
-
-               final Entity that = (Entity) o;
-
-               if (domain != null ? !domain.equals(that.getDomain()) : that
-                               .getDomain() != null)
-                       return false;
-        if (isNodeSet() != that.isNodeSet()) return false;
+        if (this == o)
+            return true;
+        if (o == null || !(o instanceof Entity))
+            return false;
+
+        final Entity that = (Entity) o;
+
+        if (domain != null ? !domain.equals(that.getDomain()) : that
+                .getDomain() != null)
+            return false;
+        if (isNodeSet() != that.isNodeSet())
+            return false;
         if (isNodeSet()) {
             if (node != null ? !node.equals(that.getNode())
                     : that.getNode() != null)
                 return false;
         }
-        if (isResourceSet() != that.isResourceSet()) return false;
+        if (isResourceSet() != that.isResourceSet())
+            return false;
         if (isResourceSet()) {
             if (resource != null ? !resource.equals(that.getResource()) : that
                     .getResource() != null)
                 return false;
         }
 
-               return true;
-       }
+        return true;
+    }
 
-       @Override
+    @Override
     public int hashCode() {
-               int result;
-               result = (node != null ? node.hashCode() : 0);
-               result = 29 * result + (domain != null ? domain.hashCode() : 0);
-               result = 29 * result + (resource != null ? resource.hashCode() 
: 0);
-               return result;
-       }
+        int result;
+        result = (node != null ? node.hashCode() : 0);
+        result = 29 * result + (domain != null ? domain.hashCode() : 0);
+        result = 29 * result + (resource != null ? resource.hashCode() : 0);
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return getFullQualifiedName();
+    }
 }


Reply via email to