summaryrefslogtreecommitdiff
path: root/src/main/java/core/time
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-06 08:02:52 +0300
committerPaul Buetow <paul@buetow.org>2025-06-06 08:02:52 +0300
commit1d99762c7965d351510cfb5e08eac25e48d96038 (patch)
treef469493e911878ab9055ccf0494211bf9015922d /src/main/java/core/time
parent4d35597bd92607c4d194686e20b125044506c79a (diff)
Modernize project structure, update Maven config, move sources, add logging config, update README and .gitignore
Diffstat (limited to 'src/main/java/core/time')
-rw-r--r--src/main/java/core/time/VSLamportTime.java50
-rw-r--r--src/main/java/core/time/VSTime.java22
-rw-r--r--src/main/java/core/time/VSVectorTime.java96
3 files changed, 168 insertions, 0 deletions
diff --git a/src/main/java/core/time/VSLamportTime.java b/src/main/java/core/time/VSLamportTime.java
new file mode 100644
index 0000000..be1226b
--- /dev/null
+++ b/src/main/java/core/time/VSLamportTime.java
@@ -0,0 +1,50 @@
+package core.time;
+
+/**
+ * The class VSLamportTime, defines how the lamport timestamps are represented.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSLamportTime implements VSTime {
+ /** Specified the global time of the lamport timestamp. It's used for
+ * correct painting position in the simulator canvas paint area.
+ */
+ private long globalTime;
+
+ /** Specified the process' local lamport time. */
+ private long lamportTime;
+
+ /**
+ * A simple constructor.
+ *
+ * @param globalTime The global time.
+ * @param lamportTime The local lamport time.
+ */
+ public VSLamportTime(long globalTime, long lamportTime) {
+ this.globalTime = globalTime;
+ this.lamportTime = lamportTime;
+ }
+
+ /* (non-Javadoc)
+ * @see core.time.VSTime#getGlobalTime()
+ */
+ public long getGlobalTime() {
+ return globalTime;
+ }
+
+ /**
+ * Gets the lamport time.
+ *
+ * @return The process' local lamport time
+ */
+ public long getLamportTime() {
+ return lamportTime;
+ }
+
+ /* (non-Javadoc)
+ * @see core.time.VSTime#toString()
+ */
+ public String toString() {
+ return "(" + lamportTime + ")";
+ }
+}
diff --git a/src/main/java/core/time/VSTime.java b/src/main/java/core/time/VSTime.java
new file mode 100644
index 0000000..d46e0e4
--- /dev/null
+++ b/src/main/java/core/time/VSTime.java
@@ -0,0 +1,22 @@
+package core.time;
+
+/**
+ * This interface is a guidline for general time format classes.
+ *
+ * @author Paul C. Buetow
+ */
+public interface VSTime {
+ /**
+ * Gets the global time.
+ *
+ * @return The global time
+ */
+ public long getGlobalTime();
+
+ /**
+ * Returns a string representation.
+ *
+ * @return The representation of the implementing object as a string
+ */
+ public String toString();
+}
diff --git a/src/main/java/core/time/VSVectorTime.java b/src/main/java/core/time/VSVectorTime.java
new file mode 100644
index 0000000..4e63b3c
--- /dev/null
+++ b/src/main/java/core/time/VSVectorTime.java
@@ -0,0 +1,96 @@
+package core.time;
+
+import java.util.ArrayList;
+
+/**
+ * The class VSVectorTime, defined how the vector timestamps are represented.
+ *
+ * @author Paul C. Buetow
+ */
+public class VSVectorTime extends ArrayList<Long> implements VSTime {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** The global time. */
+ private long globalTime;
+
+ /**
+ * Instantiates a new vector time.
+ *
+ * @param globalTime the global time
+ */
+ public VSVectorTime(long globalTime) {
+ this.globalTime = globalTime;
+ }
+
+ /**
+ * To long array.
+ *
+ * @return the long[]
+ */
+ public long[] toLongArray() {
+ final int size = super.size();
+ final long[] arr = new long[size];
+
+ for (int i = 0; i < size; ++i)
+ arr[i] = super.get(i).longValue();
+
+ return arr;
+ }
+
+ /**
+ * Sets the global time.
+ *
+ * @param globalTime the new global time
+ */
+ public void setGlobalTime(long globalTime) {
+ this.globalTime = globalTime;
+ }
+
+ /* (non-Javadoc)
+ * @see core.time.VSTime#getGlobalTime()
+ */
+ public long getGlobalTime() {
+ return globalTime;
+ }
+
+ /**
+ * Gets the copy.
+ *
+ * @return the copy
+ */
+ public VSVectorTime getCopy() {
+ final VSVectorTime vectorTime = new VSVectorTime(globalTime);
+ final int size = super.size();
+
+ for (int i = 0; i < size; ++i)
+ vectorTime.add(super.get(i));
+
+ return vectorTime;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#toString()
+ */
+ public String toString() {
+ final int size = super.size();
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append("(");
+
+ for (int i = 0; i < size-1; ++i)
+ buffer.append(super.get(i)+",");
+ buffer.append(super.get(size-1)+")");
+
+ return buffer.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#get(int)
+ */
+ public Long get(int index) {
+ if (index >= super.size())
+ return Long.valueOf(0);
+
+ return super.get(index);
+ }
+}