Skip to content

Commit 235471f

Browse files
authored
Merge pull request #2 from devxadarsh/work
Updated capacity method to handle negative input
2 parents 538fb49 + 3007f2d commit 235471f

File tree

1 file changed

+5
-0
lines changed
  • src/main/java/com/thealgorithms/datastructures/caches

1 file changed

+5
-0
lines changed

src/main/java/com/thealgorithms/datastructures/caches/ARCCache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ public class ARCCache<K, V> {
2727

2828
/**
2929
* This constructor initializes an ARCCache object with the given capacity and initializes other necessary fields
30+
* @param capacity the initial capacity of the cache
31+
* @throws IllegalArgumentException if the capacity is negative
3032
*/
3133
public ARCCache(int capacity) {
34+
if (capacity < 0) {
35+
throw new IllegalArgumentException("Capacity cannot be negative");
36+
}
3237
this.cache = new LinkedHashMap<>();
3338
this.usageCounts = new LinkedHashMap<>();
3439
this.t1Capacity = capacity / 2; // Capacity for the t1 cache

0 commit comments

Comments
 (0)