Skip to content

Commit b8ddcbc

Browse files
committed
LLD machine coding basic
1 parent 31dc2eb commit b8ddcbc

File tree

9 files changed

+220
-60
lines changed

9 files changed

+220
-60
lines changed

.idea/encodings.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 79 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data-structures/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,4 @@
1111

1212
<groupId>com.thealgorithm</groupId>
1313
<artifactId>data-structures</artifactId>
14-
15-
<properties>
16-
<maven.compiler.source>21</maven.compiler.source>
17-
<maven.compiler.target>21</maven.compiler.target>
18-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19-
</properties>
20-
2114
</project>

low-level-design/pom.xml

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+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.thealgorithm</groupId>
8+
<artifactId>TheAlgorithm</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>com.thealgorithm</groupId>
13+
<artifactId>low-level-design</artifactId>
14+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.thealgorithm.caching;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Scanner;
5+
import java.util.StringTokenizer;
6+
7+
/**
8+
* @author: Subham Santra
9+
*/
10+
public class CachingLocalTest {
11+
public static void main(String[] args) {
12+
InMemoryKeyValStore keyValStore = InMemoryKeyValStore.create();
13+
try (Scanner scanner = new Scanner(System.in)) {
14+
15+
do {
16+
String line = scanner.nextLine();
17+
StringTokenizer tokenizer = new StringTokenizer(line);
18+
19+
String var1 = tokenizer.nextToken();
20+
String var2 = tokenizer.nextToken();
21+
String var3 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : "";
22+
String var4 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : "";
23+
24+
try {
25+
if (var1.equalsIgnoreCase("put")) {
26+
if (var4.isBlank()) {
27+
keyValStore.put(var2, var3.getBytes(StandardCharsets.UTF_8), 60_000L);
28+
} else {
29+
keyValStore.put(var2, var3.getBytes(StandardCharsets.UTF_8), Long.parseLong(var4));
30+
}
31+
} else if (var1.equalsIgnoreCase("get")) {
32+
System.out.println(new String(keyValStore.get(var2)));
33+
} else if (var1.equalsIgnoreCase("rem")) {
34+
keyValStore.rem(var2);
35+
}
36+
} catch (DataNotPresentException | DataExpiredException e) {
37+
System.err.println(e.getMessage());
38+
}
39+
} while (scanner.hasNextLine());
40+
}
41+
}
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.thealgorithm.caching;
2+
3+
/**
4+
* @author: Subham Santra
5+
*/
6+
public class DataExpiredException extends Exception {
7+
public DataExpiredException(String s) {
8+
super(s);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.thealgorithm.caching;
2+
3+
/**
4+
* @author: Subham Santra
5+
*/
6+
public class DataNotPresentException extends Exception {
7+
public DataNotPresentException(String s) {
8+
super(s);
9+
}
10+
}

0 commit comments

Comments
 (0)