Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LinkedMap class #124

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5364b7f
feat: Implemented LinkedMap class
sweep-ai[bot] Oct 19, 2023
cddce6e
feat: Add LinkedMapTests.cls to test LinkedMap.cls
sweep-ai[bot] Oct 19, 2023
5182182
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 20, 2023
9e1ac71
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 23, 2023
d492faf
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 23, 2023
3b4313c
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 23, 2023
a9bcc39
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 23, 2023
aabd161
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 26, 2023
35618e9
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 27, 2023
1dbe37c
feat: Updated force-app/main/default/classes/Linke
sweep-ai[bot] Oct 28, 2023
c77b139
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 30, 2023
4552e09
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 30, 2023
6a4f781
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Oct 31, 2023
b2eb5de
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 2, 2023
e4b650a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 6, 2023
94c00b0
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 10, 2023
87fdd2b
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 13, 2023
5c864aa
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 16, 2023
af8c112
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 16, 2023
7a0086a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 16, 2023
186ac0a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 16, 2023
35ebb6a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Nov 20, 2023
6eff3dd
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 4, 2023
e1ce639
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 4, 2023
8e9f888
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 7, 2023
ef8b178
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 11, 2023
31d1c3c
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 12, 2023
6d57339
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 15, 2023
8d9bbbe
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Dec 18, 2023
7e2e11a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 1, 2024
0ea9981
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 2, 2024
3ab1dfa
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 4, 2024
fe5a78f
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 10, 2024
4f0eeb6
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 10, 2024
6eab7be
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 12, 2024
31c9732
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 18, 2024
d92fa66
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 29, 2024
af988fe
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 30, 2024
bf9165c
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Jan 31, 2024
893aa85
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 5, 2024
312d33c
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 6, 2024
f5759be
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 12, 2024
85fb829
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 14, 2024
e2a3f9f
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 14, 2024
a0da632
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 16, 2024
d43ae77
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 19, 2024
2f7cc3b
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 19, 2024
145147d
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 21, 2024
16c989f
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 26, 2024
cd77621
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Feb 26, 2024
702c6ef
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Mar 16, 2024
d4efec9
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 1, 2024
f9a0b89
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 3, 2024
d72f58c
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 3, 2024
0115e83
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 19, 2024
d2a3fb8
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 22, 2024
61f5d4a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 23, 2024
2dd22d6
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 24, 2024
a92f83a
Merge main into sweep/linked-map-implementation
sweep-ai[bot] Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions force-app/main/default/classes/LinkedMap.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class LinkedMap {
Fixed Show fixed Hide fixed
private Map<Set<String>, List<Object>> linkedMap;

public LinkedMap() {
Fixed Show fixed Hide fixed
this.linkedMap = new Map<Set<String>, List<Object>>();
}
Comment on lines +4 to +6

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment

public void put(Set<String> keys, List<Object> values) {
Fixed Show fixed Hide fixed
if (this.linkedMap.containsKey(keys)) {
this.linkedMap.get(keys).addAll(values);
} else {
this.linkedMap.put(keys, values);
}
}
Comment on lines +8 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The put method currently allows for duplicate values to be added to the list of values for a given key set. If this is not the intended behavior and you want to prevent duplicates, consider using a Set<Object> instead of a List<Object>. However, if maintaining the order of insertion is important, then the current implementation is fine.

Comment on lines +8 to +14

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment

public List<Object> get(Set<String> keys) {
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
return this.linkedMap.get(keys);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The get method returns null when the keys are not found in the map. It would be better to return an empty list instead to avoid potential NullPointerExceptions.

    public List<Object> get(Set<String> keys) {
-       return this.linkedMap.get(keys);
+       return this.linkedMap.getOrDefault(keys, new List<Object>());
    }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a thing.
Want to put a null-safe operator @codefriar ?

Copy link
Author

@sweep-ai sweep-ai bot Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Wrote Changes

Done.


public List<Object> remove(Set<String> keys) {
Fixed Show fixed Hide fixed
return this.linkedMap.remove(keys);
}
Comment on lines +20 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Similar to the get method, the remove method also returns null when the keys are not found in the map. Consider returning an empty list instead.

    public List<Object> remove(Set<String> keys) {
-       return this.linkedMap.remove(keys);
+       return this.linkedMap.remove(keys) != null ? this.linkedMap.remove(keys) : new List<Object>();
    }

Comment on lines +20 to +22

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment

public Boolean containsKey(Set<String> keys) {
Fixed Show fixed Hide fixed
return this.linkedMap.containsKey(keys);
}
Comment on lines +24 to +26

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment

public Set<Set<String>> keySet() {
Fixed Show fixed Hide fixed
return this.linkedMap.keySet();
}
Comment on lines +28 to +30

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment

public List<List<Object>> values() {
Fixed Show fixed Hide fixed
return this.linkedMap.values();
}
Comment on lines +32 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

In the values() method, you are returning the original list of values from the map. This could potentially allow outside code to modify the internal state of your LinkedMap object. To prevent this, consider returning a deep copy of the values.

- public List<List<Object>> values() {
-     return this.linkedMap.values();
- }
+ public List<List<Object>> values() {
+     List<List<Object>> deepCopyValues = new List<List<Object>>();
+     for (List<Object> valueList : this.linkedMap.values()) {
+         deepCopyValues.add(new List<Object>(valueList));
+     }
+     return deepCopyValues;
+ }

Comment on lines +32 to +34

Check warning

Code scanning / PMD

Missing ApexDoc comment Warning

Missing ApexDoc comment
}
50 changes: 50 additions & 0 deletions force-app/main/default/classes/LinkedMapTests.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@isTest
public class LinkedMapTests {
@isTest
static void testPut() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.get(new Set<String>{'key1'}), new List<Object>{'value1'});

map.put(new Set<String>{'key1'}, new List<Object>{'value2'});
System.assertEquals(map.get(new Set<String>{'key1'}), new List<Object>{'value1', 'value2'});
}

@isTest
static void testGet() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.get(new Set<String>{'key1'}), new List<Object>{'value1'});
System.assertEquals(map.get(new Set<String>{'key2'}), null);
}

@isTest
static void testRemove() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.remove(new Set<String>{'key1'}), new List<Object>{'value1'});
System.assertEquals(map.remove(new Set<String>{'key1'}), null);
}

@isTest
static void testContainsKey() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.containsKey(new Set<String>{'key1'}), true);
System.assertEquals(map.containsKey(new Set<String>{'key2'}), false);
}

@isTest
static void testKeySet() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.keySet(), new Set<Set<String>>{new Set<String>{'key1'}});
}

@isTest
static void testValues() {
LinkedMap map = new LinkedMap();
map.put(new Set<String>{'key1'}, new List<Object>{'value1'});
System.assertEquals(map.values(), new List<List<Object>>{new List<Object>{'value1'}});
}
}
Loading