Skip to content

Package: KommandoMitExceptionMitResultat

KommandoMitExceptionMitResultat

nameinstructionbranchcomplexitylinemethod
KommandoMitExceptionMitResultat()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
executeCommand()
M: 4 C: 6
60%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
getResultat()
M: 3 C: 6
67%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%

Coverage

1: package schnittstelle.kommandoArchitektur;
2:
3: /**
4: * Diese Kommandoklasse kapselt alle Kommandos mit Rückgabewert und möglicher auftretender exceptions.
5: *
6: * @param <T>
7: * Typ des Rückgabewerten
8: * @param <E>
9: * Typ der möglichen exceptions
10: */
11: public abstract class KommandoMitExceptionMitResultat<T, E extends Exception> extends Kommando {
12:         
13:         private T resultat;
14:         private E exception;
15:         
16:         @SuppressWarnings("unchecked")
17:         @Override
18:         protected void executeCommand() {
19:                 try {
20:                         this.resultat = this.doIt();
21:                 } catch (final Exception e) {
22:                         this.exception = (E) e; // TODO FIXME Art: unidentified; das kacke wie bei dem anderen Kommando hier, Warning muss suppressed
23:                         // werden, obwohl eigentlich nicht notwendig, da nichts anderes fliegen kann.
24:                 }
25:         }
26:         
27:         /**
28:          *
29:          * @return Object welches automatisch als Resultat gespeichert werden soll.
30:          * @throws E
31:          * Exception die auftreten kann.
32:          */
33:         protected abstract T doIt() throws E;
34:         
35:         /**
36:          * Gibt das Resultat des Kommandos zurück. Konnte das Kommando wegen einer Exception nicht ausgeführt werden, wird
37:          * diese geworfen.
38:          *
39:          * @return Resultat des Kommandos.
40:          * @throws E
41:          * Exception falls diese beim Ausführen des Kommandos aufgetreten ist.
42:          */
43:         public T getResultat() throws E {
44:                 // TODO Art: Feature request; um Nebenläufigkeit zu ermöglichen, muss hier das "executed" geprüft werden.
45:•                if (this.exception != null) {
46:                         throw this.exception;
47:                 }
48:                 return this.resultat;
49:         }
50:         
51: }