-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathjava_test_file.java
More file actions
32 lines (30 loc) · 1.05 KB
/
java_test_file.java
File metadata and controls
32 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Test {
/**
* Calculates the sum of two integers.
*
* @param a The first integer to be added.
* @param b The second integer to be added.
* @return The sum of the two integers.
*/
public static int a_plus_b(Integer a, Integer b) {
return a + b;
}
/**
* Compares two objects based on their keys mapped by a specified key mapping function.
*
* @param keymap A function that maps an object to a comparable value.
* @param a The first object to be compared.
* @param b The second object to be compared.
* @return An integer representing the comparison result: -1 if the key of 'a' is less than the key of 'b',
* 1 if the key of 'a' is greater than the key of 'b', and 0 if the keys are equal.
*/
public static int a_plus_b(Function<Object, Comparable> keymap, object a, Object b) {
if (keymap(a) < keymap(b)) {
return -1;
} else if (keymap(a) > keymap(b)) {
return 1;
} else {
return 0;
}
}
}