Adapter Mode: Converts the interface of a class into another interface that the customer expects. Classes with incompatible interfaces on the adapter can work seamlessly.
The project compares the old code, the iteration uses enumeration
Java code
public class Enumerationtest {public
enumeration Getenum (Vector list) {
enumeration e = List.element S (); return
e;
}
}
The project compares the old code, the iteration uses iterator
Java code
public class Iteratortest {public
iterator Getiter (Collection list) {
iterator = list. Iterator (); Return
iterator
}
}
Enumeration convert to iterator adapter
Java code
public class Enumerationiterator implements iterator {public
enumeration enumeration;
Ationiterator (Enumeration enumeration) {
This.enumeration = enumeration;
}
@Override public
b Oolean Hasnext () {
//TODO auto-generated method stub return
enumeration.hasmoreelements ();
}
@Override Public
Object Next () {
//TODO auto-generated a stub return
Enumeration.nextele ment ();
}
Because enumeration has no associated deletion method, it throws an exception
@Deprecated public
void Remove () {
//TODO auto-generated approach St UB
throw new RuntimeException ();
}
}