Skip to content

Commit e0907bb

Browse files
author
Bill Bensing
committed
Initial commit
0 parents  commit e0907bb

20 files changed

Lines changed: 1266 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
.idea/

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The Kernel
2+

kernel.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />

pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
7+
<groupId>com.wb3tech</groupId>
8+
<artifactId>kernel</artifactId>
9+
<version>0.1.0</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.target>1.13</maven.compiler.target>
14+
<maven.compiler.source>1.13</maven.compiler.source>
15+
<maven.compiler.release>13</maven.compiler.release>
16+
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
17+
<maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
18+
<junit.jupiter.version>5.6.0-M1</junit.jupiter.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.junit.jupiter</groupId>
24+
<artifactId>junit-jupiter</artifactId>
25+
<version>${junit.jupiter.version}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
<version>${maven.compiler.plugin.version}</version>
36+
<configuration>
37+
<source>${maven.compiler.source}</source>
38+
<target>${maven.compiler.target}</target>
39+
<release>${maven.compiler.release}</release>
40+
</configuration>
41+
</plugin>
42+
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-surefire-plugin</artifactId>
46+
<version>${maven.surefire.plugin.version}</version>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
51+
<distributionManagement>
52+
<repository>
53+
<id>github</id>
54+
<name>GitHub WB3Tech Kernel - Apache Maven Packages</name>
55+
<url>https://maven.pkg.github.com/WB3Tech-Kernel-Java/com.wb3tech.kernel</url>
56+
</repository>
57+
</distributionManagement>
58+
59+
60+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.wb3tech.kernel;
2+
3+
public abstract class Entity implements Identifiable {
4+
5+
private Identity id;
6+
7+
protected void setId(Identity id) {
8+
if (id == null) { throw new NullPointerException("The identity is null."); }
9+
if (id.isInvalid()) { throw new IllegalStateException("The identity is not valid."); }
10+
this.id = id.copy();
11+
}
12+
13+
public Identity getId() {
14+
return this.id.copy();
15+
}
16+
17+
protected void assignNewIdentity() {
18+
this.id = Identity.New();
19+
}
20+
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.wb3tech.kernel;
2+
3+
public interface EventDispatcher<Event> {
4+
void Dispatch(Event event);
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.wb3tech.kernel;
2+
3+
public interface Identifiable {
4+
5+
Identity getId();
6+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.wb3tech.kernel;
2+
3+
import java.util.UUID;
4+
5+
/***
6+
* Forms the basis for any identifiable entity for the WB3Tech kernel.
7+
*/
8+
public class Identity {
9+
10+
private UUID id;
11+
12+
Identity(UUID id) {
13+
if (id == null) { throw new NullPointerException("Identity UUID cannot be null."); }
14+
this.id = id;
15+
}
16+
17+
/***
18+
* Returns new instance with a value of 00000000-0000-0000-0000-000000000000.
19+
* @return Identity
20+
*/
21+
public static Identity Default() {
22+
return new Identity(new UUID(0,0));
23+
}
24+
25+
/***
26+
* Returns new instance with a random value.
27+
* @return Identity
28+
*/
29+
public static Identity New() {
30+
return new Identity(UUID.randomUUID());
31+
}
32+
33+
/***
34+
* Returns instance with a supplied UUID.
35+
* @param id UUID
36+
* @return Identity
37+
*/
38+
public static Identity New(UUID id) {
39+
return new Identity(id);
40+
}
41+
42+
public boolean isValid() {
43+
return !this.id.toString().equals("00000000-0000-0000-0000-000000000000");
44+
}
45+
46+
public boolean isInvalid() {
47+
return !this.isValid();
48+
}
49+
50+
public boolean equals(Identity identity) {
51+
if (this.isInvalid()) { throw new IllegalStateException("Cannot compare, current instance is in invalid."); }
52+
if (identity.isInvalid()) { throw new IllegalStateException("Cannot compare, instance being compared is invalid."); }
53+
return this.id.toString().equals(identity.toString());
54+
}
55+
56+
public String toString() {
57+
return this.id.toString();
58+
}
59+
60+
public UUID value() {
61+
return this.id;
62+
}
63+
64+
protected Identity copy() {
65+
return new Identity(this.id);
66+
}
67+
68+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.wb3tech.kernel;
2+
3+
public interface RequestHandler<Request> {
4+
void Handle(Request request);
5+
}

0 commit comments

Comments
 (0)