directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [1/2] directory-kerby git commit: Added some Javadoc
Date Wed, 30 Dec 2015 12:19:48 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 6a223db19 -> 047258b62


Added some Javadoc

Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/5c9c0070
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/5c9c0070
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/5c9c0070

Branch: refs/heads/trunk
Commit: 5c9c0070aec5472b1fe117c54aa481306eeffdcb
Parents: 6a223db
Author: Emmanuel Lécharny <elecharny@symas.com>
Authored: Wed Dec 30 12:56:13 2015 +0100
Committer: Emmanuel Lécharny <elecharny@symas.com>
Committed: Wed Dec 30 12:56:13 2015 +0100

----------------------------------------------------------------------
 .../kerberos/kerb/type/base/HostAddrType.java   | 22 ++++-
 .../kerberos/kerb/type/base/HostAddress.java    | 85 +++++++++++++++-----
 2 files changed, 87 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5c9c0070/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java
index 8315690..6cc67ac 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddrType.java
@@ -21,6 +21,11 @@ package org.apache.kerby.kerberos.kerb.type.base;
 
 import org.apache.kerby.asn1.EnumType;
 
+/**
+ * The various possible HostAddress types.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public enum HostAddrType implements EnumType {
     /**
      * Constant for the "null" host address type.
@@ -74,23 +79,38 @@ public enum HostAddrType implements EnumType {
      */
     ADDRTYPE_INET6(24);
 
-
+    /** the inner value */
     private final int value;
 
+    /**
+     * Create a new enum instance
+     */
     private HostAddrType(int value) {
         this.value = value;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public int getValue() {
         return value;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String getName() {
         return name();
     }
 
+    /**
+     * Get the HostAddrType associated with a value.
+     * 
+     * @param value The integer value of the HostAddrType we are looking for
+     * @return The associated NameType, or NULL if not found or if value is null
+     */
     public static HostAddrType fromValue(Integer value) {
         if (value != null) {
             for (EnumType e : values()) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5c9c0070/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java
index f2ef67a..7b5cc3d 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/base/HostAddress.java
@@ -29,95 +29,142 @@ import org.apache.kerby.asn1.type.Asn1Integer;
 import org.apache.kerby.asn1.type.Asn1OctetString;
 import org.apache.kerby.kerberos.kerb.type.KrbSequenceType;
 
-/*
-HostAddress     ::= SEQUENCE  {
-        addr-type       [0] Int32,
-        address         [1] OCTET STRING
-}
+/**
+ * The HostAddress as defined in RFC 4120 :
+ * <pre>
+ * HostAddress     ::= SEQUENCE  {
+ *         addr-type       [0] Int32,
+ *         address         [1] OCTET STRING
+ * }
+ * </pre>
  */
 public class HostAddress extends KrbSequenceType {
+    /**
+     * The HostAddress fields
+     */
     protected enum HostAddressField implements EnumType {
         ADDR_TYPE,
         ADDRESS;
 
+        /**
+         * {@inheritDoc}
+         */
         @Override
         public int getValue() {
             return ordinal();
         }
 
+        /**
+         * {@inheritDoc}
+         */
         @Override
         public String getName() {
             return name();
         }
     }
 
+    /** The HostAddress' fields */
     static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
             new ExplicitField(HostAddressField.ADDR_TYPE, Asn1Integer.class),
             new ExplicitField(HostAddressField.ADDRESS, Asn1OctetString.class)
     };
 
+    /**
+     * Creates a new (empty) instance ofHostAddress
+     */
     public HostAddress() {
         super(fieldInfos);
     }
 
+    /**
+     * Creates a new instance of a HostAddress using an {@link InetAddress} 
+     * @param inetAddress The {@link InetAddress} to use
+     */
     public HostAddress(InetAddress inetAddress) {
-        this();
+        super(fieldInfos);
 
         setAddrType(HostAddrType.ADDRTYPE_INET);
         setAddress(inetAddress.getAddress());
     }
 
+    /**
+     * @return The HostAddrType for this instance
+     */
     public HostAddrType getAddrType() {
         Integer value = getFieldAsInteger(HostAddressField.ADDR_TYPE);
+        
         return HostAddrType.fromValue(value);
     }
 
+    /**
+     * Sets the AddressType
+     * @param addrType The HostAddrType to set
+     */
     public void setAddrType(HostAddrType addrType) {
         setField(HostAddressField.ADDR_TYPE, addrType);
     }
 
+    /**
+     * @return The HostAddress as a byte[]
+     */
     public byte[] getAddress() {
         return getFieldAsOctets(HostAddressField.ADDRESS);
     }
 
+    /**
+     * Sets the address
+     * 
+     * @param address The address to use, as a byte[]
+     */
     public void setAddress(byte[] address) {
         setFieldAsOctets(HostAddressField.ADDRESS, address);
     }
 
+    /**
+     * Compare a given {@link InetAddress} with the current HostAddress
+     * @param address The {@link InetAddress} we want to compare with the HostAddress
+     * @return <tt>true</tt> if they are equal
+     */
     public boolean equalsWith(InetAddress address) {
         if (address == null) {
             return false;
         }
+        
         HostAddress that = new HostAddress(address);
-        return that.equals(this);
+        
+        return equals(that);
     }
 
+    /**
+     * @see Object#equals()
+     */
     @Override
     public boolean equals(Object other) {
-        if (other == null) {
-            return false;
-        }
         if (other == this) {
             return true;
-        } else if (!(other instanceof HostAddress)) {
+        }
+        
+        if (!(other instanceof HostAddress)) {
             return false;
         }
 
         HostAddress that = (HostAddress) other;
-        if (getAddrType() == that.getAddrType()
-                && Arrays.equals(getAddress(), that.getAddress())) {
-            return true;
-        }
-        return false;
+        
+        return getAddrType() == that.getAddrType()
+                && Arrays.equals(getAddress(), that.getAddress());
     }
 
+    /**
+     * @see Object#hashCode()
+     */
     @Override
     public int hashCode() {
-        int result = getAddrType().getValue();
+        int hash = 17 + getAddrType().getValue() * 31;
+        
         if (getAddress() != null) {
-            result = 31 * result + Arrays.hashCode(getAddress());
+            hash = 31 * hash + Arrays.hashCode(getAddress());
         }
 
-        return result;
+        return hash;
     }
 }


Mime
View raw message