You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2018/05/23 12:31:09 UTC

[GitHub] DaanHoogland closed pull request #2660: Macaddresses

DaanHoogland closed pull request #2660: Macaddresses
URL: https://github.com/apache/cloudstack/pull/2660
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/utils/src/main/java/com/cloud/utils/net/MacAddress.java b/utils/src/main/java/com/cloud/utils/net/MacAddress.java
index b9118cfcab0..fd82de80c8a 100644
--- a/utils/src/main/java/com/cloud/utils/net/MacAddress.java
+++ b/utils/src/main/java/com/cloud/utils/net/MacAddress.java
@@ -31,9 +31,9 @@
 
 import org.apache.log4j.Logger;
 
-import com.cloud.utils.NumbersUtil;
-
 /**
+ * This class retrieves the (first) MAC address for the machine is it is loaded on and stores it statically for retrieval.
+ * It can also be used for formatting MAC addresses.
  * copied from the public domain utility from John Burkard.
  * @author <a href="mailto:jb@eaio.com">Johann Burkard</a>
  * @version 2.1.3
@@ -242,13 +242,6 @@ static String parse(String in) {
         return null;
     }
 
-    public static void main(String[] args) {
-        MacAddress addr = MacAddress.getMacAddress();
-        System.out.println("addr in integer is " + addr.toLong());
-        System.out.println("addr in bytes is " + NumbersUtil.bytesToString(addr.toByteArray(), 0, addr.toByteArray().length));
-        System.out.println("addr in char is " + addr.toString(":"));
-    }
-
     /**
      * Parses a <code>long</code> from a hex encoded number. This method will skip
      * all characters that are not 0-9 and a-f (the String is lower cased first).
@@ -258,7 +251,7 @@ public static void main(String[] args) {
      * @return a <code>long</code>
      * @throws NullPointerException if the String is <code>null</code>
      */
-    public static long parseLong(String s) throws NullPointerException {
+    private static long parseLong(String s) throws NullPointerException {
         s = s.toLowerCase();
         long out = 0;
         byte shifts = 0;
@@ -278,35 +271,6 @@ public static long parseLong(String s) throws NullPointerException {
         return out;
     }
 
-    /**
-     * Parses an <code>int</code> from a hex encoded number. This method will skip
-     * all characters that are not 0-9 and a-f (the String is lower cased first).
-     * Returns 0 if the String does not contain any interesting characters.
-     *
-     * @param s the String to extract an <code>int</code> from, may not be <code>null</code>
-     * @return an <code>int</code>
-     * @throws NullPointerException if the String is <code>null</code>
-     */
-    public static int parseInt(String s) throws NullPointerException {
-        s = s.toLowerCase();
-        int out = 0;
-        byte shifts = 0;
-        char c;
-        for (int i = 0; i < s.length() && shifts < 8; i++) {
-            c = s.charAt(i);
-            if ((c > 47) && (c < 58)) {
-                out <<= 4;
-                ++shifts;
-                out |= c - 48;
-            } else if ((c > 96) && (c < 103)) {
-                ++shifts;
-                out <<= 4;
-                out |= c - 87;
-            }
-        }
-        return out;
-    }
-
     /**
      * Parses a <code>short</code> from a hex encoded number. This method will skip
      * all characters that are not 0-9 and a-f (the String is lower cased first).
@@ -316,7 +280,7 @@ public static int parseInt(String s) throws NullPointerException {
      * @return a <code>short</code>
      * @throws NullPointerException if the String is <code>null</code>
      */
-    public static short parseShort(String s) throws NullPointerException {
+    private static short parseShort(String s) throws NullPointerException {
         s = s.toLowerCase();
         short out = 0;
         byte shifts = 0;
@@ -335,33 +299,4 @@ public static short parseShort(String s) throws NullPointerException {
         }
         return out;
     }
-
-    /**
-     * Parses a <code>byte</code> from a hex encoded number. This method will skip
-     * all characters that are not 0-9 and a-f (the String is lower cased first).
-     * Returns 0 if the String does not contain any interesting characters.
-     *
-     * @param s the String to extract a <code>byte</code> from, may not be <code>null</code>
-     * @return a <code>byte</code>
-     * @throws NullPointerException if the String is <code>null</code>
-     */
-    public static byte parseByte(String s) throws NullPointerException {
-        s = s.toLowerCase();
-        byte out = 0;
-        byte shifts = 0;
-        char c;
-        for (int i = 0; i < s.length() && shifts < 2; i++) {
-            c = s.charAt(i);
-            if ((c > 47) && (c < 58)) {
-                out <<= 4;
-                ++shifts;
-                out |= c - 48;
-            } else if ((c > 96) && (c < 103)) {
-                ++shifts;
-                out <<= 4;
-                out |= c - 87;
-            }
-        }
-        return out;
-    }
 }
diff --git a/utils/src/test/java/com/cloud/utils/net/MacAddressTest.java b/utils/src/test/java/com/cloud/utils/net/MacAddressTest.java
index 845a435eb54..78da1d6d08c 100644
--- a/utils/src/test/java/com/cloud/utils/net/MacAddressTest.java
+++ b/utils/src/test/java/com/cloud/utils/net/MacAddressTest.java
@@ -21,6 +21,7 @@
 
 import static org.junit.Assert.assertEquals;
 
+import com.cloud.utils.NumbersUtil;
 import org.junit.Test;
 
 public class MacAddressTest {
@@ -51,10 +52,4 @@ public final void testMacAddressToLong() throws Exception {
     // TODO    public final void testToString() throws Exception {
     // TODO    public final void testGetMacAddress() throws Exception {
     // TODO    public final void testParse() throws Exception {
-    // TODO    public final void testMain() throws Exception {
-    // TODO    public final void testParseLong() throws Exception {
-    // TODO    public final void testParseInt() throws Exception {
-    // TODO    public final void testParseShort() throws Exception {
-    // TODO    public final void testParseByte() throws Exception {
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services