Skip to content

Commit 2c3a22d

Browse files
author
Koushik Sai
committed
Applied clang-format
1 parent b9914f2 commit 2c3a22d

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/ImmutableHashMap.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public V get(K key) {
6363
Node<K, V> current = table[index];
6464

6565
while (current != null) {
66-
if ((key == null && current.key == null)
67-
|| (key != null && key.equals(current.key))) {
66+
if ((key == null && current.key == null) || (key != null && key.equals(current.key))) {
6867
return current.value;
6968
}
7069
current = current.next;
@@ -95,9 +94,7 @@ public int size() {
9594
* Computes hash index for a given key.
9695
*/
9796
private int hash(K key) {
98-
return key == null
99-
? 0
100-
: (key.hashCode() & Integer.MAX_VALUE) % table.length;
97+
return key == null ? 0 : (key.hashCode() & Integer.MAX_VALUE) % table.length;
10198
}
10299

103100
/**

src/test/java/com/thealgorithms/datastructures/hashmap/hashing/ImmutableHashMapTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertNull;
66
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
78
import org.junit.jupiter.api.Test;
89

910
class ImmutableHashMapTest {
1011

1112
@Test
1213
void testEmptyMap() {
13-
ImmutableHashMap<String, Integer> map
14-
= ImmutableHashMap.<String, Integer>empty();
14+
ImmutableHashMap<String, Integer> map = ImmutableHashMap.<String, Integer>empty();
1515

1616
assertEquals(0, map.size());
1717
assertNull(map.get("A"));
1818
}
1919

2020
@Test
2121
void testPutDoesNotModifyOriginalMap() {
22-
ImmutableHashMap<String, Integer> map1
23-
= ImmutableHashMap.<String, Integer>empty();
22+
ImmutableHashMap<String, Integer> map1 = ImmutableHashMap.<String, Integer>empty();
2423

2524
ImmutableHashMap<String, Integer> map2 = map1.put("A", 1);
2625

@@ -32,10 +31,7 @@ void testPutDoesNotModifyOriginalMap() {
3231

3332
@Test
3433
void testMultiplePuts() {
35-
ImmutableHashMap<String, Integer> map
36-
= ImmutableHashMap.<String, Integer>empty()
37-
.put("A", 1)
38-
.put("B", 2);
34+
ImmutableHashMap<String, Integer> map = ImmutableHashMap.<String, Integer>empty().put("A", 1).put("B", 2);
3935

4036
assertEquals(2, map.size());
4137
assertEquals(1, map.get("A"));
@@ -44,19 +40,15 @@ void testMultiplePuts() {
4440

4541
@Test
4642
void testContainsKey() {
47-
ImmutableHashMap<String, Integer> map
48-
= ImmutableHashMap.<String, Integer>empty()
49-
.put("X", 100);
43+
ImmutableHashMap<String, Integer> map = ImmutableHashMap.<String, Integer>empty().put("X", 100);
5044

5145
assertTrue(map.containsKey("X"));
5246
assertFalse(map.containsKey("Y"));
5347
}
5448

5549
@Test
5650
void testNullKey() {
57-
ImmutableHashMap<String, Integer> map
58-
= ImmutableHashMap.<String, Integer>empty()
59-
.put(null, 50);
51+
ImmutableHashMap<String, Integer> map = ImmutableHashMap.<String, Integer>empty().put(null, 50);
6052

6153
assertEquals(50, map.get(null));
6254
}

0 commit comments

Comments
 (0)