From c8a318944aae0ff9944974f4e7cb6c7f2277b65a Mon Sep 17 00:00:00 2001 From: Javan Thomas Date: Mon, 29 Aug 2016 23:19:55 -0400 Subject: [PATCH] Addresses issue #5 by correcting bogus counting --- .idea/codeStyleSettings.xml | 9 +++++++++ .idea/misc.xml | 2 +- .../flashy/services/FlashCardServiceImpl.java | 10 ++++------ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .idea/codeStyleSettings.xml diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..5dfbdec --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 164b970..02642ab 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java index 5b660e9..651ef7c 100644 --- a/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java +++ b/src/main/java/com/teamtreehouse/flashy/services/FlashCardServiceImpl.java @@ -1,8 +1,9 @@ package com.teamtreehouse.flashy.services; +import static java.util.stream.Collectors.toList; + import com.teamtreehouse.flashy.domain.FlashCard; import com.teamtreehouse.flashy.repositories.FlashCardRepository; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,8 +13,6 @@ import java.util.Map; import java.util.Random; -import static java.util.stream.Collectors.toList; - @Service public class FlashCardServiceImpl implements FlashCardService { private FlashCardRepository flashCardRepository; @@ -62,10 +61,9 @@ public FlashCard getNextFlashCardBasedOnViews(Map idToViewCounts) { continue; } Long lowestScore = idToViewCounts.get(leastViewedId); - if (entry.getValue() >= lowestScore) { - break; + if (entry.getValue() < lowestScore) { + leastViewedId = entry.getKey(); } - leastViewedId = entry.getKey(); } return flashCardRepository.findOne(leastViewedId); }