|
| 1 | +package com.bobocode.basics; |
| 2 | + |
| 3 | +import java.util.Map; |
| 4 | + |
| 5 | +/** |
| 6 | + * {@link HeterogeneousMaxHolder} is a multi-type container that holds maximum values per each type. It's kind of a |
| 7 | + * key/value map, where the key is a type and the value is the maximum among all values of this type that were put. |
| 8 | + * <p> |
| 9 | + * It's based on the {@link Map} and provides an API that allows to put a value by type, and get a max value by type. |
| 10 | + */ |
| 11 | +public class HeterogeneousMaxHolder { |
| 12 | + |
| 13 | + /** |
| 14 | + * A method put stores a provided value by its type, if the value is greater than the current maximum. In other words, the logic |
| 15 | + * of this method makes sure that only max value is stored and everything else is ignored. |
| 16 | + * <p> |
| 17 | + * If the current max value is less than a provided one, or if it's null, then a provided value gets stored and the old |
| 18 | + * max is returned. Otherwise, nothing new is added, and the provided value is returned. |
| 19 | + * <p> |
| 20 | + * So technically, this method always stored the greater value and returns the smaller one. |
| 21 | + * |
| 22 | + * @param key a provided value type |
| 23 | + * @param value a value to put |
| 24 | + * @param <T> value type parameter |
| 25 | + * @return a smaller value among the provided value and the current maximum |
| 26 | + */ |
| 27 | + // todo: implement a method according to javadoc |
| 28 | + |
| 29 | + /** |
| 30 | + * An overloaded method put implements the same logic using a custom comparator. A given comparator is wrapped with |
| 31 | + * a null-safe comparator, considering null smaller than any non-null object. |
| 32 | + * |
| 33 | + * All arguments must not be null. |
| 34 | + * |
| 35 | + * @param key a provided value type |
| 36 | + * @param value a value to put |
| 37 | + * @param comparator a custom comparator for the given type |
| 38 | + * @param <T> value type parameter |
| 39 | + * @return a smaller value among the provided value and the current maximum |
| 40 | + */ |
| 41 | + // todo: implement a method according to javadoc |
| 42 | + |
| 43 | + /** |
| 44 | + * A method getMax returns a max value by the given type. If no value is stored by this type, then it returns null. |
| 45 | + * |
| 46 | + * @param key a provided value type |
| 47 | + * @param <T> value type parameter |
| 48 | + * @return current max value or null |
| 49 | + */ |
| 50 | + // todo: implement a method according to javadoc |
| 51 | +} |
0 commit comments