3
3
import com .bobocode .data .Accounts ;
4
4
import com .bobocode .model .Account ;
5
5
import com .bobocode .model .CreditAccount ;
6
+ import com .bobocode .optionals .exception .AccountNotFoundException ;
7
+ import com .bobocode .optionals .function .AccountProvider ;
8
+ import com .bobocode .optionals .function .AccountService ;
9
+ import com .bobocode .optionals .function .CreditAccountProvider ;
10
+ import com .bobocode .util .ExerciseNotCompletedException ;
6
11
7
12
import javax .annotation .Nonnull ;
8
13
import javax .annotation .Nullable ;
11
16
import java .util .Optional ;
12
17
import java .util .OptionalDouble ;
13
18
19
+ /**
20
+ * {@link CrazyOptionals} is an exercise class. Each method represents some operation with a {@link Account} and
21
+ * should be implemented using Optional API. Every method that is not implemented yet throws
22
+ * {@link ExerciseNotCompletedException}.
23
+ * <p>
24
+ * TODO: remove exception and implement each method of this class using Optional API
25
+ */
14
26
public class CrazyOptionals {
15
27
16
28
/**
@@ -20,7 +32,7 @@ public class CrazyOptionals {
20
32
* @return optional object that holds text
21
33
*/
22
34
public static Optional <String > optionalOfString (@ Nullable String text ) {
23
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
35
+ throw new ExerciseNotCompletedException ( );
24
36
}
25
37
26
38
/**
@@ -30,7 +42,7 @@ public static Optional<String> optionalOfString(@Nullable String text) {
30
42
* @param amount money to deposit
31
43
*/
32
44
public static void deposit (AccountProvider accountProvider , BigDecimal amount ) {
33
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
45
+ throw new ExerciseNotCompletedException ( );
34
46
}
35
47
36
48
/**
@@ -40,7 +52,7 @@ public static void deposit(AccountProvider accountProvider, BigDecimal amount) {
40
52
* @return optional object that holds account
41
53
*/
42
54
public static Optional <Account > optionalOfAccount (@ Nonnull Account account ) {
43
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
55
+ throw new ExerciseNotCompletedException ( );
44
56
}
45
57
46
58
/**
@@ -52,7 +64,7 @@ public static Optional<Account> optionalOfAccount(@Nonnull Account account) {
52
64
* @return account from provider or defaultAccount
53
65
*/
54
66
public static Account getAccount (AccountProvider accountProvider , Account defaultAccount ) {
55
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
67
+ throw new ExerciseNotCompletedException ( );
56
68
}
57
69
58
70
/**
@@ -63,7 +75,7 @@ public static Account getAccount(AccountProvider accountProvider, Account defaul
63
75
* @param accountService
64
76
*/
65
77
public static void processAccount (AccountProvider accountProvider , AccountService accountService ) {
66
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
78
+ throw new ExerciseNotCompletedException ( );
67
79
}
68
80
69
81
/**
@@ -74,7 +86,7 @@ public static void processAccount(AccountProvider accountProvider, AccountServic
74
86
* @return provided or generated account
75
87
*/
76
88
public static Account getOrGenerateAccount (AccountProvider accountProvider ) {
77
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
89
+ throw new ExerciseNotCompletedException ( );
78
90
}
79
91
80
92
/**
@@ -84,7 +96,7 @@ public static Account getOrGenerateAccount(AccountProvider accountProvider) {
84
96
* @return optional balance
85
97
*/
86
98
public static Optional <BigDecimal > retrieveBalance (AccountProvider accountProvider ) {
87
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
99
+ throw new ExerciseNotCompletedException ( );
88
100
}
89
101
90
102
/**
@@ -95,7 +107,7 @@ public static Optional<BigDecimal> retrieveBalance(AccountProvider accountProvid
95
107
* @return provided account
96
108
*/
97
109
public static Account getAccount (AccountProvider accountProvider ) {
98
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
110
+ throw new ExerciseNotCompletedException ( );
99
111
}
100
112
101
113
/**
@@ -105,7 +117,7 @@ public static Account getAccount(AccountProvider accountProvider) {
105
117
* @return optional credit balance
106
118
*/
107
119
public static Optional <BigDecimal > retrieveCreditBalance (CreditAccountProvider accountProvider ) {
108
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
120
+ throw new ExerciseNotCompletedException ( );
109
121
}
110
122
111
123
@@ -117,7 +129,7 @@ public static Optional<BigDecimal> retrieveCreditBalance(CreditAccountProvider a
117
129
* @return optional gmail account
118
130
*/
119
131
public static Optional <Account > retrieveAccountGmail (AccountProvider accountProvider ) {
120
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
132
+ throw new ExerciseNotCompletedException ( );
121
133
}
122
134
123
135
/**
@@ -130,7 +142,7 @@ public static Optional<Account> retrieveAccountGmail(AccountProvider accountProv
130
142
* @return account got from either accountProvider or fallbackProvider
131
143
*/
132
144
public static Account getAccountWithFallback (AccountProvider accountProvider , AccountProvider fallbackProvider ) {
133
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
145
+ throw new ExerciseNotCompletedException ( );
134
146
}
135
147
136
148
/**
@@ -141,7 +153,7 @@ public static Account getAccountWithFallback(AccountProvider accountProvider, Ac
141
153
* @return account with the highest balance
142
154
*/
143
155
public static Account getAccountWithMaxBalance (List <Account > accounts ) {
144
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
156
+ throw new ExerciseNotCompletedException ( );
145
157
}
146
158
147
159
/**
@@ -151,7 +163,7 @@ public static Account getAccountWithMaxBalance(List<Account> accounts) {
151
163
* @return the lowest balance values
152
164
*/
153
165
public static OptionalDouble findMinBalanceValue (List <Account > accounts ) {
154
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
166
+ throw new ExerciseNotCompletedException ( );
155
167
}
156
168
157
169
/**
@@ -161,7 +173,7 @@ public static OptionalDouble findMinBalanceValue(List<Account> accounts) {
161
173
* @param accountService
162
174
*/
163
175
public static void processAccountWithMaxBalance (List <Account > accounts , AccountService accountService ) {
164
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
176
+ throw new ExerciseNotCompletedException ( );
165
177
}
166
178
167
179
/**
@@ -171,7 +183,7 @@ public static void processAccountWithMaxBalance(List<Account> accounts, AccountS
171
183
* @return total credit balance
172
184
*/
173
185
public static double calculateTotalCreditBalance (List <CreditAccount > accounts ) {
174
- throw new UnsupportedOperationException ( "Some people say that method does not work until you implement it" );
186
+ throw new ExerciseNotCompletedException ( );
175
187
}
176
188
}
177
189
0 commit comments