src/share/classes/com/sun/jndi/dns/DnsName.java

Print this page

        

@@ -27,11 +27,10 @@
 
 
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Enumeration;
-import java.util.Iterator;
 
 import javax.naming.*;
 
 
 /**

@@ -109,11 +108,11 @@
     private String domain = "";
 
     // The labels of this domain name, as a list of strings.  Index 0
     // corresponds to the leftmost (least significant) label:  note that
     // this is the reverse of the ordering used by the Name interface.
-    private ArrayList labels = new ArrayList();
+    private ArrayList<String> labels = new ArrayList<>();
 
     // The number of octets needed to carry this domain name in a DNS
     // packet.  Equal to the sum of the lengths of each label, plus the
     // number of non-root labels, plus 1.  Must remain less than 256.
     private short octets = 1;

@@ -150,27 +149,23 @@
 
         if (size() == n.size()) {
             domain = n.domain;
             octets = n.octets;
         } else {
-            Iterator iter = labels.iterator();
-            while (iter.hasNext()) {
-                String label = (String) iter.next();
+            for (String label: labels) {
                 if (label.length() > 0) {
                     octets += (short) (label.length() + 1);
                 }
             }
         }
     }
 
 
     public String toString() {
         if (domain == null) {
-            StringBuffer buf = new StringBuffer();
-            Iterator iter = labels.iterator();
-            while (iter.hasNext()) {
-                String label = (String) iter.next();
+            StringBuilder buf = new StringBuilder();
+            for (String label: labels) {
                 if (buf.length() > 0 || label.length() == 0) {
                     buf.append('.');
                 }
                 escape(buf, label);
             }

@@ -181,13 +176,12 @@
 
     /**
      * Does this domain name follow <em>host name</em> syntax?
      */
     public boolean isHostName() {
-        Iterator iter = labels.iterator();
-        while (iter.hasNext()) {
-            if (!isHostNameLabel((String) iter.next())) {
+        for (String label: labels) {
+            if (!isHostNameLabel(label)) {
                 return false;
             }
         }
         return true;
     }

@@ -239,20 +233,20 @@
     public String get(int pos) {
         if (pos < 0 || pos >= size()) {
             throw new ArrayIndexOutOfBoundsException();
         }
         int i = size() - pos - 1;       // index of "pos" component in "labels"
-        return (String) labels.get(i);
+        return labels.get(i);
     }
 
-    public Enumeration getAll() {
-        return new Enumeration() {
+    public Enumeration<String> getAll() {
+        return new Enumeration<String>() {
             int pos = 0;
             public boolean hasMoreElements() {
                 return (pos < size());
             }
-            public Object nextElement() {
+            public String nextElement() {
                 if (pos < size()) {
                     return get(pos++);
                 }
                 throw new java.util.NoSuchElementException();
             }

@@ -274,11 +268,11 @@
     public Object remove(int pos) {
         if (pos < 0 || pos >= size()) {
             throw new ArrayIndexOutOfBoundsException();
         }
         int i = size() - pos - 1;     // index of element to remove in "labels"
-        String label = (String) labels.remove(i);
+        String label = labels.remove(i);
         int len = label.length();
         if (len > 0) {
             octets -= (short) (len + 1);
         }
         domain = null;          // invalidate "domain"

@@ -528,11 +522,11 @@
     }
 
     /*
      * Append a label to buf, escaping as needed.
      */
-    private static void escape(StringBuffer buf, String label) {
+    private static void escape(StringBuilder buf, String label) {
         for (int i = 0; i < label.length(); i++) {
             char c = label.charAt(i);
             if (c == '.' || c == '\\') {
                 buf.append('\\');
             }