BAEL-3486 (#8458)
* Hexagonal architecture: a quick and practical example * BAEL-3486 commit * Formatting issue solved * Update code for consistency with article
This commit is contained in:
parent
e11c779a6c
commit
63397e4daa
|
@ -15,7 +15,7 @@ public class GreedyAlgorithm {
|
|||
this.fp = new FollowersPath();
|
||||
}
|
||||
|
||||
public long findMostFollowersPath(String account) throws Exception {
|
||||
public long findMostFollowersPath(String account) {
|
||||
long max = 0;
|
||||
SocialUser toFollow = null;
|
||||
|
||||
|
@ -31,12 +31,8 @@ public class GreedyAlgorithm {
|
|||
if (currentLevel < maxLevel - 1) {
|
||||
currentLevel++;
|
||||
max += findMostFollowersPath(toFollow.getUsername());
|
||||
//fp.addFollower(toFollow.getUsername(), max);
|
||||
//fp.addCount(max);
|
||||
return max;
|
||||
} else {
|
||||
//fp.addFollower(toFollow.getUsername(), max);
|
||||
//fp.addCount(max);
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ public class NonGreedyAlgorithm {
|
|||
this.currentLevel = level;
|
||||
}
|
||||
|
||||
|
||||
public long findMostFollowersPath(String account) throws Exception {
|
||||
public long findMostFollowersPath(String account) {
|
||||
List<SocialUser> followers = tc.getFollowers(account);
|
||||
long total = currentLevel > 0 ? followers.size() : 0;
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ public class SocialConnector {
|
|||
return this.isCounterEnabled;
|
||||
}
|
||||
|
||||
public List<SocialUser> getFollowers(String account) throws Exception {
|
||||
public List<SocialUser> getFollowers(String account) {
|
||||
if (counter < 0)
|
||||
throw new Exception ("API limit reached");
|
||||
throw new IllegalStateException ("API limit reached");
|
||||
else {
|
||||
if(this.isCounterEnabled) counter--;
|
||||
for(SocialUser user : users) {
|
||||
|
|
|
@ -35,21 +35,21 @@ public class GreedyAlgorithmUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void greedyAlgorithmTest() throws Exception {
|
||||
public void greedyAlgorithmTest() {
|
||||
GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork());
|
||||
assertEquals(ga.findMostFollowersPath("root"), 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nongreedyAlgorithmTest() throws Exception {
|
||||
public void nongreedyAlgorithmTest() {
|
||||
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0);
|
||||
Assertions.assertThrows(Exception.class, () -> {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
nga.findMostFollowersPath("root");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nongreedyAlgorithmUnboundedTest() throws Exception {
|
||||
public void nongreedyAlgorithmUnboundedTest() {
|
||||
SocialConnector sc = prepareNetwork();
|
||||
sc.switchCounter();
|
||||
NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0);
|
||||
|
|
Loading…
Reference in New Issue