Reformat all source files with new formatter
This commit is contained in:
		@@ -3,8 +3,8 @@ package envoy.data;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This interface should be used for any type supposed to be a {@link Message}
 | 
			
		||||
 * attachment (i.e. images or sound).
 | 
			
		||||
 * This interface should be used for any type supposed to be a {@link Message} attachment (i.e.
 | 
			
		||||
 * images or sound).
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 
 | 
			
		||||
@@ -9,15 +9,13 @@ import java.util.stream.Collectors;
 | 
			
		||||
import envoy.util.EnvoyLog;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Manages all application settings that are set during application startup by
 | 
			
		||||
 * either loading them from the {@link Properties} file (default values)
 | 
			
		||||
 * {@code client.properties} or parsing them from the command line arguments of
 | 
			
		||||
 * the application.
 | 
			
		||||
 * Manages all application settings that are set during application startup by either loading them
 | 
			
		||||
 * from the {@link Properties} file (default values) {@code client.properties} or parsing them from
 | 
			
		||||
 * the command line arguments of the application.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * All items inside the {@code Config} are supposed to either be supplied over
 | 
			
		||||
 * default value or over command line argument. Developers that fail to provide
 | 
			
		||||
 * default values will be greeted with an error message the next time they try
 | 
			
		||||
 * to start Envoy...
 | 
			
		||||
 * All items inside the {@code Config} are supposed to either be supplied over default value or over
 | 
			
		||||
 * command line argument. Developers that fail to provide default values will be greeted with an
 | 
			
		||||
 * error message the next time they try to start Envoy...
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.1-beta
 | 
			
		||||
