Reputation: 95
I am getting raw type warnings in my program.i used @SuppressWarnings("rawtypes"),but it is more convenient if there some other method to resolve this issue.can anyone help me i have this warning in the following code of NamingEnumeration part:
try {
String[] attrIDs = { Constants.UNIQUEMEMBER };
Attributes answer = iniDirContext.getAttributes("cn=" + groupName
+ "," + Constants.PROJECT_DN, attrIDs);
NamingEnumeration ae = answer.getAll();
Attribute attr = (Attribute) ae.next();
for (NamingEnumeration e = attr.getAll(); e.hasMore();) {
String str = e.next().toString();
if (getAppUserRole(str))
count = count + 1;
}
} catch (Exception e1) {
e1.printStackTrace();
}
Upvotes: 0
Views: 400
Reputation: 11093
Use as list1
NamingEnumeration<NameClassPair>
instead of the raw type. The same goes for results1
- use NamingEnumeration<SearchResult>
. That way, you don't even have to cast.
Compare your code with this:
ArrayList list = new ArrayList(); //raw typed
list.add("entry"); //add a string
String s = (String)list.get(0); //but return type is Object, because list in raw typed
ArrayList<String> list2 = new ArrayList<String>(); //strong typed
list2.add("entry"); //add a string
String s2 = list2.get(0); //return type is String, because list2 is strong typed
The whole code becomes:
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<NameClassPair> list1 = iniDirContext.list(Constants.ORG_SEARCH_BASE);
while (list1.hasMore()) {
String base = list1.next().getName() + "," + Constants.ORG_SEARCH_BASE; //no cast needed, list1 is strong typed
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(&(objectclass=groupOfUniqueNames))";
NamingEnumeration<SearchResult> results1 = iniDirContext.search(base, filter, searchControls);
while (results1.hasMore()) {
SearchResult searchResult = results1.next();
Attributes attributes = searchResult.getAttributes();
Attribute cn = attributes.get(Constants.CN);
Attribute address = attributes.get(Constants.POSTAL_ADDRESS);
if (cn.get().equals(oranizationData.getOrgName()) && address.equals(oranizationData.getOrgAddress())) {
return false;
}
}
}
Upvotes: 3
Reputation: 141
Use <Class_Name>
, most likely on NameClassPair
. Something like NameClassPair<String, String>
.
Upvotes: 0