Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 930a4d9

Browse files
committed
GP-146 - new Heterogeneous Max Holder Exercise
* add HeterogeneousMaxHolder with javadocs * add HeterogeneousMaxHolderTest.java that provides test * add README.MD * update pom.xml
1 parent ccdd947 commit 930a4d9

File tree

5 files changed

+547
-0
lines changed

5 files changed

+547
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# <img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=50/>Heterogeneous Max Holder
2+
#### Improve your generics-related skills implementing a multi-type max holder container 💪
3+
4+
### Objectives
5+
* create a container class that uses *a type token*
6+
* declare a generic type parameter that is `Comparable`
7+
* implement a generic method put that stores max values by its type ✅
8+
* overload a generic method put with a custom `Comparator`
9+
* implement a generic method getMax that retrieves a max value by its type ✅
10+
* wrap a comparator instance to make it null-safe ✅
11+
12+
---
13+
#### 🆕 First time here? – [See Introduction](https://github.com/bobocode-projects/java-fundamentals-exercises/tree/main/0-0-intro#introduction)
14+
#### ➡️ Have any feedback? – [Please fill the form ](https://forms.gle/u6kHcecFuzxV232LA)
15+
16+
##
17+
<div align="center"><img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/animation/GitHub%20Star_3.gif" height=50/></div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>1-0-java-basics</artifactId>
7+
<groupId>com.bobocode</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>1-3-2-heterogeneous-max-holder</artifactId>
13+
14+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /