for (int j = i+1; j < list.size(); j++)
{
entry = list.get(j);
- if(entry.getWord().equals(newEntry.getWord()))
+ if(entry.getKey().equals(newEntry.getKey()))
{
list.remove(j);
break;
return this;
}
- if (entry.getWord().equals(newEntry.getWord()))
+ if (entry.getKey().equals(newEntry.getKey()))
oldPosition = i;
}
{
Entry entry = this.entries[i];
- if (seenWords.contains(entry.getWord()))
- throw new IllegalArgumentException("Invalid Ranking: Multiple occurrences of word -> " + entry.getWord());
+ if (seenWords.contains(entry.getKey()))
+ throw new IllegalArgumentException("Invalid Ranking: Multiple occurrences of word -> " + entry.getKey());
if (entry.getCounter() > lowesCounting)
throw new IllegalArgumentException("Invalid Ranking: Entries are not sorted correctly");
- seenWords.add(entry.getWord());
+ seenWords.add(entry.getKey());
lowesCounting = entry.getCounter();
}
Set<String> otherWordsWithCurrentCount = new HashSet<>();
Entry myEntry = entries[i];
long currentCount = myEntry.getCounter();
- myWordsWithCurrentCount.add(myEntry.getWord());
+ myWordsWithCurrentCount.add(myEntry.getKey());
while (true)
{
Entry otherEntry = other.entries[i];
if (otherEntry.getCounter() != currentCount)
return false;
- otherWordsWithCurrentCount.add(otherEntry.getWord());
+ otherWordsWithCurrentCount.add(otherEntry.getKey());
if (++i >= entries.length)
return myWordsWithCurrentCount.equals(otherWordsWithCurrentCount);
myEntry = entries[i];
myWordsWithCurrentCount.clear();
otherWordsWithCurrentCount.clear();
}
- myWordsWithCurrentCount.add(myEntry.getWord());
+ myWordsWithCurrentCount.add(myEntry.getKey());
}
}
class TestData
{
+ static final String TYPE_COUNTER = "COUNTER";
+
static final TestUser PETER = TestUser.of("peter");
static final TestUser KLAUS = TestUser.of("klaus");
private static final KeyValue<TestWord, TestCounter>[] INPUT_MESSAGES = new KeyValue[]
{
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Hallo"),
- TestCounter.of(PETER.getUser(),"Hallo",1)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Hallo"),
+ TestCounter.of("Hallo",1)),
new KeyValue<>(
- TestWord.of(KLAUS.getUser(),"Müsch"),
- TestCounter.of(KLAUS.getUser(),"Müsch",1)),
+ TestWord.of(TYPE_COUNTER, KLAUS.getUser(),"Müsch"),
+ TestCounter.of("Müsch",1)),
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Welt"),
- TestCounter.of(PETER.getUser(),"Welt",1)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Welt"),
+ TestCounter.of("Welt",1)),
new KeyValue<>(
- TestWord.of(KLAUS.getUser(),"Müsch"),
- TestCounter.of(KLAUS.getUser(),"Müsch",2)),
+ TestWord.of(TYPE_COUNTER, KLAUS.getUser(),"Müsch"),
+ TestCounter.of("Müsch",2)),
new KeyValue<>(
- TestWord.of(KLAUS.getUser(),"s"),
- TestCounter.of(KLAUS.getUser(),"s",1)),
+ TestWord.of(TYPE_COUNTER, KLAUS.getUser(),"s"),
+ TestCounter.of("s",1)),
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Boäh"),
- TestCounter.of(PETER.getUser(),"Boäh",1)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Boäh"),
+ TestCounter.of("Boäh",1)),
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Welt"),
- TestCounter.of(PETER.getUser(),"Welt",2)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Welt"),
+ TestCounter.of("Welt",2)),
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Boäh"),
- TestCounter.of(PETER.getUser(),"Boäh",2)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Boäh"),
+ TestCounter.of("Boäh",2)),
new KeyValue<>(
- TestWord.of(KLAUS.getUser(),"s"),
- TestCounter.of(KLAUS.getUser(),"s",2)),
+ TestWord.of(TYPE_COUNTER, KLAUS.getUser(),"s"),
+ TestCounter.of("s",2)),
new KeyValue<>(
- TestWord.of(PETER.getUser(),"Boäh"),
- TestCounter.of(PETER.getUser(),"Boäh",3)),
+ TestWord.of(TYPE_COUNTER, PETER.getUser(),"Boäh"),
+ TestCounter.of("Boäh",3)),
new KeyValue<>(
- TestWord.of(KLAUS.getUser(),"s"),
- TestCounter.of(KLAUS.getUser(),"s",3)),
+ TestWord.of(TYPE_COUNTER, KLAUS.getUser(),"s"),
+ TestCounter.of("s",3)),
};
static void assertExpectedMessages(MultiValueMap<TestUser, TestRanking> receivedMessages)
return Arrays
.stream(entries)
.map(entry -> TestEntry.of(
- entry.getWord(),
+ entry.getKey(),
entry.getCounter() == null
? -1l
: entry.getCounter()))