src/share/classes/javax/naming/ldap/Rdn.java
Print this page
@@ -102,12 +102,11 @@
* @since 1.5
*/
public class Rdn implements Serializable, Comparable<Object> {
- // private transient ArrayList<RdnEntry> entries;
- private transient ArrayList entries;
+ private transient ArrayList<RdnEntry> entries;
// The common case.
private static final int DEFAULT_SIZE = 1;
private static final long serialVersionUID = -5994465067210009656L;
@@ -128,16 +127,16 @@
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
- entries = new ArrayList(attrSet.size());
- NamingEnumeration attrs = attrSet.getAll();
+ entries = new ArrayList<>(attrSet.size());
+ NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
- Attribute attr = (Attribute) attrs.next();
+ Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
@@ -159,22 +158,22 @@
* @param rdnString The non-null and non-empty RFC2253 formatted string.
* @throws InvalidNameException If a syntax error occurs during
* parsing of the rdnString.
*/
public Rdn(String rdnString) throws InvalidNameException {
- entries = new ArrayList(DEFAULT_SIZE);
+ entries = new ArrayList<>(DEFAULT_SIZE);
(new Rfc2253Parser(rdnString)).parseRdn(this);
}
/**
* Constructs an Rdn from the given <tt>rdn</tt>.
* The contents of the <tt>rdn</tt> are simply copied into the newly
* created Rdn.
* @param rdn The non-null Rdn to be copied.
*/
public Rdn(Rdn rdn) {
- entries = new ArrayList(rdn.entries.size());
+ entries = new ArrayList<>(rdn.entries.size());
entries.addAll(rdn.entries);
}
/**
* Constructs an Rdn from the given attribute type and
@@ -197,22 +196,22 @@
if (type.equals("") || isEmptyValue(value)) {
throw new InvalidNameException(
"type or value cannot be empty, type:" + type +
" value:" + value);
}
- entries = new ArrayList(DEFAULT_SIZE);
+ entries = new ArrayList<>(DEFAULT_SIZE);
put(type, value);
}
private boolean isEmptyValue(Object val) {
return ((val instanceof String) && val.equals("")) ||
((val instanceof byte[]) && (((byte[]) val).length == 0));
}
// An empty constructor used by the parser
Rdn() {
- entries = new ArrayList(DEFAULT_SIZE);
+ entries = new ArrayList<>(DEFAULT_SIZE);
}
/*
* Adds the given attribute type and value to this Rdn.
* The string attribute values are not interpretted as
@@ -255,11 +254,11 @@
* to the type returned by {@link #getType() getType()} method.
*
* @return The non-null attribute value.
*/
public Object getValue() {
- return ((RdnEntry) entries.get(0)).getValue();
+ return entries.get(0).getValue();
}
/**
* Retrieves one of this Rdn's type.
* This is a convenience method for obtaining the type,
@@ -273,11 +272,11 @@
* value corresponding to the type returned by this method.
*
* @return The non-null attribute type.
*/
public String getType() {
- return ((RdnEntry) entries.get(0)).getType();
+ return entries.get(0).getType();
}
/**
* Returns this Rdn as a string represented in a format defined by
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a> and described
@@ -327,12 +326,11 @@
Rdn that = (Rdn) obj;
int minSize = Math.min(entries.size(), that.entries.size());
for (int i = 0; i < minSize; i++) {
// Compare a single pair of type/value pairs.
- int diff = ((RdnEntry) entries.get(i)).compareTo(
- that.entries.get(i));
+ int diff = entries.get(i).compareTo(that.entries.get(i));
if (diff != 0) {
return diff;
}
}
return (entries.size() - that.entries.size()); // longer RDN wins
@@ -406,22 +404,22 @@
* mappings of this Rdn.
*/
public Attributes toAttributes() {
Attributes attrs = new BasicAttributes(true);
for (int i = 0; i < entries.size(); i++) {
- RdnEntry entry = (RdnEntry) entries.get(i);
+ RdnEntry entry = entries.get(i);
Attribute attr = attrs.put(entry.getType(), entry.getValue());
if (attr != null) {
attr.add(entry.getValue());
attrs.put(attr);
}
}
return attrs;
}
- private static class RdnEntry implements Comparable {
+ private static class RdnEntry implements Comparable<RdnEntry> {
private String type;
private Object value;
// If non-null, a cannonical representation of the value suitable
// for comparison using String.compareTo()
@@ -433,16 +431,11 @@
Object getValue() {
return value;
}
- public int compareTo(Object obj) {
-
- // Any change here affecting equality must be
- // reflected in hashCode().
- RdnEntry that = (RdnEntry) obj;
-
+ public int compareTo(RdnEntry that) {
int diff = type.toUpperCase().compareTo(
that.type.toUpperCase());
if (diff != 0) {
return diff;
}
@@ -753,11 +746,11 @@
}
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
s.defaultReadObject();
- entries = new ArrayList(DEFAULT_SIZE);
+ entries = new ArrayList<>(DEFAULT_SIZE);
String unparsed = (String) s.readObject();
try {
(new Rfc2253Parser(unparsed)).parseRdn(this);
} catch (InvalidNameException e) {
// shouldn't happen