I know the task will not pass due to missing Date objects. Although I thought it will meet at least most of the requirements but it doesn't, even a single one.
Anyone can tell me what's wrong? And how did you use
Date class
to measure the time? Because obviouslySystem.currentMillis();
would be easier.. package com.codegym.task.task33.task3310;
import com.codegym.task.task33.task3310.strategy.HashMapStorageStrategy;
import com.codegym.task.task33.task3310.strategy.StorageStrategy;
import java.sql.SQLOutput;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class Solution {
public static void main(String[] args) {
new Solution().testStrategy(new HashMapStorageStrategy(), 10000);
}
public Set<Long> getIds(Shortener shortener, Set<String> strings) {
return strings.stream().map(shortener::getId).collect(Collectors.toSet());
}
public Set<String> getStrings(Shortener shortener, Set<Long> keys) {
return keys.stream().map(shortener::getString).collect(Collectors.toSet());
}
public void testStrategy(StorageStrategy strategy, long elementsNumber) {
Set<String> elements = new HashSet<>();
System.out.println(strategy.getClass().getName().substring(strategy.getClass().getName().lastIndexOf(".") + 1));
for(int i = 0; i < elementsNumber; i++){
elements.add(Helper.generateRandomString());
}
Shortener shortener = new Shortener(strategy);
Set<Long> ids = getIds(shortener, elements);
Set<String> strings = getStrings(shortener, ids);
if(elements.containsAll(strings))
System.out.println("The test passed.");
else
System.out.println("The test failed.");
}
}