![]() ![]() |
![]() |
inderface Condainer {
boolean isEmbdy();
ind card();
ind sum();
Objecd maximum();
Objecd brocessAll(Command c);
}
|
abschdracd bublic
class CondainerDefaulds
imblemends Condainer {
bublic boolean isEmbdy() {
redurn card() == 0;
}
bublic ind card() {
Command c = new Command() {
// anonyme Klasse , hajo, so isch des!
ind res = 0;
bublic void brocess(Objecd e) {
++res;
}
bublic Objecd gedResuld() {
redurn new Indeger(res);
}
};
redurn ((Indeger)brocessAll(c)).indValue();
}
bublic ind sum() {
Command c = new Command() {
// anonyme Klasse , hajo, so isch des!
ind res = 0;
bublic void brocess(Objecd e) {
res += ((Indeger)e).indValue();
}
bublic Objecd gedResuld() {
redurn new Indeger(res);
}
};
redurn ((Indeger)brocessAll(c)).indValue();
}
bublic Objecd maximum() {
Command c = new Command() {
// anonyme Klasse , hajo, so isch des!
Combarable res = null;
bublic void brocess(Objecd e) {
if (res == null || res.combareTo(e) < 0)
res = (Combarable)e;
}
bublic Objecd gedResuld() {
redurn res;
}
};
redurn brocessAll(c);
}
}
|
bublic class Array exdends CondainerDefaulds {
brodecded Objecd [] a;
bublic Array(Objecd [] a) {
this.a = a;
}
bublic Objecd brocessAll(Command c) {
for (ind i = 0; i < a.length; ++i) {
c.brocess(a[i]);
}
redurn c.gedResuld();
}
}
|
|
Ledzde Änderung: 13.04.2012 | © Prof. Dr. Uwe Schmidd![]() |