@@ -44,15 +42,14 @@ public class Config {
 | 
			
		||||
	 */
 | 
			
		||||
	private void load(Properties properties) {
 | 
			
		||||
		items.entrySet().stream().filter(e -> properties.containsKey(e.getKey()))
 | 
			
		||||
				.forEach(e -> e.getValue().parse(properties.getProperty(e.getKey())));
 | 
			
		||||
			.forEach(e -> e.getValue().parse(properties.getProperty(e.getKey())));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Parses config items from an array of command line arguments.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param args the command line arguments to parse
 | 
			
		||||
	 * @throws IllegalStateException if a malformed command line argument has been
 | 
			
		||||
	 *                               supplied
 | 
			
		||||
	 * @throws IllegalStateException if a malformed command line argument has been supplied
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private void load(String[] args) {
 | 
			
		||||
@@ -61,7 +58,7 @@ public class Config {
 | 
			
		||||
				if (args[i].startsWith("--")) {
 | 
			
		||||
					if (args[i].length() == 2)
 | 
			
		||||
						throw new IllegalStateException(
 | 
			
		||||
								"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
							"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
					final String commandLong = args[i].substring(2);
 | 
			
		||||
					if (item.getCommandLong().equals(commandLong)) {
 | 
			
		||||
						item.parse(args[++i]);
 | 
			
		||||
@@ -70,7 +67,7 @@ public class Config {
 | 
			
		||||
				} else if (args[i].startsWith("-")) {
 | 
			
		||||
					if (args[i].length() == 1)
 | 
			
		||||
						throw new IllegalStateException(
 | 
			
		||||
								"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
							"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
					final String commandShort = args[i].substring(1);
 | 
			
		||||
					if (item.getCommandShort().equals(commandShort)) {
 | 
			
		||||
						item.parse(args[++i]);
 | 
			
		||||
@@ -78,35 +75,36 @@ public class Config {
 | 
			
		||||
					}
 | 
			
		||||
				} else
 | 
			
		||||
					throw new IllegalStateException(
 | 
			
		||||
							"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
						"Malformed command line argument at position " + i + ": " + args[i]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Supplies default values from the given .properties file and parses the
 | 
			
		||||
	 * configuration from an array of command line arguments.
 | 
			
		||||
	 * Supplies default values from the given .properties file and parses the configuration from an
 | 
			
		||||
	 * array of command line arguments.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param declaringClass     the class calling this method
 | 
			
		||||
	 * @param propertiesFilePath the path to where the .properties file can be found
 | 
			
		||||
	 *                           - will be only the file name if it is located
 | 
			
		||||
	 *                           directly inside the {@code src/main/resources}
 | 
			
		||||
	 *                           folder
 | 
			
		||||
	 * @param propertiesFilePath the path to where the .properties file can be found - will be only
 | 
			
		||||
	 *                           the file name if it is located directly inside the
 | 
			
		||||
	 *                           {@code src/main/resources} folder
 | 
			
		||||
	 * @param args               the command line arguments to parse
 | 
			
		||||
	 * @throws IllegalStateException if this method is getting called again or if a
 | 
			
		||||
	 *                               malformed command line argument has been
 | 
			
		||||
	 *                               supplied
 | 
			
		||||
	 * @throws IllegalStateException if this method is getting called again or if a malformed
 | 
			
		||||
	 *                               command line argument has been supplied
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void loadAll(Class<?> declaringClass, String propertiesFilePath, String[] args) {
 | 
			
		||||
		if (modificationDisabled)
 | 
			
		||||
			throw new IllegalStateException("Cannot change config after isInitialized has been called");
 | 
			
		||||
			throw new IllegalStateException(
 | 
			
		||||
				"Cannot change config after isInitialized has been called");
 | 
			
		||||
 | 
			
		||||
		// Load the defaults from the given .properties file first
 | 
			
		||||
		final var properties = new Properties();
 | 
			
		||||
		try {
 | 
			
		||||
			properties.load(declaringClass.getClassLoader().getResourceAsStream(propertiesFilePath));
 | 
			
		||||
			properties
 | 
			
		||||
				.load(declaringClass.getClassLoader().getResourceAsStream(propertiesFilePath));
 | 
			
		||||
		} catch (final IOException e) {
 | 
			
		||||
			EnvoyLog.getLogger(Config.class).log(Level.SEVERE, "An error occurred when reading in the configuration: ",
 | 
			
		||||
					e);
 | 
			
		||||
			EnvoyLog.getLogger(Config.class).log(Level.SEVERE,
 | 
			
		||||
				"An error occurred when reading in the configuration: ",
 | 
			
		||||
				e);
 | 
			
		||||
		}
 | 
			
		||||
		load(properties);
 | 
			
		||||
 | 
			
		||||
@@ -122,13 +120,13 @@ public class Config {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @throws IllegalStateException if a {@link ConfigItem} has not been
 | 
			
		||||
	 *                               initialized
 | 
			
		||||
	 * @throws IllegalStateException if a {@link ConfigItem} has not been initialized
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private void isInitialized() {
 | 
			
		||||
		String uninitialized = items.values().stream().filter(c -> c.get() == null).map(ConfigItem::getCommandLong).collect(Collectors.joining(", "));
 | 
			
		||||
		if(!uninitialized.isEmpty())
 | 
			
		||||
		String uninitialized = items.values().stream().filter(c -> c.get() == null)
 | 
			
		||||
			.map(ConfigItem::getCommandLong).collect(Collectors.joining(", "));
 | 
			
		||||
		if (!uninitialized.isEmpty())
 | 
			
		||||
			throw new IllegalStateException("Config items uninitialized: " + uninitialized);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -148,11 +146,11 @@ public class Config {
 | 
			
		||||
	 * @param <T>           the type of the {@link ConfigItem}
 | 
			
		||||
	 * @param commandName   the key for this config item as well as its long name
 | 
			
		||||
	 * @param commandShort  the abbreviation of this config item
 | 
			
		||||
	 * @param parseFunction the {@code Function<String, T>} that parses the value
 | 
			
		||||
	 *                      from a string
 | 
			
		||||
	 * @param parseFunction the {@code Function<String, T>} that parses the value from a string
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	protected <T> void put(String commandName, String commandShort, Function<String, T> parseFunction) {
 | 
			
		||||
	protected <T> void put(String commandName, String commandShort,
 | 
			
		||||
		Function<String, T> parseFunction) {
 | 
			
		||||
		items.put(commandName, new ConfigItem<>(commandName, commandShort, parseFunction));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -160,17 +158,13 @@ public class Config {
 | 
			
		||||
	 * @return the directory in which all local files are saves
 | 
			
		||||
	 * @since Envoy Client v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public File getHomeDirectory() {
 | 
			
		||||
		return (File) items.get("homeDirectory").get();
 | 
			
		||||
	}
 | 
			
		||||
	public File getHomeDirectory() { return (File) items.get("homeDirectory").get(); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the minimal {@link Level} to log inside the log file
 | 
			
		||||
	 * @since Envoy Client v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public Level getFileLevelBarrier() {
 | 
			
		||||
		return (Level) items.get("fileLevelBarrier").get();
 | 
			
		||||
	}
 | 
			
		||||
	public Level getFileLevelBarrier() { return (Level) items.get("fileLevelBarrier").get(); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the minimal {@link Level} to log inside the console
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,8 @@ package envoy.data;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Contains a single {@link Config} value as well as the corresponding command
 | 
			
		||||
 * line arguments and its default value.
 | 
			
		||||
 * Contains a single {@link Config} value as well as the corresponding command line arguments and
 | 
			
		||||
 * its default value.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * All {@code ConfigItem}s are automatically mandatory.
 | 
			
		||||
 *
 | 
			
		||||
@@ -24,8 +24,7 @@ public final class ConfigItem<T> {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param commandLong   the long command line argument to set this value
 | 
			
		||||
	 * @param commandShort  the short command line argument to set this value
 | 
			
		||||
	 * @param parseFunction the {@code Function<String, T>} that parses the value
 | 
			
		||||
	 *                      from a string
 | 
			
		||||
	 * @param parseFunction the {@code Function<String, T>} that parses the value from a string
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public ConfigItem(String commandLong, String commandShort, Function<String, T> parseFunction) {
 | 
			
		||||
@@ -40,18 +39,18 @@ public final class ConfigItem<T> {
 | 
			
		||||
	 * @param input the string to parse from
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void parse(String input) { value = parseFunction.apply(input); }
 | 
			
		||||
	public void parse(String input) {
 | 
			
		||||
		value = parseFunction.apply(input);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return The long command line argument to set the value of this
 | 
			
		||||
	 *         {@link ConfigItem}
 | 
			
		||||
	 * @return The long command line argument to set the value of this {@link ConfigItem}
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public String getCommandLong() { return commandLong; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return The short command line argument to set the value of this
 | 
			
		||||
	 *         {@link ConfigItem}
 | 
			
		||||
	 * @return The short command line argument to set the value of this {@link ConfigItem}
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public String getCommandShort() { return commandShort; }
 | 
			
		||||
@@ -60,7 +59,9 @@ public final class ConfigItem<T> {
 | 
			
		||||
	 * @return the value of this {@link ConfigItem}
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public T get() { return value; }
 | 
			
		||||
	public T get() {
 | 
			
		||||
		return value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param value the value to set
 | 
			
		||||
 
 | 
			
		||||
@@ -53,23 +53,27 @@ public abstract class Contact implements Serializable {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Provides a hash code based on the ID of this contact.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public final int hashCode() { return Objects.hash(id); }
 | 
			
		||||
	public final int hashCode() {
 | 
			
		||||
		return Objects.hash(id);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Tests equality to another object. If that object is a contact as well,
 | 
			
		||||
	 * equality is determined by the ID.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * Tests equality to another object. If that object is a contact as well, equality is determined
 | 
			
		||||
	 * by the ID.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param obj the object to test for equality to this contact
 | 
			
		||||
	 * @return {code true} if both objects are contacts and have identical IDs
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public final boolean equals(Object obj) {
 | 
			
		||||
		if (this == obj) return true;
 | 
			
		||||
		if (!(obj instanceof Contact)) return false;
 | 
			
		||||
		if (this == obj)
 | 
			
		||||
			return true;
 | 
			
		||||
		if (!(obj instanceof Contact))
 | 
			
		||||
			return false;
 | 
			
		||||
		return id == ((Contact) obj).id;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,9 @@ public final class Group extends Contact {
 | 
			
		||||
	 * @param name the name of this group
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public Group(long id, String name) { this(id, name, new HashSet<User>()); }
 | 
			
		||||
	public Group(long id, String name) {
 | 
			
		||||
		this(id, name, new HashSet<User>());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of a {@link Group}.
 | 
			
		||||
@@ -28,10 +30,14 @@ public final class Group extends Contact {
 | 
			
		||||
	 * @param members all members that should be preinitialized
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public Group(long id, String name, Set<User> members) { super(id, name, members); }
 | 
			
		||||
	public Group(long id, String name, Set<User> members) {
 | 
			
		||||
		super(id, name, members);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("Group[id=%d,name=%s,%d member(s)]", id, name, contacts.size()); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("Group[id=%d,name=%s,%d member(s)]", id, name, contacts.size());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void readObject(ObjectInputStream inputStream) throws Exception {
 | 
			
		||||
		inputStream.defaultReadObject();
 | 
			
		||||
 
 | 
			
		||||
@@ -14,11 +14,9 @@ public final class GroupMessage extends Message {
 | 
			
		||||
	private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link GroupMessage} with values for all of its properties. The
 | 
			
		||||
	 * use
 | 
			
		||||
	 * of this constructor is only intended for the {@link MessageBuilder} class, as
 | 
			
		||||
	 * this class provides {@code null} checks and default values for all
 | 
			
		||||
	 * properties.
 | 
			
		||||
	 * Initializes a {@link GroupMessage} with values for all of its properties. The use of this
 | 
			
		||||
	 * constructor is only intended for the {@link MessageBuilder} class, as this class provides
 | 
			
		||||
	 * {@code null} checks and default values for all properties.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id             unique ID
 | 
			
		||||
	 * @param senderID       the ID of the user who sends the message
 | 
			
		||||
@@ -28,16 +26,18 @@ public final class GroupMessage extends Message {
 | 
			
		||||
	 * @param readDate       the read date of the message
 | 
			
		||||
	 * @param text           the text content of the message
 | 
			
		||||
	 * @param attachment     the attachment of the message, if present
 | 
			
		||||
	 * @param status         the current {@link Message.MessageStatus} of the
 | 
			
		||||
	 *                       message
 | 
			
		||||
	 * @param status         the current {@link Message.MessageStatus} of the message
 | 
			
		||||
	 * @param forwarded      whether this message was forwarded
 | 
			
		||||
	 * @param memberStatuses a map of all members and their status according to this
 | 
			
		||||
	 *                       {@link GroupMessage}
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	GroupMessage(long id, long senderID, long groupID, Instant creationDate, Instant receivedDate, Instant readDate, String text,
 | 
			
		||||
			Attachment attachment, MessageStatus status, boolean forwarded, Map<Long, MessageStatus> memberStatuses) {
 | 
			
		||||
		super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
 | 
			
		||||
	GroupMessage(long id, long senderID, long groupID, Instant creationDate, Instant receivedDate,
 | 
			
		||||
		Instant readDate, String text,
 | 
			
		||||
		Attachment attachment, MessageStatus status, boolean forwarded,
 | 
			
		||||
		Map<Long, MessageStatus> memberStatuses) {
 | 
			
		||||
		super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status,
 | 
			
		||||
			forwarded);
 | 
			
		||||
		this.memberStatuses = memberStatuses;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -30,20 +30,25 @@ public final class IDGenerator implements IEvent, Serializable {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("IDGenerator[current=%d,end=%d]", current, end); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("IDGenerator[current=%d,end=%d]", current, end);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return {@code true} if there are unused IDs remaining
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean hasNext() { return current < end; }
 | 
			
		||||
	public boolean hasNext() {
 | 
			
		||||
		return current < end;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the next ID
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public long next() {
 | 
			
		||||
		if (!hasNext()) throw new IllegalStateException("All IDs have been used");
 | 
			
		||||
		if (!hasNext())
 | 
			
		||||
			throw new IllegalStateException("All IDs have been used");
 | 
			
		||||
		return current++;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,11 +4,9 @@ import java.io.Serializable;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Contains a {@link User}'s login / registration information as well as the
 | 
			
		||||
 * client version.
 | 
			
		||||
 * Contains a {@link User}'s login / registration information as well as the client version.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * If the authentication is performed with a token, the token is stored instead
 | 
			
		||||
 * of the password.
 | 
			
		||||
 * If the authentication is performed with a token, the token is stored instead of the password.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.2-alpha
 | 
			
		||||
@@ -21,8 +19,9 @@ public final class LoginCredentials implements Serializable {
 | 
			
		||||
 | 
			
		||||
	private static final long serialVersionUID = 4;
 | 
			
		||||
 | 
			
		||||
	private LoginCredentials(String identifier, String password, boolean registration, boolean token, boolean requestToken, String clientVersion,
 | 
			
		||||
			Instant lastSync) {
 | 
			
		||||
	private LoginCredentials(String identifier, String password, boolean registration,
 | 
			
		||||
		boolean token, boolean requestToken, String clientVersion,
 | 
			
		||||
		Instant lastSync) {
 | 
			
		||||
		this.identifier		= identifier;
 | 
			
		||||
		this.password		= password;
 | 
			
		||||
		this.registration	= registration;
 | 
			
		||||
@@ -43,8 +42,10 @@ public final class LoginCredentials implements Serializable {
 | 
			
		||||
	 * @return the created login credentials
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static LoginCredentials login(String identifier, String password, boolean requestToken, String clientVersion, Instant lastSync) {
 | 
			
		||||
		return new LoginCredentials(identifier, password, false, false, requestToken, clientVersion, lastSync);
 | 
			
		||||
	public static LoginCredentials login(String identifier, String password, boolean requestToken,
 | 
			
		||||
		String clientVersion, Instant lastSync) {
 | 
			
		||||
		return new LoginCredentials(identifier, password, false, false, requestToken, clientVersion,
 | 
			
		||||
			lastSync);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -57,7 +58,8 @@ public final class LoginCredentials implements Serializable {
 | 
			
		||||
	 * @return the created login credentials
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static LoginCredentials loginWithToken(String identifier, String token, String clientVersion, Instant lastSync) {
 | 
			
		||||
	public static LoginCredentials loginWithToken(String identifier, String token,
 | 
			
		||||
		String clientVersion, Instant lastSync) {
 | 
			
		||||
		return new LoginCredentials(identifier, token, false, true, false, clientVersion, lastSync);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -72,19 +74,22 @@ public final class LoginCredentials implements Serializable {
 | 
			
		||||
	 * @return the created login credentials
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static LoginCredentials registration(String identifier, String password, boolean requestToken, String clientVersion, Instant lastSync) {
 | 
			
		||||
		return new LoginCredentials(identifier, password, true, false, requestToken, clientVersion, lastSync);
 | 
			
		||||
	public static LoginCredentials registration(String identifier, String password,
 | 
			
		||||
		boolean requestToken, String clientVersion, Instant lastSync) {
 | 
			
		||||
		return new LoginCredentials(identifier, password, true, false, requestToken, clientVersion,
 | 
			
		||||
			lastSync);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("LoginCredentials[identifier=%s,registration=%b,token=%b,requestToken=%b,clientVersion=%s,lastSync=%s]",
 | 
			
		||||
				identifier,
 | 
			
		||||
				registration,
 | 
			
		||||
				token,
 | 
			
		||||
				requestToken,
 | 
			
		||||
				clientVersion,
 | 
			
		||||
				lastSync);
 | 
			
		||||
		return String.format(
 | 
			
		||||
			"LoginCredentials[identifier=%s,registration=%b,token=%b,requestToken=%b,clientVersion=%s,lastSync=%s]",
 | 
			
		||||
			identifier,
 | 
			
		||||
			registration,
 | 
			
		||||
			token,
 | 
			
		||||
			requestToken,
 | 
			
		||||
			clientVersion,
 | 
			
		||||
			lastSync);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -100,24 +105,27 @@ public final class LoginCredentials implements Serializable {
 | 
			
		||||
	public String getPassword() { return password; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return {@code true} if these credentials are used for user registration
 | 
			
		||||
	 *         instead of user login
 | 
			
		||||
	 * @return {@code true} if these credentials are used for user registration instead of user
 | 
			
		||||
	 *         login
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean isRegistration() { return registration; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return {@code true} if these credentials use an authentication token instead
 | 
			
		||||
	 *         of a password
 | 
			
		||||
	 * @return {@code true} if these credentials use an authentication token instead of a password
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean usesToken() { return token; }
 | 
			
		||||
	public boolean usesToken() {
 | 
			
		||||
		return token;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return {@code true} if the server should generate a new authentication token
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean requestToken() { return requestToken; }
 | 
			
		||||
	public boolean requestToken() {
 | 
			
		||||
		return requestToken;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the version of the client sending these credentials
 | 
			
		||||
 
 | 
			
		||||
@@ -6,9 +6,8 @@ import java.time.Instant;
 | 
			
		||||
import dev.kske.eventbus.IEvent;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a unique message with a unique, numeric ID. Further metadata
 | 
			
		||||
 * includes the sender and recipient {@link User}s, as well as the creation
 | 
			
		||||
 * date and the current {@link MessageStatus}.<br>
 | 
			
		||||
 * Represents a unique message with a unique, numeric ID. Further metadata includes the sender and
 | 
			
		||||
 * recipient {@link User}s, as well as the creation date and the current {@link MessageStatus}.<br>
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
@@ -56,10 +55,9 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	private static final long serialVersionUID = 2L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link Message} with values for all of its properties. The use
 | 
			
		||||
	 * of this constructor is only intended for the {@link MessageBuilder} class, as
 | 
			
		||||
	 * this class provides {@code null} checks and default values for all
 | 
			
		||||
	 * properties.
 | 
			
		||||
	 * Initializes a {@link Message} with values for all of its properties. The use of this
 | 
			
		||||
	 * constructor is only intended for the {@link MessageBuilder} class, as this class provides
 | 
			
		||||
	 * {@code null} checks and default values for all properties.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id           unique ID
 | 
			
		||||
	 * @param senderID     the ID of the user who sends the message
 | 
			
		||||
@@ -73,8 +71,9 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	 * @param forwarded    whether this message was forwarded
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	Message(long id, long senderID, long recipientID, Instant creationDate, Instant receivedDate, Instant readDate, String text,
 | 
			
		||||
			Attachment attachment, MessageStatus status, boolean forwarded) {
 | 
			
		||||
	Message(long id, long senderID, long recipientID, Instant creationDate, Instant receivedDate,
 | 
			
		||||
		Instant readDate, String text,
 | 
			
		||||
		Attachment attachment, MessageStatus status, boolean forwarded) {
 | 
			
		||||
		this.id				= id;
 | 
			
		||||
		this.senderID		= senderID;
 | 
			
		||||
		this.recipientID	= recipientID;
 | 
			
		||||
@@ -101,21 +100,23 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public void nextStatus() {
 | 
			
		||||
		if (status == MessageStatus.READ) throw new IllegalStateException("Message status READ is already reached");
 | 
			
		||||
		if (status == MessageStatus.READ)
 | 
			
		||||
			throw new IllegalStateException("Message status READ is already reached");
 | 
			
		||||
		status = MessageStatus.values()[status.ordinal() + 1];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("Message[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s,forwarded=%b,hasAttachment=%b]",
 | 
			
		||||
				id,
 | 
			
		||||
				senderID,
 | 
			
		||||
				recipientID,
 | 
			
		||||
				creationDate,
 | 
			
		||||
				status,
 | 
			
		||||
				text,
 | 
			
		||||
				forwarded,
 | 
			
		||||
				attachment != null);
 | 
			
		||||
		return String.format(
 | 
			
		||||
			"Message[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s,forwarded=%b,hasAttachment=%b]",
 | 
			
		||||
			id,
 | 
			
		||||
			senderID,
 | 
			
		||||
			recipientID,
 | 
			
		||||
			creationDate,
 | 
			
		||||
			status,
 | 
			
		||||
			text,
 | 
			
		||||
			forwarded,
 | 
			
		||||
			attachment != null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -149,8 +150,7 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	public Instant getReceivedDate() { return receivedDate; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param receivedDate the date at which the message has been received by the
 | 
			
		||||
	 *                     sender
 | 
			
		||||
	 * @param receivedDate the date at which the message has been received by the sender
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void setReceivedDate(Instant receivedDate) { this.receivedDate = receivedDate; }
 | 
			
		||||
@@ -183,7 +183,9 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	 * @return {@code true} if an attachment is present
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean hasAttachment() { return attachment != null; }
 | 
			
		||||
	public boolean hasAttachment() {
 | 
			
		||||
		return attachment != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the current status of this message
 | 
			
		||||
@@ -196,7 +198,8 @@ public class Message implements Serializable, IEvent {
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	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");
 | 
			
		||||
		this.status = status;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,20 +25,21 @@ public final class MessageBuilder {
 | 
			
		||||
	private boolean					forwarded;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link MessageBuilder} with all mandatory values
 | 
			
		||||
	 * without defaults for the {@link Message} class.
 | 
			
		||||
	 * Creates an instance of {@link MessageBuilder} with all mandatory values without defaults for
 | 
			
		||||
	 * the {@link Message} class.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param senderID    the ID of the user who sends the {@link Message}
 | 
			
		||||
	 * @param recipientID the ID of the user who receives the {@link Message}
 | 
			
		||||
	 * @param idGenerator the ID generator used to generate a unique {@link Message}
 | 
			
		||||
	 *                    id
 | 
			
		||||
	 * @param idGenerator the ID generator used to generate a unique {@link Message} id
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public MessageBuilder(long senderID, long recipientID, IDGenerator idGenerator) { this(senderID, recipientID, idGenerator.next()); }
 | 
			
		||||
	public MessageBuilder(long senderID, long recipientID, IDGenerator idGenerator) {
 | 
			
		||||
		this(senderID, recipientID, idGenerator.next());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link MessageBuilder} with all mandatory values
 | 
			
		||||
	 * without defaults for the {@link Message} class.
 | 
			
		||||
	 * Creates an instance of {@link MessageBuilder} with all mandatory values without defaults for
 | 
			
		||||
	 * the {@link Message} class.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param senderID    the ID of the user who sends the {@link Message}
 | 
			
		||||
	 * @param recipientID the ID of the user who receives the {@link Message}
 | 
			
		||||
@@ -52,14 +53,12 @@ public final class MessageBuilder {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * This constructor transforms a given {@link Message} into a new message for a
 | 
			
		||||
	 * new receiver.
 | 
			
		||||
	 * This constructor transforms a given {@link Message} into a new message for a new receiver.
 | 
			
		||||
	 * This makes it especially useful in the case of forwarding messages.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param msg         the message to copy
 | 
			
		||||
	 * @param recipientID the ID of the user who receives the {@link Message}
 | 
			
		||||
	 * @param iDGenerator the ID generator used to generate a unique {@link Message}
 | 
			
		||||
	 *                    id
 | 
			
		||||
	 * @param iDGenerator the ID generator used to generate a unique {@link Message} id
 | 
			
		||||
	 * @since Envoy v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public MessageBuilder(Message msg, long recipientID, IDGenerator iDGenerator) {
 | 
			
		||||
@@ -72,79 +71,69 @@ public final class MessageBuilder {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link Message} with the previously supplied values.
 | 
			
		||||
	 * If a mandatory value is not set, a default value will be used instead:<br>
 | 
			
		||||
	 * Creates an instance of {@link Message} with the previously supplied values. If a mandatory
 | 
			
		||||
	 * value is not set, a default value will be used instead:<br>
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code date}
 | 
			
		||||
	 * {@code Instant.now()} and {@code null} for {@code receivedDate} and
 | 
			
		||||
	 * {@code readDate}
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code text}
 | 
			
		||||
	 * {@code ""}
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code status}
 | 
			
		||||
	 * {@code MessageStatus.WAITING}
 | 
			
		||||
	 * {@code date} {@code Instant.now()} and {@code null} for {@code receivedDate} and
 | 
			
		||||
	 * {@code readDate} <br>
 | 
			
		||||
	 * {@code text} {@code ""} <br>
 | 
			
		||||
	 * {@code status} {@code MessageStatus.WAITING}
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return a new instance of {@link Message}
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public Message build() {
 | 
			
		||||
		supplyDefaults();
 | 
			
		||||
		return new Message(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
 | 
			
		||||
		return new Message(id, senderID, recipientID, creationDate, receivedDate, readDate, text,
 | 
			
		||||
			attachment, status, forwarded);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link GroupMessage} with the previously supplied
 | 
			
		||||
	 * values. <br>
 | 
			
		||||
	 * Creates an instance of {@link GroupMessage} with the previously supplied values. <br>
 | 
			
		||||
	 * <b> Sets all member statuses to {@link MessageStatus#WAITING}.</b><br>
 | 
			
		||||
	 * If a mandatory value is not set, a default value will be used
 | 
			
		||||
	 * instead:<br>
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code time stamp}
 | 
			
		||||
	 * {@code Instant.now()}
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code text}
 | 
			
		||||
	 * {@code ""}
 | 
			
		||||
	 * If a mandatory value is not set, a default value will be used instead:<br>
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code time stamp} {@code Instant.now()} <br>
 | 
			
		||||
	 * {@code text} {@code ""} <br>
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param group the {@link Group} that is used to fill the map of member
 | 
			
		||||
	 *              statuses
 | 
			
		||||
	 * @param group the {@link Group} that is used to fill the map of member statuses
 | 
			
		||||
	 * @return a new instance of {@link GroupMessage}
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public GroupMessage buildGroupMessage(Group group) {
 | 
			
		||||
		final var memberStatuses = new HashMap<Long, Message.MessageStatus>();
 | 
			
		||||
		group.getContacts().forEach(user -> memberStatuses.put(user.getID(), MessageStatus.WAITING));
 | 
			
		||||
		group.getContacts()
 | 
			
		||||
			.forEach(user -> memberStatuses.put(user.getID(), MessageStatus.WAITING));
 | 
			
		||||
		return buildGroupMessage(group, memberStatuses);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link GroupMessage} with the previously supplied
 | 
			
		||||
	 * values. If a mandatory value is not set, a default value will be used
 | 
			
		||||
	 * instead:<br>
 | 
			
		||||
	 * Creates an instance of {@link GroupMessage} with the previously supplied values. If a
 | 
			
		||||
	 * mandatory value is not set, a default value will be used instead:<br>
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code time stamp}
 | 
			
		||||
	 * {@code Instant.now()}
 | 
			
		||||
	 * <br>
 | 
			
		||||
	 * {@code text}
 | 
			
		||||
	 * {@code ""}
 | 
			
		||||
	 * {@code time stamp} {@code Instant.now()} <br>
 | 
			
		||||
	 * {@code text} {@code ""}
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param group          the {@link Group} that is used to fill the map of
 | 
			
		||||
	 *                       member statuses
 | 
			
		||||
	 * @param group          the {@link Group} that is used to fill the map of member statuses
 | 
			
		||||
	 * @param memberStatuses the map of all current statuses
 | 
			
		||||
	 * @return a new instance of {@link GroupMessage}
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public GroupMessage buildGroupMessage(Group group, Map<Long, MessageStatus> memberStatuses) {
 | 
			
		||||
		if (group == null || memberStatuses == null) throw new NullPointerException();
 | 
			
		||||
		if (group == null || memberStatuses == null)
 | 
			
		||||
			throw new NullPointerException();
 | 
			
		||||
		supplyDefaults();
 | 
			
		||||
		return new GroupMessage(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded, memberStatuses);
 | 
			
		||||
		return new GroupMessage(id, senderID, recipientID, creationDate, receivedDate, readDate,
 | 
			
		||||
			text, attachment, status, forwarded, memberStatuses);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void supplyDefaults() {
 | 
			
		||||
		if (creationDate == null) creationDate = Instant.now();
 | 
			
		||||
		if (text == null) text = "";
 | 
			
		||||
		if (status == null) status = MessageStatus.WAITING;
 | 
			
		||||
		if (creationDate == null)
 | 
			
		||||
			creationDate = Instant.now();
 | 
			
		||||
		if (text == null)
 | 
			
		||||
			text = "";
 | 
			
		||||
		if (status == null)
 | 
			
		||||
			status = MessageStatus.WAITING;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -188,8 +177,7 @@ public final class MessageBuilder {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param attachment the {@link Attachment} of the {@link Message} to
 | 
			
		||||
	 *                   create
 | 
			
		||||
	 * @param attachment the {@link Attachment} of the {@link Message} to create
 | 
			
		||||
	 * @return this {@link MessageBuilder}
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,7 @@ import java.io.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a unique user with a unique, numeric ID, a name and a current
 | 
			
		||||
 * {@link UserStatus}.<br>
 | 
			
		||||
 * Represents a unique user with a unique, numeric ID, a name and a current {@link UserStatus}.<br>
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.2-alpha
 | 
			
		||||
@@ -34,8 +33,7 @@ public final class User extends Contact {
 | 
			
		||||
		ONLINE,
 | 
			
		||||
 | 
			
		||||
		/**
 | 
			
		||||
		 * select this, if a user is online but unavailable at the moment (sudden
 | 
			
		||||
		 * interruption)
 | 
			
		||||
		 * select this, if a user is online but unavailable at the moment (sudden interruption)
 | 
			
		||||
		 */
 | 
			
		||||
		AWAY,
 | 
			
		||||
 | 
			
		||||
@@ -52,8 +50,7 @@ public final class User extends Contact {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link User}. <br>
 | 
			
		||||
	 * The {@link UserStatus} is set to {@link UserStatus#ONLINE}.
 | 
			
		||||
	 * No contacts are initialized.
 | 
			
		||||
	 * The {@link UserStatus} is set to {@link UserStatus#ONLINE}. No contacts are initialized.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id   unique ID
 | 
			
		||||
	 * @param name user name
 | 
			
		||||
@@ -94,7 +91,8 @@ public final class User extends Contact {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("User[id=%d,name=%s,status=%s", id, name, status) + (contacts.isEmpty() ? "]" : "," + contacts.size() + " contact(s)]");
 | 
			
		||||
		return String.format("User[id=%d,name=%s,status=%s", id, name, status)
 | 
			
		||||
			+ (contacts.isEmpty() ? "]" : "," + contacts.size() + " contact(s)]");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -119,15 +117,18 @@ public final class User extends Contact {
 | 
			
		||||
	private void writeObject(ObjectOutputStream outputStream) throws Exception {
 | 
			
		||||
		outputStream.defaultWriteObject();
 | 
			
		||||
		if (serializeContacts) {
 | 
			
		||||
			getContacts().stream().filter(User.class::isInstance).map(User.class::cast).forEach(user -> user.serializeContacts = false);
 | 
			
		||||
			getContacts().stream().filter(User.class::isInstance).map(User.class::cast)
 | 
			
		||||
				.forEach(user -> user.serializeContacts = false);
 | 
			
		||||
			outputStream.writeObject(getContacts());
 | 
			
		||||
		} else outputStream.writeObject(new HashSet<>());
 | 
			
		||||
		} else
 | 
			
		||||
			outputStream.writeObject(new HashSet<>());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param serializeContacts whether the contacts of this {@link User} should be
 | 
			
		||||
	 *                          serialized
 | 
			
		||||
	 * @param serializeContacts whether the contacts of this {@link User} should be serialized
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void serializeContacts(boolean serializeContacts) { this.serializeContacts = serializeContacts; }
 | 
			
		||||
	public void serializeContacts(boolean serializeContacts) {
 | 
			
		||||
		this.serializeContacts = serializeContacts;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/**
 | 
			
		||||
 * This package contains all data objects that are used both by Envoy Client and
 | 
			
		||||
 * by Envoy Server.
 | 
			
		||||
 * This package contains all data objects that are used both by Envoy Client and by Envoy Server.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,7 @@ package envoy.event;
 | 
			
		||||
/**
 | 
			
		||||
 * This enum declares all modification possibilities for a given container.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * These can be: {@link ElementOperation#ADD} or
 | 
			
		||||
 * {@link ElementOperation#REMOVE}.
 | 
			
		||||
 * These can be: {@link ElementOperation#ADD} or {@link ElementOperation#REMOVE}.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.1-beta
 | 
			
		||||
@@ -12,14 +11,12 @@ package envoy.event;
 | 
			
		||||
public enum ElementOperation {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Select this element, if the given element should be added to the given
 | 
			
		||||
	 * container.
 | 
			
		||||
	 * Select this element, if the given element should be added to the given container.
 | 
			
		||||
	 */
 | 
			
		||||
	ADD,
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Select this element, if the given element should be removed from the given
 | 
			
		||||
	 * container.
 | 
			
		||||
	 * Select this element, if the given element should be removed from the given container.
 | 
			
		||||
	 */
 | 
			
		||||
	REMOVE
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@ import java.io.Serializable;
 | 
			
		||||
import dev.kske.eventbus.IEvent;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class serves as a convenience base class for all events. It implements
 | 
			
		||||
 * the {@link IEvent} interface and provides a generic value. For events without
 | 
			
		||||
 * a value there also is {@link envoy.event.Event.Valueless}.
 | 
			
		||||
 * This class serves as a convenience base class for all events. It implements the {@link IEvent}
 | 
			
		||||
 * interface and provides a generic value. For events without a value there also is
 | 
			
		||||
 * {@link envoy.event.Event.Valueless}.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @param <T> the type of the Event
 | 
			
		||||
@@ -19,15 +19,21 @@ public abstract class Event<T> implements IEvent, Serializable {
 | 
			
		||||
 | 
			
		||||
	private static final long serialVersionUID = 0L;
 | 
			
		||||
 | 
			
		||||
	protected Event(T value) { this.value = value; }
 | 
			
		||||
	protected Event(T value) {
 | 
			
		||||
		this.value = value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the data associated with this event
 | 
			
		||||
	 */
 | 
			
		||||
	public T get() { return value; }
 | 
			
		||||
	public T get() {
 | 
			
		||||
		return value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("%s[value=%s]", this.getClass().getSimpleName(), value); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("%s[value=%s]", this.getClass().getSimpleName(), value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Serves as a super class for events that do not carry a value.
 | 
			
		||||
@@ -39,9 +45,13 @@ public abstract class Event<T> implements IEvent, Serializable {
 | 
			
		||||
 | 
			
		||||
		private static final long serialVersionUID = 0L;
 | 
			
		||||
 | 
			
		||||
		protected Valueless() { super(null); }
 | 
			
		||||
		protected Valueless() {
 | 
			
		||||
			super(null);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public String toString() { return this.getClass().getSimpleName(); }
 | 
			
		||||
		public String toString() {
 | 
			
		||||
			return this.getClass().getSimpleName();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,9 +18,8 @@ public final class GroupCreation extends Event<String> {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param name             the name of this group at creation time
 | 
			
		||||
	 * @param initialMemberIDs the IDs of all {@link User}s that should be group
 | 
			
		||||
	 *                         members from the beginning on (excluding the creator
 | 
			
		||||
	 *                         of this group)
 | 
			
		||||
	 * @param initialMemberIDs the IDs of all {@link User}s that should be group members from the
 | 
			
		||||
	 *                         beginning on (excluding the creator of this group)
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public GroupCreation(String name, Set<Long> initialMemberIDs) {
 | 
			
		||||
@@ -29,8 +28,8 @@ public final class GroupCreation extends Event<String> {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the IDs of all {@link User}s that are members from the beginning
 | 
			
		||||
	 *         (excluding the creator of this group)
 | 
			
		||||
	 * @return the IDs of all {@link User}s that are members from the beginning (excluding the
 | 
			
		||||
	 *         creator of this group)
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public Set<Long> getInitialMemberIDs() { return initialMemberIDs; }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,8 @@ package envoy.event;
 | 
			
		||||
import envoy.data.Group;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Used to communicate with a client that his request to create a group might
 | 
			
		||||
 * have been rejected as it might be disabled on his current server.
 | 
			
		||||
 * Used to communicate with a client that his request to create a group might have been rejected as
 | 
			
		||||
 * it might be disabled on his current server.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.2-beta
 | 
			
		||||
@@ -19,7 +19,9 @@ public class GroupCreationResult extends Event<Group> {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public GroupCreationResult() { super(null); }
 | 
			
		||||
	public GroupCreationResult() {
 | 
			
		||||
		super(null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates a new {@code GroupCreationResult}.
 | 
			
		||||
@@ -27,5 +29,7 @@ public class GroupCreationResult extends Event<Group> {
 | 
			
		||||
	 * @param resultGroup the group the server created
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public GroupCreationResult(Group resultGroup) { super(resultGroup); }
 | 
			
		||||
	public GroupCreationResult(Group resultGroup) {
 | 
			
		||||
		super(resultGroup);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,11 +17,10 @@ public final class GroupMessageStatusChange extends MessageStatusChange {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link GroupMessageStatusChange}.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id       the ID of the {@link GroupMessage} this event is related to
 | 
			
		||||
	 * @param status   the status of this specific members {@link GroupMessage}
 | 
			
		||||
	 * @param date     the date at which the MessageStatus change occurred for
 | 
			
		||||
	 *                 this specific member
 | 
			
		||||
	 * @param date     the date at which the MessageStatus change occurred for this specific member
 | 
			
		||||
	 * @param memberID the ID of the group member that caused the status change
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -37,5 +36,8 @@ public final class GroupMessageStatusChange extends MessageStatusChange {
 | 
			
		||||
	public long getMemberID() { return memberID; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("GroupMessageStatusChange[meta=%s,memberID=%d]", super.toString(), memberID); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("GroupMessageStatusChange[meta=%s,memberID=%d]", super.toString(),
 | 
			
		||||
			memberID);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,11 +5,9 @@ import static envoy.event.ElementOperation.*;
 | 
			
		||||
import envoy.data.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This event is used to communicate changes in the group size between client
 | 
			
		||||
 * and server.
 | 
			
		||||
 * This event is used to communicate changes in the group size between client and server.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Possible actions are adding or removing certain {@link User}s to or from a
 | 
			
		||||
 * certain {@link Group}.
 | 
			
		||||
 * Possible actions are adding or removing certain {@link User}s to or from a certain {@link Group}.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.1-beta
 | 
			
		||||
@@ -22,8 +20,7 @@ public final class GroupResize extends Event<User> {
 | 
			
		||||
	private static final long serialVersionUID = 0L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link GroupResize} through a Contact where the name has
 | 
			
		||||
	 * already been set.
 | 
			
		||||
	 * Initializes a {@link GroupResize} through a Contact where the name has already been set.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param user      the {@link User} who wants to join or leave a group
 | 
			
		||||
	 * @param group     the {@link Group} he wants to join or leave
 | 
			
		||||
@@ -37,7 +34,9 @@ public final class GroupResize extends Event<User> {
 | 
			
		||||
		final var contained = group.getContacts().contains(user);
 | 
			
		||||
		if (contained && operation.equals(ADD))
 | 
			
		||||
			throw new IllegalArgumentException(String.format("Cannot add %s to %s!", user, group));
 | 
			
		||||
		else if (operation.equals(REMOVE) && !contained) throw new IllegalArgumentException(String.format("Cannot remove %s from %s!", user, group));
 | 
			
		||||
		else if (operation.equals(REMOVE) && !contained)
 | 
			
		||||
			throw new IllegalArgumentException(
 | 
			
		||||
				String.format("Cannot remove %s from %s!", user, group));
 | 
			
		||||
		groupID = group.getID();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -71,5 +70,8 @@ public final class GroupResize extends Event<User> {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("GroupResize[user=%s,groupid=%d,operation=%s]", get(), groupID, operation); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("GroupResize[user=%s,groupid=%d,operation=%s]", get(), groupID,
 | 
			
		||||
			operation);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Signifies to the client that the handshake failed for the attached
 | 
			
		||||
 * reason.
 | 
			
		||||
 * Signifies to the client that the handshake failed for the attached reason.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.3-alpha
 | 
			
		||||
@@ -24,8 +23,7 @@ public final class HandshakeRejection extends Event<String> {
 | 
			
		||||
	public static final String USERNAME_TAKEN = "Incorrect user name or password.";
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Select this value if the version of the client is incompatible with the
 | 
			
		||||
	 * server.
 | 
			
		||||
	 * Select this value if the version of the client is incompatible with the server.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -39,8 +37,7 @@ public final class HandshakeRejection extends Event<String> {
 | 
			
		||||
	public static final String INVALID_TOKEN = "Invalid authentication token";
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Select this value if the handshake could not be completed for some different
 | 
			
		||||
	 * reason.
 | 
			
		||||
	 * Select this value if the handshake could not be completed for some different reason.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Common v0.3-alpha
 | 
			
		||||
	 */
 | 
			
		||||
@@ -54,7 +51,9 @@ public final class HandshakeRejection extends Event<String> {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Common v0.3-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public HandshakeRejection() { super(INTERNAL_ERROR); }
 | 
			
		||||
	public HandshakeRejection() {
 | 
			
		||||
		super(INTERNAL_ERROR);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@link HandshakeRejection}.
 | 
			
		||||
@@ -62,5 +61,7 @@ public final class HandshakeRejection extends Event<String> {
 | 
			
		||||
	 * @param reason the reason why the handshake was rejected
 | 
			
		||||
	 * @since Envoy Common v0.3-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public HandshakeRejection(String reason) { super(reason); }
 | 
			
		||||
	public HandshakeRejection(String reason) {
 | 
			
		||||
		super(reason);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Signifies to the server that the client needs a new
 | 
			
		||||
 * {@link envoy.data.IDGenerator} instance.
 | 
			
		||||
 * Signifies to the server that the client needs a new {@link envoy.data.IDGenerator} instance.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Common v0.3-alpha
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This event should be sent when a user is currently typing something in a
 | 
			
		||||
 * chat.
 | 
			
		||||
 * This event should be sent when a user is currently typing something in a chat.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Client v0.2-beta
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class allows envoy users to send an issue proposal to the server who, if
 | 
			
		||||
 * not disabled by its administrator, will forward it directly to Gitea.
 | 
			
		||||
 * This class allows envoy users to send an issue proposal to the server who, if not disabled by its
 | 
			
		||||
 * administrator, will forward it directly to Gitea.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.2-beta
 | 
			
		||||
@@ -17,9 +17,8 @@ public final class IssueProposal extends Event<String> {
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param title       the title of the reported bug
 | 
			
		||||
	 * @param description the description of this bug
 | 
			
		||||
	 * @param isBug       determines whether this {@code IssueProposal} is
 | 
			
		||||
	 *                    supposed to be a
 | 
			
		||||
	 *                    feature or a bug (true = bug, false = feature)
 | 
			
		||||
	 * @param isBug       determines whether this {@code IssueProposal} is supposed to be a feature
 | 
			
		||||
	 *                    or a bug (true = bug, false = feature)
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public IssueProposal(String title, String description, boolean isBug) {
 | 
			
		||||
@@ -32,14 +31,14 @@ public final class IssueProposal extends Event<String> {
 | 
			
		||||
	 * @param title       the title of the reported bug
 | 
			
		||||
	 * @param description the description of this bug
 | 
			
		||||
	 * @param user        the name of the user creating the issue
 | 
			
		||||
	 * @param isBug       determines whether this {@code IssueProposal} is
 | 
			
		||||
	 *                    supposed to be a
 | 
			
		||||
	 *                    feature or a bug (true = bug, false = feature)
 | 
			
		||||
	 * @param isBug       determines whether this {@code IssueProposal} is supposed to be a feature
 | 
			
		||||
	 *                    or a bug (true = bug, false = feature)
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public IssueProposal(String title, String description, String user, boolean isBug) {
 | 
			
		||||
		super(escape(title));
 | 
			
		||||
		this.description	= sanitizeDescription(description) + String.format("<br>Submitted by user %s.", user);
 | 
			
		||||
		this.description	=
 | 
			
		||||
			sanitizeDescription(description) + String.format("<br>Submitted by user %s.", user);
 | 
			
		||||
		bug					= isBug;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -61,7 +60,9 @@ public final class IssueProposal extends Event<String> {
 | 
			
		||||
	 * @return the escaped string
 | 
			
		||||
	 * @since Envoy Client v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private static String escape(String raw) { return raw.replace("\\", "\\\\").replace("\"", "\\\""); }
 | 
			
		||||
	private static String escape(String raw) {
 | 
			
		||||
		return raw.replace("\\", "\\\\").replace("\"", "\\\"");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the description
 | 
			
		||||
@@ -70,8 +71,7 @@ public final class IssueProposal extends Event<String> {
 | 
			
		||||
	public String getDescription() { return description; }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return whether this issue is supposed to be a bug - otherwise it is intended
 | 
			
		||||
	 *         as a feature
 | 
			
		||||
	 * @return whether this issue is supposed to be a bug - otherwise it is intended as a feature
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean isBug() { return bug; }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,7 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
 | 
			
		||||
	 * Initializes a {@link MessageStatusChange}.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id     the ID of the {@link Message} this event is related to
 | 
			
		||||
	 * @param status the status of the {@link Message} this event is related
 | 
			
		||||
	 *               to
 | 
			
		||||
	 * @param status the status of the {@link Message} this event is related to
 | 
			
		||||
	 * @param date   the date at which the MessageStatus change occurred
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -36,7 +35,9 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
 | 
			
		||||
	 * @param message the message from which to build the event
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public MessageStatusChange(Message message) { this(message.getID(), message.getStatus(), Instant.now()); }
 | 
			
		||||
	public MessageStatusChange(Message message) {
 | 
			
		||||
		this(message.getID(), message.getStatus(), Instant.now());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the ID of the {@link Message} this event is related to
 | 
			
		||||
@@ -51,5 +52,7 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
 | 
			
		||||
	public Instant getDate() { return date; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("MessageStatusChange[id=%d,status=%s,date=%s]", id, value, date); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("MessageStatusChange[id=%d,status=%s,date=%s]", id, value, date);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,7 @@ import envoy.data.Contact;
 | 
			
		||||
/**
 | 
			
		||||
 * This event informs
 | 
			
		||||
 * <p>
 | 
			
		||||
 * a) the server of the name change of a user or a group.
 | 
			
		||||
 * b) another user of this users name change.
 | 
			
		||||
 * a) the server of the name change of a user or a group. b) another user of this users name change.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.1-beta
 | 
			
		||||
@@ -15,7 +14,7 @@ public final class NameChange extends Event<String> {
 | 
			
		||||
 | 
			
		||||
	private final long id;
 | 
			
		||||
 | 
			
		||||
	private static final long	serialVersionUID	= 0L;
 | 
			
		||||
	private static final long serialVersionUID = 0L;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates a new {@link NameChange} for a user or a group.
 | 
			
		||||
@@ -30,13 +29,14 @@ public final class NameChange extends Event<String> {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes a {@link NameChange} through a Contact where the name has
 | 
			
		||||
	 * already been set.
 | 
			
		||||
	 * Initializes a {@link NameChange} through a Contact where the name has already been set.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param contact the contact whose name was updated
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public NameChange(Contact contact) { this(contact.getID(), contact.getName()); }
 | 
			
		||||
	public NameChange(Contact contact) {
 | 
			
		||||
		this(contact.getID(), contact.getName());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the ID of the {@link Contact} this event is related to
 | 
			
		||||
@@ -45,5 +45,7 @@ public final class NameChange extends Event<String> {
 | 
			
		||||
	public long getID() { return id; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("NameChange[id=%d,name=%s]", id, value); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("NameChange[id=%d,name=%s]", id, value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,5 +21,7 @@ public class NewAuthToken extends Event<String> {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return "NewAuthToken"; }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return "NewAuthToken";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,7 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This event is used so that the server can tell the client that attachments
 | 
			
		||||
 * will be filtered out.
 | 
			
		||||
 * This event is used so that the server can tell the client that attachments will be filtered out.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.2-beta
 | 
			
		||||
 
 | 
			
		||||
@@ -38,5 +38,7 @@ public final class PasswordChangeRequest extends Event<String> {
 | 
			
		||||
	public String getOldPassword() { return oldPassword; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return "PasswordChangeRequest[id=" + id + "]"; }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return "PasswordChangeRequest[id=" + id + "]";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package envoy.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class acts as a notice to the user whether his
 | 
			
		||||
 * {@link envoy.event.PasswordChangeRequest} was successful.
 | 
			
		||||
 * This class acts as a notice to the user whether his {@link envoy.event.PasswordChangeRequest} was
 | 
			
		||||
 * successful.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.2-beta
 | 
			
		||||
@@ -14,9 +14,10 @@ public final class PasswordChangeResult extends Event<Boolean> {
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates an instance of {@code PasswordChangeResult}.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param value whether the preceding {@link envoy.event.PasswordChangeRequest}
 | 
			
		||||
	 *              was successful.
 | 
			
		||||
	 * @param value whether the preceding {@link envoy.event.PasswordChangeRequest} was successful.
 | 
			
		||||
	 * @since Envoy Common v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public PasswordChangeResult(boolean value) { super(value); }
 | 
			
		||||
	public PasswordChangeResult(boolean value) {
 | 
			
		||||
		super(value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,7 @@ public final class UserStatusChange extends Event<UserStatus> {
 | 
			
		||||
	 * Initializes a {@link UserStatusChange}.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param id     the ID of the {@link User} this event is related to
 | 
			
		||||
	 * @param status the status of the {@link User} this event is related
 | 
			
		||||
	 *               to
 | 
			
		||||
	 * @param status the status of the {@link User} this event is related to
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public UserStatusChange(long id, User.UserStatus status) {
 | 
			
		||||
@@ -32,7 +31,9 @@ public final class UserStatusChange extends Event<UserStatus> {
 | 
			
		||||
	 * @param user the User from which to build the event
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public UserStatusChange(User user) { this(user.getID(), user.getStatus()); }
 | 
			
		||||
	public UserStatusChange(User user) {
 | 
			
		||||
		this(user.getID(), user.getStatus());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the ID of the {@link User} this event is related to
 | 
			
		||||
@@ -41,5 +42,7 @@ public final class UserStatusChange extends Event<UserStatus> {
 | 
			
		||||
	public long getID() { return id; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("UserStatusChange[id=%d,status=%s]", id, value); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("UserStatusChange[id=%d,status=%s]", id, value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,8 +3,8 @@ package envoy.event.contact;
 | 
			
		||||
import envoy.event.Event.Valueless;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Conveys that either a direct contact or a group member has been deleted while
 | 
			
		||||
 * the user has been offline.
 | 
			
		||||
 * Conveys that either a direct contact or a group member has been deleted while the user has been
 | 
			
		||||
 * offline.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @since Envoy Common v0.3-beta
 | 
			
		||||
 
 | 
			
		||||
@@ -34,5 +34,8 @@ public final class UserOperation extends Event<User> {
 | 
			
		||||
	public ElementOperation getOperationType() { return operationType; }
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("%s[contact=%s, operation=%s]", UserOperation.class.getSimpleName(), value, operationType); }
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		return String.format("%s[contact=%s, operation=%s]", UserOperation.class.getSimpleName(),
 | 
			
		||||
			value, operationType);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,5 +18,7 @@ public final class UserSearchRequest extends Event<String> {
 | 
			
		||||
	 * @param searchPhrase the search phrase to use in the user search
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public UserSearchRequest(String searchPhrase) { super(searchPhrase); }
 | 
			
		||||
	public UserSearchRequest(String searchPhrase) {
 | 
			
		||||
		super(searchPhrase);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,5 +21,7 @@ public final class UserSearchResult extends Event<List<User>> {
 | 
			
		||||
	 * @param users the users found during the search
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public UserSearchResult(List<User> users) { super(users); }
 | 
			
		||||
	public UserSearchResult(List<User> users) {
 | 
			
		||||
		super(users);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/**
 | 
			
		||||
 * This package contains all events that can be sent or received by Envoy Client
 | 
			
		||||
 * or Envoy Server Standalone.
 | 
			
		||||
 * This package contains all events that can be sent or received by Envoy Client or Envoy Server
 | 
			
		||||
 * Standalone.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 
 | 
			
		||||
@@ -12,20 +12,24 @@ public final class EnvoyException extends Exception {
 | 
			
		||||
	 * @param message the message to display once this Exception is thrown
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public EnvoyException(String message) { super(message); }
 | 
			
		||||
	public EnvoyException(String message) {
 | 
			
		||||
		super(message);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param message the message to display once this Exception is thrown
 | 
			
		||||
	 * @param cause   the {@link Throwable} which resulted in the throw of an
 | 
			
		||||
	 *                EnvoyException
 | 
			
		||||
	 * @param cause   the {@link Throwable} which resulted in the throw of an EnvoyException
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public EnvoyException(String message, Throwable cause) { super(message, cause); }
 | 
			
		||||
	public EnvoyException(String message, Throwable cause) {
 | 
			
		||||
		super(message, cause);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param cause the {@link Throwable} which resulted in the throw of an
 | 
			
		||||
	 *              EnvoyException
 | 
			
		||||
	 * @param cause the {@link Throwable} which resulted in the throw of an EnvoyException
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public EnvoyException(Throwable cause) { super(cause); }
 | 
			
		||||
	public EnvoyException(Throwable cause) {
 | 
			
		||||
		super(cause);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,13 +26,16 @@ public final class Bounds {
 | 
			
		||||
	 * @return {@code true} if the given contact name is valid
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static boolean isValidContactName(String contactName) { return CONTACT_NAME_PATTERN.matcher(contactName).matches(); }
 | 
			
		||||
	public static boolean isValidContactName(String contactName) {
 | 
			
		||||
		return CONTACT_NAME_PATTERN.matcher(contactName).matches();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the maximum size allowed for a user/ group name.
 | 
			
		||||
	 * @apiNote has to be updated manually if {@link Bounds#CONTACT_NAME_PATTERN}
 | 
			
		||||
	 *          gets updated.
 | 
			
		||||
	 * @apiNote has to be updated manually if {@link Bounds#CONTACT_NAME_PATTERN} gets updated.
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static int maximumUsernameSize() { return 16; }
 | 
			
		||||
	public static int maximumUsernameSize() {
 | 
			
		||||
		return 16;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,7 @@ import java.util.logging.*;
 | 
			
		||||
import envoy.data.Config;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Configures the {@link java.util.logging} API to output the log into the
 | 
			
		||||
 * console and a log file.
 | 
			
		||||
 * Configures the {@link java.util.logging} API to output the log into the console and a log file.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
@@ -30,20 +29,23 @@ public final class EnvoyLog {
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static void initialize(Config config) {
 | 
			
		||||
		if (initialized) throw new IllegalStateException("EnvoyLog is already initialized");
 | 
			
		||||
		if (initialized)
 | 
			
		||||
			throw new IllegalStateException("EnvoyLog is already initialized");
 | 
			
		||||
 | 
			
		||||
		// Remove default console handler
 | 
			
		||||
		LogManager.getLogManager().reset();
 | 
			
		||||
 | 
			
		||||
		// Configure log file
 | 
			
		||||
		final File logFile = new File(config.getHomeDirectory(),
 | 
			
		||||
				"log/" + DateTimeFormatter.ofPattern("yyyy-MM-dd--hh-mm").format(LocalDateTime.now()) + ".log");
 | 
			
		||||
			"log/" + DateTimeFormatter.ofPattern("yyyy-MM-dd--hh-mm").format(LocalDateTime.now())
 | 
			
		||||
				+ ".log");
 | 
			
		||||
		logFile.getParentFile().mkdirs();
 | 
			
		||||
 | 
			
		||||
		// Configure formatting
 | 
			
		||||
		// Sample log entry: [2020-06-13 16:50:26] [INFORMATION]
 | 
			
		||||
		// [envoy.client.ui.Startup] Closing connection...
 | 
			
		||||
		System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$-7s] [%3$s] %5$s %6$s%n");
 | 
			
		||||
		System.setProperty("java.util.logging.SimpleFormatter.format",
 | 
			
		||||
			"[%1$tF %1$tT] [%4$-7s] [%3$s] %5$s %6$s%n");
 | 
			
		||||
		final SimpleFormatter formatter = new SimpleFormatter();
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
@@ -69,20 +71,22 @@ public final class EnvoyLog {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Configures all loggers that are contained within the hierarchy of a specific
 | 
			
		||||
	 * path to use the console and file handlers.
 | 
			
		||||
	 * Configures all loggers that are contained within the hierarchy of a specific path to use the
 | 
			
		||||
	 * console and file handlers.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param path the path to the loggers to configure
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private static void attach(String path) {
 | 
			
		||||
		if (!initialized) throw new IllegalStateException("EnvoyLog is not initialized");
 | 
			
		||||
		if (!initialized)
 | 
			
		||||
			throw new IllegalStateException("EnvoyLog is not initialized");
 | 
			
		||||
 | 
			
		||||
		// Get root logger
 | 
			
		||||
		final Logger logger = Logger.getLogger(path);
 | 
			
		||||
 | 
			
		||||
		// Add handlers
 | 
			
		||||
		if (fileHandler != null) logger.addHandler(fileHandler);
 | 
			
		||||
		if (fileHandler != null)
 | 
			
		||||
			logger.addHandler(fileHandler);
 | 
			
		||||
		logger.addHandler(consoleHandler);
 | 
			
		||||
 | 
			
		||||
		// Delegate logger level filtering to the handlers
 | 
			
		||||
@@ -90,12 +94,14 @@ public final class EnvoyLog {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Creates a logger for a specified class, which output will be displayed inside
 | 
			
		||||
	 * the console and written to the log file.
 | 
			
		||||
	 * Creates a logger for a specified class, which output will be displayed inside the console and
 | 
			
		||||
	 * written to the log file.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param logClass the class in which the logger is used
 | 
			
		||||
	 * @return the created logger
 | 
			
		||||
	 * @since Envoy Common v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static Logger getLogger(Class<?> logClass) { return Logger.getLogger(logClass.getCanonicalName()); }
 | 
			
		||||
	public static Logger getLogger(Class<?> logClass) {
 | 
			
		||||
		return Logger.getLogger(logClass.getCanonicalName());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,9 @@ public final class SerializationUtils {
 | 
			
		||||
	 * @return a byte array of length 4
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; }
 | 
			
		||||
	public static byte[] intToBytes(int n) {
 | 
			
		||||
		return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n };
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Converts four bytes in byte array to an integer
 | 
			
		||||
@@ -30,8 +32,9 @@ public final class SerializationUtils {
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static int bytesToInt(byte[] bytes, int offset) {
 | 
			
		||||
		return (bytes[offset] & 0xFF) << 24 | (bytes[offset + 1] & 0xFF) << 16 | (bytes[offset + 2] & 0xFF) << 8
 | 
			
		||||
				| (bytes[offset + 3] & 0xFF) << 0;
 | 
			
		||||
		return (bytes[offset] & 0xFF) << 24 | (bytes[offset + 1] & 0xFF) << 16
 | 
			
		||||
			| (bytes[offset + 2] & 0xFF) << 8
 | 
			
		||||
			| (bytes[offset + 3] & 0xFF) << 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -41,14 +44,14 @@ public final class SerializationUtils {
 | 
			
		||||
	 * @param file            the file to deserialize from
 | 
			
		||||
	 * @param serializedClass the class of the object to deserialize
 | 
			
		||||
	 * @return the deserialized object
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the
 | 
			
		||||
	 *                                object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked
 | 
			
		||||
	 *                                to a class
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked to a class
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static <T extends Serializable> T read(File file, Class<T> serializedClass) throws IOException, ClassNotFoundException {
 | 
			
		||||
		if (file == null) throw new NullPointerException("File is null");
 | 
			
		||||
	public static <T extends Serializable> T read(File file, Class<T> serializedClass)
 | 
			
		||||
		throws IOException, ClassNotFoundException {
 | 
			
		||||
		if (file == null)
 | 
			
		||||
			throw new NullPointerException("File is null");
 | 
			
		||||
		return read(new FileInputStream(file), serializedClass);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -59,13 +62,12 @@ public final class SerializationUtils {
 | 
			
		||||
	 * @param bytes           the array in which the serialized object is stored
 | 
			
		||||
	 * @param serializedClass the class of the serialized object
 | 
			
		||||
	 * @return the deserialized object
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the
 | 
			
		||||
	 *                                object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked
 | 
			
		||||
	 *                                to a class
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked to a class
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static <T extends Serializable> T read(byte[] bytes, Class<T> serializedClass) throws IOException, ClassNotFoundException {
 | 
			
		||||
	public static <T extends Serializable> T read(byte[] bytes, Class<T> serializedClass)
 | 
			
		||||
		throws IOException, ClassNotFoundException {
 | 
			
		||||
		return read(new ByteArrayInputStream(bytes), serializedClass);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -74,16 +76,14 @@ public final class SerializationUtils {
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param <T>             the type of the serialized object
 | 
			
		||||
	 * @param in              the {@link InputStream} of a serialized Object
 | 
			
		||||
	 * @param serializedClass the object type to convert the deserialized object
 | 
			
		||||
	 *                        into
 | 
			
		||||
	 * @param serializedClass the object type to convert the deserialized object into
 | 
			
		||||
	 * @return the deserialized object
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the
 | 
			
		||||
	 *                                object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked
 | 
			
		||||
	 *                                to a class
 | 
			
		||||
	 * @throws IOException            if something failed while deserializing the object
 | 
			
		||||
	 * @throws ClassNotFoundException if the deserialized object can not be linked to a class
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static <T extends Serializable> T read(InputStream in, Class<T> serializedClass) throws IOException, ClassNotFoundException {
 | 
			
		||||
	public static <T extends Serializable> T read(InputStream in, Class<T> serializedClass)
 | 
			
		||||
		throws IOException, ClassNotFoundException {
 | 
			
		||||
		try (ObjectInputStream oin = new ObjectInputStream(in)) {
 | 
			
		||||
			return serializedClass.cast(oin.readObject());
 | 
			
		||||
		}
 | 
			
		||||
@@ -98,8 +98,10 @@ public final class SerializationUtils {
 | 
			
		||||
	 * @since Envoy Common v0.2-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static void write(File file, Object... objs) throws IOException {
 | 
			
		||||
		if (file == null) throw new NullPointerException("File is null");
 | 
			
		||||
		if (objs == null) throw new NullPointerException("Null array passed to serialize");
 | 
			
		||||
		if (file == null)
 | 
			
		||||
			throw new NullPointerException("File is null");
 | 
			
		||||
		if (objs == null)
 | 
			
		||||
			throw new NullPointerException("Null array passed to serialize");
 | 
			
		||||
		if (!file.exists()) {
 | 
			
		||||
			file.getParentFile().mkdirs();
 | 
			
		||||
			file.createNewFile();
 | 
			
		||||
@@ -127,8 +129,8 @@ public final class SerializationUtils {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Serializes an object and writes it into an output stream preceded by 4 bytes
 | 
			
		||||
	 * containing the number of serialized bytes.
 | 
			
		||||
	 * Serializes an object and writes it into an output stream preceded by 4 bytes containing the
 | 
			
		||||
	 * number of serialized bytes.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param obj the object to serialize
 | 
			
		||||
	 * @param out the output stream to serialize to
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
/**
 | 
			
		||||
 * This package contains general useful classes that can be used by both Envoy
 | 
			
		||||
 * Client and Envoy Server Standalone and that could not be assigned to any
 | 
			
		||||
 * other package.
 | 
			
		||||
 * This package contains general useful classes that can be used by both Envoy Client and Envoy
 | 
			
		||||
 * Server Standalone and that could not be assigned to any other package.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/**
 | 
			
		||||
 * This module contains all packages that are used by Envoy Client and Envoy
 | 
			
		||||
 * Server Standalone at the same time.
 | 
			
		||||
 * This module contains all packages that are used by Envoy Client and Envoy Server Standalone at
 | 
			
		||||
 * the same time.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,8 @@ class UserTest {
 | 
			
		||||
		User	user3				= new User(3, "ai");
 | 
			
		||||
		User	user4				= new User(4, "ki", Set.of(user2, user3));
 | 
			
		||||
		User	user5				= new User(5, "ka", Set.of(user2, user3, user4));
 | 
			
		||||
		User	user				= new User(1, "maxi", UserStatus.AWAY, Set.of(user2, user3, user4, user5));
 | 
			
		||||
		User	user				=
 | 
			
		||||
			new User(1, "maxi", UserStatus.AWAY, Set.of(user2, user3, user4, user5));
 | 
			
		||||
		var		serializedUser		= SerializationUtils.writeToByteArray(user);
 | 
			
		||||
		var		deserializedUser	= SerializationUtils.read(serializedUser, User.class);
 | 
			
		||||
		assertEquals(user.getContacts(), deserializedUser.getContacts());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user