Skip to content

Commit 3140084

Browse files
mguarnacciamaibin
authored andcommitted
BAEL-3486 (eugenp#8458)
* Hexagonal architecture: a quick and practical example * BAEL-3486 commit * Formatting issue solved * Update code for consistency with article
1 parent 0dfecf0 commit 3140084

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GreedyAlgorithm(SocialConnector sc) {
1515
this.fp = new FollowersPath();
1616
}
1717

18-
public long findMostFollowersPath(String account) throws Exception {
18+
public long findMostFollowersPath(String account) {
1919
long max = 0;
2020
SocialUser toFollow = null;
2121

@@ -31,12 +31,8 @@ public long findMostFollowersPath(String account) throws Exception {
3131
if (currentLevel < maxLevel - 1) {
3232
currentLevel++;
3333
max += findMostFollowersPath(toFollow.getUsername());
34-
//fp.addFollower(toFollow.getUsername(), max);
35-
//fp.addCount(max);
3634
return max;
3735
} else {
38-
//fp.addFollower(toFollow.getUsername(), max);
39-
//fp.addCount(max);
4036
return max;
4137
}
4238
}

algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ public NonGreedyAlgorithm(SocialConnector tc, int level) {
1313
this.tc = tc;
1414
this.currentLevel = level;
1515
}
16-
17-
18-
public long findMostFollowersPath(String account) throws Exception {
16+
17+
public long findMostFollowersPath(String account) {
1918
List<SocialUser> followers = tc.getFollowers(account);
2019
long total = currentLevel > 0 ? followers.size() : 0;
2120

algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public boolean switchCounter() {
2020
return this.isCounterEnabled;
2121
}
2222

23-
public List<SocialUser> getFollowers(String account) throws Exception {
23+
public List<SocialUser> getFollowers(String account) {
2424
if (counter < 0)
25-
throw new Exception ("API limit reached");
25+
throw new IllegalStateException ("API limit reached");
2626
else {
2727
if(this.isCounterEnabled) counter--;
2828
for(SocialUser user : users) {

algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ private SocialConnector prepareNetwork() {
3535
}
3636

3737
@Test
38-
public void greedyAlgorithmTest() throws Exception {
38+
public void greedyAlgorithmTest() {
3939
GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork());
4040
assertEquals(ga.findMostFollowersPath("root"), 5);
4141
}
4242

4343
@Test
44-
public void nongreedyAlgorithmTest() throws Exception {
44+
public void nongreedyAlgorithmTest() {
4545
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0);
46-
Assertions.assertThrows(Exception.class, () -> {
46+
Assertions.assertThrows(IllegalStateException.class, () -> {
4747
nga.findMostFollowersPath("root");
4848
});
4949
}
5050

5151
@Test
52-
public void nongreedyAlgorithmUnboundedTest() throws Exception {
52+
public void nongreedyAlgorithmUnboundedTest() {
5353
SocialConnector sc = prepareNetwork();
5454
sc.switchCounter();
5555
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0);

0 commit comments

Comments
 (0)