@@ -35,22 +35,22 @@ private interface Element {
3535 return (int )expire ;
3636}
3737
38- private static class CacheRRset extends RRset implements Element {
38+ private static class CacheRRset < T extends Record > extends RRset < T > implements Element {
3939 private static final long serialVersionUID = 5971755205903597024L ;
4040
4141 int credibility ;
4242 int expire ;
4343
4444 public
45- CacheRRset (Record rec , int cred , long maxttl ) {
45+ CacheRRset (T rec , int cred , long maxttl ) {
4646 super ();
4747 this .credibility = cred ;
4848 this .expire = limitExpire (rec .getTTL (), maxttl );
4949 addRR (rec );
5050 }
5151
5252 public
53- CacheRRset (RRset rrset , int cred , long maxttl ) {
53+ CacheRRset (RRset < T > rrset , int cred , long maxttl ) {
5454 super (rrset );
5555 this .credibility = cred ;
5656 this .expire = limitExpire (rrset .getTTL (), maxttl );
@@ -132,7 +132,7 @@ private static class NegativeElement implements Element {
132132 }
133133}
134134
135- private static class CacheMap extends LinkedHashMap {
135+ private static class CacheMap extends LinkedHashMap < Name , Object > {
136136 private int maxsize ;
137137
138138 CacheMap (int maxsize ) {
@@ -198,7 +198,7 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
198198 Master m = new Master (file );
199199 Record record ;
200200 while ((record = m .nextRecord ()) != null )
201- addRecord (record , Credibility .HINT , m );
201+ addRecord (record , Credibility .HINT );
202202}
203203
204204private synchronized Object
@@ -214,9 +214,10 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
214214private synchronized Element []
215215allElements (Object types ) {
216216 if (types instanceof List ) {
217- List typelist = (List ) types ;
217+ @ SuppressWarnings ("unchecked" )
218+ List <Element > typelist = (List <Element >) types ;
218219 int size = typelist .size ();
219- return ( Element []) typelist .toArray (new Element [size ]);
220+ return typelist .toArray (new Element [size ]);
220221 } else {
221222 Element set = (Element ) types ;
222223 return new Element [] {set };
@@ -271,9 +272,10 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
271272 }
272273 int type = element .getType ();
273274 if (types instanceof List ) {
275+ @ SuppressWarnings ("unchecked" )
274276 List <Element > list = (List <Element >) types ;
275277 for (int i = 0 ; i < list .size (); i ++) {
276- Element elt = ( Element ) list .get (i );
278+ Element elt = list .get (i );
277279 if (elt .getType () == type ) {
278280 list .set (i , element );
279281 return ;
@@ -328,22 +330,22 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
328330 * Adds a record to the Cache.
329331 * @param r The record to be added
330332 * @param cred The credibility of the record
331- * @param o The source of the record (this could be a Message, for example)
332333 * @see Record
333334 */
334335public synchronized void
335- addRecord (Record r , int cred , Object o ) {
336+ addRecord (Record r , int cred ) {
336337 Name name = r .getName ();
337338 int type = r .getRRsetType ();
338339 if (!Type .isRR (type ))
339340 return ;
340341 Element element = findElement (name , type , cred );
341342 if (element == null ) {
342- CacheRRset crrset = new CacheRRset (r , cred , maxcache );
343+ CacheRRset < Record > crrset = new CacheRRset <> (r , cred , maxcache );
343344 addRRset (crrset , cred );
344345 } else if (element .compareCredibility (cred ) == 0 ) {
345346 if (element instanceof CacheRRset ) {
346- CacheRRset crrset = (CacheRRset ) element ;
347+ @ SuppressWarnings ("unchecked" )
348+ CacheRRset <Record > crrset = (CacheRRset <Record >) element ;
347349 crrset .addRR (r );
348350 }
349351 }
@@ -355,8 +357,8 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
355357 * @param cred The credibility of these records
356358 * @see RRset
357359 */
358- public synchronized void
359- addRRset (RRset rrset , int cred ) {
360+ public synchronized < T extends Record > void
361+ addRRset (RRset < T > rrset , int cred ) {
360362 long ttl = rrset .getTTL ();
361363 Name name = rrset .getName ();
362364 int type = rrset .getType ();
@@ -368,11 +370,11 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
368370 if (element != null && element .compareCredibility (cred ) <= 0 )
369371 element = null ;
370372 if (element == null ) {
371- CacheRRset crrset ;
373+ CacheRRset < T > crrset ;
372374 if (rrset instanceof CacheRRset )
373- crrset = (CacheRRset ) rrset ;
375+ crrset = (CacheRRset < T > ) rrset ;
374376 else
375- crrset = new CacheRRset (rrset , cred , maxcache );
377+ crrset = new CacheRRset <> (rrset , cred , maxcache );
376378 addElement (name , crrset );
377379 }
378380 }
@@ -453,7 +455,7 @@ else if (isExact)
453455 continue ;
454456 if (element .compareCredibility (minCred ) < 0 )
455457 continue ;
456- sr .addRRset ((CacheRRset ) element );
458+ sr .addRRset ((CacheRRset <?> ) element );
457459 added ++;
458460 }
459461 /* There were positive entries */
@@ -518,11 +520,12 @@ else if (isExact)
518520 return lookup (name , type , minCred );
519521}
520522
521- private RRset []
523+ @ SuppressWarnings ("unchecked" )
524+ private <T extends Record > List <RRset <T >>
522525findRecords (Name name , int type , int minCred ) {
523526 SetResponse cr = lookupRecords (name , type , minCred );
524527 if (cr .isSuccessful ())
525- return cr .answers ();
528+ return ( List < RRset < T >>)( List ) cr .answers ();
526529 else
527530 return null ;
528531}
@@ -535,7 +538,7 @@ else if (isExact)
535538 * @return An array of RRsets, or null
536539 * @see Credibility
537540 */
538- public RRset []
541+ public < T extends Record > List < RRset < T >>
539542findRecords (Name name , int type ) {
540543 return findRecords (name , type , Credibility .NORMAL );
541544}
@@ -548,7 +551,7 @@ else if (isExact)
548551 * @return An array of RRsets, or null
549552 * @see Credibility
550553 */
551- public RRset []
554+ public < T extends Record > List < RRset < T >>
552555findAnyRecords (Name name , int type ) {
553556 return findRecords (name , type , Credibility .GLUE );
554557}
@@ -572,14 +575,12 @@ else if (isExact)
572575}
573576
574577private static void
575- markAdditional (RRset rrset , Set <Name > names ) {
578+ markAdditional (RRset <?> rrset , Set <Name > names ) {
576579 Record first = rrset .first ();
577580 if (first .getAdditionalName () == null )
578581 return ;
579582
580- Iterator <Record > it = rrset .rrs ();
581- while (it .hasNext ()) {
582- Record r = it .next ();
583+ for (Record r : rrset .rrs ()) {
583584 Name name = r .getAdditionalName ();
584585 if (name != null )
585586 names .add (name );
@@ -594,6 +595,7 @@ else if (isExact)
594595 * lookup, or null if nothing useful could be cached from the message.
595596 * @see Message
596597 */
598+ @ SuppressWarnings ("unchecked" )
597599public SetResponse
598600addMessage (Message in ) {
599601 boolean isAuth = in .getHeader ().getFlag (Flags .AA );
@@ -623,7 +625,7 @@ else if (isExact)
623625 additionalNames = new HashSet <>();
624626
625627 answers = in .getSectionRRsets (Section .ANSWER );
626- for (RRset answer : answers ) {
628+ for (RRset <?> answer : answers ) {
627629 if (answer .getDClass () != qclass )
628630 continue ;
629631 int type = answer .getType ();
@@ -664,14 +666,15 @@ else if (isExact)
664666 }
665667
666668 auth = in .getSectionRRsets (Section .AUTHORITY );
667- RRset soa = null , ns = null ;
668- for (RRset rset : auth ) {
669+ RRset <SOARecord > soa = null ;
670+ RRset <NSRecord > ns = null ;
671+ for (RRset <?> rset : auth ) {
669672 if (rset .getType () == Type .SOA &&
670673 curname .subdomain (rset .getName ()))
671- soa = rset ;
674+ soa = ( RRset < SOARecord >) rset ;
672675 else if (rset .getType () == Type .NS &&
673676 curname .subdomain (rset .getName ()))
674- ns = rset ;
677+ ns = ( RRset < NSRecord >) rset ;
675678 }
676679 if (!completed ) {
677680 /* This is a negative response or a referral. */
@@ -710,7 +713,7 @@ else if (rset.getType() == Type.NS &&
710713 }
711714
712715 addl = in .getSectionRRsets (Section .ADDITIONAL );
713- for (RRset rRset : addl ) {
716+ for (RRset <?> rRset : addl ) {
714717 int type = rRset .getType ();
715718 if (type != Type .A && type != Type .AAAA && type != Type .A6 )
716719 continue ;
0 commit comments