Renamed MessageIdGenerator to IdGenerator, added IdGeneratorRequest

Also removed src/test/resources from pom.xml.
This commit is contained in:
Kai S. K. Engelbart 2020-01-28 17:01:02 +01:00
parent e5c67b859b
commit 40f6d41fff
6 changed files with 35 additions and 15 deletions

View File

@ -24,10 +24,5 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -18,6 +18,11 @@
<build> <build>
<finalName>envoy-common</finalName> <finalName>envoy-common</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -1,32 +1,39 @@
package envoy.data; package envoy.data;
import java.io.Serializable;
/** /**
* Generates increasing IDs between two numbers.<br> * Generates increasing IDs between two numbers.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>MessageIdGenerator.java</strong><br> * File: <strong>IdGenerator.java</strong><br>
* Created: <strong>31.12.2019</strong><br> * Created: <strong>31.12.2019</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public class MessageIdGenerator { public class IdGenerator implements Serializable {
private final long end; private final long end;
private long current; private long current;
private static final long serialVersionUID = -1517378307055845147L;
/** /**
* Creates an instance of {@link MessageIdGenerator}. * Creates an instance of {@link IdGenerator}.
* *
* @param begin the first ID * @param begin the first ID
* @param end the last ID * @param end the last ID
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public MessageIdGenerator(long begin, long end) { public IdGenerator(long begin, long end) {
current = begin; current = begin;
this.end = end; this.end = end;
} }
@Override
public String toString() { return String.format("MessageIdGenerator[current=%d,end=%d]", current, end); }
/** /**
* @return {@code true} if there are unused IDs remaining * @return {@code true} if there are unused IDs remaining
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha

View File

@ -24,7 +24,7 @@ public class Message implements Serializable {
* *
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public static enum MessageStatus { public enum MessageStatus {
/** /**
* is selected, if a message was sent but not received by the server yet. * is selected, if a message was sent but not received by the server yet.
@ -77,7 +77,7 @@ public class Message implements Serializable {
this.id = id; this.id = id;
this.senderId = senderId; this.senderId = senderId;
this.recipientId = recipientId; this.recipientId = recipientId;
this.creationDate = date; creationDate = date;
this.text = text; this.text = text;
this.attachment = attachment; this.attachment = attachment;
this.status = status; this.status = status;
@ -186,6 +186,6 @@ public class Message implements Serializable {
*/ */
public void setStatus(MessageStatus status) { public void setStatus(MessageStatus status) {
if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time"); if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time");
else this.status = status; this.status = status;
} }
} }

View File

@ -14,6 +14,5 @@ public interface Event<T> {
/** /**
* @return the data associated with this event * @return the data associated with this event
*/ */
T get(); default T get() { return null; }
} }

View File

@ -0,0 +1,14 @@
package envoy.event;
/**
* Signifies to the server that the client needs a new
* {@link envoy.data.IdGenerator} instance.<br>
* <br>
* Project: <strong>envoy-common</strong><br>
* File: <strong>IdGeneratorRequest.java</strong><br>
* Created: <strong>28 Jan 2020</strong><br>
*
* @author Kai S. K. Engelbart
*/
public class IdGeneratorRequest implements Event<Void> {
}