src/share/classes/javax/naming/ldap/LdapName.java
Print this page
@@ -102,13 +102,11 @@
* @since 1.5
*/
public class LdapName implements Name {
- // private transient ArrayList<Rdn> rdns; // parsed name components
-
- private transient ArrayList rdns; // parsed name components
+ private transient List<Rdn> rdns; // parsed name components
private transient String unparsed; // if non-null, the DN in unparsed form
private static final long serialVersionUID = -1595520034788997356L;
/**
* Constructs an LDAP name from the given distinguished name.
@@ -142,35 +140,33 @@
// } else {
// throw IllegalArgumentException(
// "Invalid entries, list entries must be of type Rdn");
// }
- this.rdns = new ArrayList(rdns.size());
+ this.rdns = new ArrayList<>(rdns.size());
for (int i = 0; i < rdns.size(); i++) {
Object obj = rdns.get(i);
if (!(obj instanceof Rdn)) {
throw new IllegalArgumentException("Entry:" + obj +
" not a valid type;list entries must be of type Rdn");
}
- this.rdns.add(obj);
+ this.rdns.add((Rdn)obj);
}
}
/*
* Constructs an LDAP name given its parsed components (the elements
* of "rdns" in the range [beg,end)) and, optionally
* (if "name" is not null), the unparsed DN.
*
*/
- // private LdapName(String name, List<Rdn> rdns, int beg, int end) {
-
- private LdapName(String name, ArrayList rdns, int beg, int end) {
+ private LdapName(String name, List<Rdn> rdns, int beg, int end) {
unparsed = name;
// this.rdns = rdns.subList(beg, end);
- List sList = rdns.subList(beg, end);
- this.rdns = new ArrayList(sList);
+ List<Rdn> sList = rdns.subList(beg, end);
+ this.rdns = new ArrayList<>(sList);
}
/**
* Retrieves the number of components in this LDAP name.
* @return The non-negative number of components in this LDAP name.
@@ -199,11 +195,11 @@
*
* @return A non-null enumeration of the components of this LDAP name.
* Each element of the enumeration is of class String.
*/
public Enumeration<String> getAll() {
- final Iterator iter = rdns.iterator();
+ final Iterator<Rdn> iter = rdns.iterator();
return new Enumeration<String>() {
public boolean hasMoreElements() {
return iter.hasNext();
}
@@ -232,11 +228,11 @@
* @return The non-null RDN at index posn.
* @exception IndexOutOfBoundsException if posn is outside the
* specified range.
*/
public Rdn getRdn(int posn) {
- return (Rdn) rdns.get(posn);
+ return rdns.get(posn);
}
/**
* Creates a name whose components consist of a prefix of the
* components of this LDAP name.
@@ -368,11 +364,11 @@
int len2 = rdns.size();
return (len1 >= len2 &&
doesListMatch(len1 - len2, len1, rdns));
}
- private boolean doesListMatch(int beg, int end, List rdns) {
+ private boolean doesListMatch(int beg, int end, List<Rdn> rdns) {
for (int i = beg; i < end; i++) {
if (!this.rdns.get(i).equals(rdns.get(i - beg))) {
return false;
}
}
@@ -455,14 +451,14 @@
unparsed = null; // no longer valid
if (suffix instanceof LdapName) {
LdapName s = (LdapName) suffix;
rdns.addAll(posn, s.rdns);
} else {
- Enumeration comps = suffix.getAll();
+ Enumeration<String> comps = suffix.getAll();
while (comps.hasMoreElements()) {
rdns.add(posn++,
- (new Rfc2253Parser((String) comps.nextElement()).
+ (new Rfc2253Parser(comps.nextElement()).
parseRdn()));
}
}
return this;
}
@@ -487,11 +483,11 @@
Object obj = suffixRdns.get(i);
if (!(obj instanceof Rdn)) {
throw new IllegalArgumentException("Entry:" + obj +
" not a valid type;suffix list entries must be of type Rdn");
}
- rdns.add(i + posn, obj);
+ rdns.add(i + posn, (Rdn)obj);
}
return this;
}
/**
@@ -625,15 +621,15 @@
return unparsed;
}
StringBuilder builder = new StringBuilder();
int size = rdns.size();
if ((size - 1) >= 0) {
- builder.append((Rdn) rdns.get(size - 1));
+ builder.append(rdns.get(size - 1));
}
for (int next = size - 2; next >= 0; next--) {
builder.append(',');
- builder.append((Rdn) rdns.get(next));
+ builder.append(rdns.get(next));
}
unparsed = builder.toString();
return unparsed;
}
@@ -670,12 +666,12 @@
return true;
}
// Compare RDNs one by one for equality
for (int i = 0; i < rdns.size(); i++) {
// Compare a single pair of RDNs.
- Rdn rdn1 = (Rdn) rdns.get(i);
- Rdn rdn2 = (Rdn) that.rdns.get(i);
+ Rdn rdn1 = rdns.get(i);
+ Rdn rdn2 = that.rdns.get(i);
if (!rdn1.equals(rdn2)) {
return false;
}
}
return true;
@@ -725,12 +721,12 @@
// Compare RDNs one by one, lexicographically.
int minSize = Math.min(rdns.size(), that.rdns.size());
for (int i = 0; i < minSize; i++) {
// Compare a single pair of RDNs.
- Rdn rdn1 = (Rdn)rdns.get(i);
- Rdn rdn2 = (Rdn)that.rdns.get(i);
+ Rdn rdn1 = rdns.get(i);
+ Rdn rdn2 = that.rdns.get(i);
int diff = rdn1.compareTo(rdn2);
if (diff != 0) {
return diff;
}
@@ -750,11 +746,11 @@
// Sum up the hash codes of the components.
int hash = 0;
// For each RDN...
for (int i = 0; i < rdns.size(); i++) {
- Rdn rdn = (Rdn) rdns.get(i);
+ Rdn rdn = rdns.get(i);
hash += rdn.hashCode();
}
return hash;
}
@@ -784,8 +780,8 @@
}
private void parse() throws InvalidNameException {
// rdns = (ArrayList<Rdn>) (new RFC2253Parser(unparsed)).getDN();
- rdns = (ArrayList) (new Rfc2253Parser(unparsed)).parseDn();
+ rdns = new Rfc2253Parser(unparsed).parseDn();
}
}