This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/database/LocalDb.java

120 lines
2.9 KiB
Java
Raw Normal View History

package envoy.client.database;
import java.util.*;
import envoy.client.Chat;
import envoy.data.IdGenerator;
import envoy.data.User;
/**
* Stores information about the current {@link User} and their {@link Chat}s.
* For message ID generation a {@link IdGenerator} is stored as well.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>LocalDb.java</strong><br>
* Created: <strong>3 Feb 2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy v0.3-alpha
*/
public abstract class LocalDb {
protected User user;
protected Map<String, User> users = new HashMap<>();
protected List<Chat> chats = new ArrayList<>();
protected IdGenerator idGenerator;
/**
* Initializes a storage space for a user-specific list of chats.
*
* @since Envoy v0.3-alpha
*/
public void initializeUserStorage() {}
/**
* Stores all users. If the client user is specified, their chats will be stored
* as well. The message id generator will also be saved if present.
*
* @throws Exception if the saving process failed
* @since Envoy v0.3-alpha
*/
public void save() throws Exception {}
/**
* Loads all user data.
*
* @throws Exception if the loading process failed
* @since Envoy v0.3-alpha
*/
public void loadUsers() throws Exception {}
/**
* Loads all chat data of the client user.
*
* @throws Exception if the loading process failed
* @since Envoy v0.3-alpha
*/
public void loadChats() throws Exception {}
/**
* Loads the ID generator. Any exception thrown during this process is ignored.
*
* @since Envoy v0.3-alpha
*/
public void loadIdGenerator() {}
/**
* @return a {@code Map<String, User>} of all users stored locally with their
* user names as keys
* @since Envoy v0.2-alpha
*/
public Map<String, User> getUsers() { return users; }
/**
* @param users the users to set
*/
public void setUsers(Map<String, User> users) { this.users = users; }
/**
* @return all saved {@link Chat} objects that list the client user as the
* sender
* @since Envoy v0.1-alpha
**/
public List<Chat> getChats() { return chats; }
/**
* @param chats the chats to set
*/
public void setChats(List<Chat> chats) { this.chats = chats; }
/**
* @return the {@link User} who initialized the local database
* @since Envoy v0.2-alpha
*/
public User getUser() { return user; }
/**
* @param user the user to set
* @since Envoy v0.2-alpha
*/
public void setUser(User user) { this.user = user; }
/**
* @return the message ID generator
* @since Envoy v0.3-alpha
*/
public IdGenerator getIdGenerator() { return idGenerator; }
/**
* @param idGenerator the message ID generator to set
* @since Envoy v0.3-alpha
*/
public void setIdGenerator(IdGenerator idGenerator) { this.idGenerator = idGenerator; }
/**
* @return {@code true} if an {@link IdGenerator} is present
* @since Envoy v0.3-alpha
*/
public boolean hasIdGenerator() { return idGenerator != null; }
}