diff --git a/uebung07/src/oop/ch05/mensa/AccountCard.java b/uebung07/src/oop/ch05/mensa/AccountCard.java index b74f3a4..6b98523 100644 --- a/uebung07/src/oop/ch05/mensa/AccountCard.java +++ b/uebung07/src/oop/ch05/mensa/AccountCard.java @@ -5,15 +5,15 @@ import oop.ch05.secured.SecuredContent; import oop.ch05.secured.SecurityClient; public class AccountCard extends MensaCard { - private final SecuredContent account; + private final SecuredContent account; public AccountCard(String key, String account, int password) { super(key, Color.white); - this.account = new SecuredContent(password, account); + this.account = new SecuredContent<>(password, account); } public String getAccount() { - return (String) account.getContent(); + return account.getContent(); } public void setAccount(SecurityClient client, String account) throws AuthorizationException { diff --git a/uebung07/src/oop/ch05/mensa/CashCard.java b/uebung07/src/oop/ch05/mensa/CashCard.java index 810f6d0..36fa7ea 100644 --- a/uebung07/src/oop/ch05/mensa/CashCard.java +++ b/uebung07/src/oop/ch05/mensa/CashCard.java @@ -4,17 +4,17 @@ import oop.ch05.secured.AuthorizationException; import oop.ch05.secured.SecuredContent; public class CashCard extends MensaCard { - private final SecuredContent balance; + private final SecuredContent balance; public CashCard(String key, Color color, int password) { super(key, color); - balance = new SecuredContent(password, 0); + balance = new SecuredContent<>(password, 0); if (color != Color.blue && color != Color.green) throw new IllegalArgumentException("Invalid CashCard color " + color); } public int getBalance() { - return (Integer) balance.getContent(); + return balance.getContent(); } void deposit(VendingMachine client, int cents) diff --git a/uebung07/src/oop/ch05/secured/SecuredContent.java b/uebung07/src/oop/ch05/secured/SecuredContent.java index 1426aaf..445b4ee 100644 --- a/uebung07/src/oop/ch05/secured/SecuredContent.java +++ b/uebung07/src/oop/ch05/secured/SecuredContent.java @@ -7,13 +7,14 @@ import java.util.Random; * by a challenge-response approach. The content may be read at any time, but * only authorized clients are allowed to modify the contents. * + * @param the type of the actual secured content * @author Mark Minas */ -public class SecuredContent { +public class SecuredContent { /** * The actual, secured content */ - private Object content; + private E content; /** * A random number generator used for generating challenges. */ @@ -30,7 +31,7 @@ public class SecuredContent { * challenge. * @param content the contained content */ - public SecuredContent(int password, Object content) { + public SecuredContent(int password, E content) { this.password = password; this.content = content; } @@ -39,7 +40,7 @@ public class SecuredContent { * Returns the contained contents. There is no authorization necessary for * reading the contents. */ - public Object getContent() { + public E getContent() { return content; } @@ -52,12 +53,12 @@ public class SecuredContent { * @param content The new contained contents * @throws AuthorizationException if the specified client cannot authorize himself */ - public void setContent(SecurityClient client, Object content) + public void setContent(SecurityClient client, E content) throws AuthorizationException { final int challenge = nextChallenge(); if (client.challengeResponse(challenge) != requiredResponse(challenge)) throw new AuthorizationException(client - + " is not authorized to access contents."); + + " is not authorized to access contents."); this.content = content; }