Not passing the last requirement! I suspect the problem is in the FileStorageStrategy class but I can't find how/why. Can someone give me a small hint?
package com.codegym.task.task33.task3310;
import com.codegym.task.task33.task3310.strategy.*;
import com.codegym.task.task33.task3310.tests.FunctionalTest;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
public class Solution {
public static Set<Long> getIds(Shortener shortener, Set<String> strings){
Set<Long> set = new HashSet<>();
for (String s : strings){
set.add(shortener.getId(s));
}
return set;
}
public static Set<String> getStrings(Shortener shortener, Set<Long> keys){
Set<String> set = new HashSet<>();
for (Long id : keys){
set.add(shortener.getString(id));
}
return set;
}
public static void testStrategy(StorageStrategy strategy, long elementsNumber){
Helper.printMessage(strategy.getClass().getSimpleName());
Set<String> test = new HashSet<>();
for (int i=0;i<elementsNumber;i++){
test.add(Helper.generateRandomString());
}
Shortener shortener = new Shortener(strategy);
long startTime = new Date().getTime();
for (String s : test){
shortener.getId(s);
}
long endTime = new Date().getTime();
long timeElapsed = endTime - startTime;
Helper.printMessage(timeElapsed+"");
Set<Long> idTest = new HashSet<>();
for (String s : test){
idTest.add(shortener.getId(s));
}
long startTime2 = new Date().getTime();
for (Long id : idTest){
shortener.getString(id);
}
long endTime2 = new Date().getTime();
long timeElapsed2 = endTime2 - startTime2;
Helper.printMessage(timeElapsed2+"");
Set<String> stringTest = new HashSet<>();
for (Long id : idTest){
stringTest.add(shortener.getString(id));
}
if (stringTest.equals(test)) Helper.printMessage("The test passed.");
else if (!stringTest.equals(test)) Helper.printMessage("The test failed.");
}
public static void main(String[] args) {
//FunctionalTest functionalTest = new FunctionalTest();
//functionalTest.testHashMapStorageStrategy();
//functionalTest.testOurHashMapStorageStrategy();
//functionalTest.testFileStorageStrategy();
//functionalTest.testHashBiMapStorageStrategy();
//functionalTest.testOurHashBiMapStorageStrategy();
//functionalTest.testDualHashBidiMapStorageStrategy();
//testStrategy(new OurHashBiMapStorageStrategy(), 100);
//testStrategy(new HashBiMapStorageStrategy(), 100);
//testStrategy(new FileStorageStrategy(), 100);
//testStrategy(new HashBiMapStorageStrategy(), 100);
//testStrategy(new OurHashBiMapStorageStrategy(), 100);
//testStrategy(new DualHashBidiMapStorageStrategy(), 100);
}
}