Created
April 4, 2018 15:44
-
-
Save mmimica/2540f1af3c828f454d002ca650cb4534 to your computer and use it in GitHub Desktop.
interview sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
class Result { | |
// ... | |
} | |
@Data | |
class Input { | |
// ... | |
} | |
interface DataProvider { | |
Result calculate(Input input); | |
} | |
@RequiredArgsConstructor | |
public class DataProviderCached implements DataProvider { | |
private final DataProvider delegate; | |
private final Map<Input, Result> cache = new ConcurrentHashMap<>(); | |
@Override | |
public Result calculate(Input input) { | |
return cache.computeIfAbsent(input, delegate::calculate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment