harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r439141 - /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
Date Fri, 01 Sep 2006 02:32:28 GMT
Author: smishura
Date: Thu Aug 31 19:32:28 2006
New Revision: 439141

URL: http://svn.apache.org/viewvc?rev=439141&view=rev
Log:
Add toString(), equals(), hasCode() methods

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java?rev=439141&r1=439140&r2=439141&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
Thu Aug 31 19:32:28 2006
@@ -71,10 +71,41 @@
         return name;
     }
 
-    /** PrincipalName ::= SEQUENCE {
-     *      name-type   [0] Int32,
-     *      name-string [1] SEQUENCE OF KerberosString
-     *  }
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (!(obj instanceof PrincipalName)) {
+            return false;
+        }
+
+        PrincipalName that = (PrincipalName) obj;
+
+        return type == that.type && Arrays.equals(that.name, name);
+    }
+
+    public int hashCode() {
+        return type + Arrays.hashCode(name);
+    }
+
+    public String toString() {
+        StringBuilder buf = new StringBuilder("Name: ");
+
+        for (int i = 0; i < (name.length - 1); i++) {
+            buf.append(name[i]);
+            buf.append('/');
+        }
+        buf.append(name[name.length - 1]);
+        buf.append(", type: ");
+        buf.append(type);
+
+        return buf.toString();
+    }
+
+    /**
+     * PrincipalName ::= SEQUENCE { name-type [0] Int32, name-string [1]
+     * SEQUENCE OF KerberosString }
      */
     public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
             new ASN1Explicit(0, ASN1Integer.getInstance()),
@@ -86,7 +117,7 @@
             Object[] values = (Object[]) in.content;
 
             int type = ASN1Integer.toIntValue(values[0]);
-            
+
             // TODO: list to array conversion should be done by framework
             List list = (List) values[1];
             String[] name = new String[list.size()];
@@ -100,7 +131,7 @@
             PrincipalName name = (PrincipalName) object;
 
             values[0] = BigInteger.valueOf(name.getType()).toByteArray();
-            
+
             values[1] = Arrays.asList(name.getName());
         }
     };



Mime
View raw message