Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.Serializable;
  4. import java.util.List;
  5.  
  6. import static com.company.TuringConstants.*;
  7.  
  8. public class Command implements Serializable {
  9.  
  10.     private String command;
  11.     private String username;
  12.     private String password;
  13.     private String docName;
  14.     private int section;
  15.     private int numSections;
  16.     private String collaborator;
  17.     private FileAttachment fileAttachment;
  18.  
  19.     public Command(String command, String username) {
  20.         this.command = command;
  21.         this.username = username;
  22.     }
  23.  
  24.     public String getUsername() {
  25.         return username;
  26.     }
  27.  
  28.     public String getPassword() {
  29.         return password;
  30.     }
  31.  
  32.     public String getCommand() {
  33.         return command;
  34.     }
  35.  
  36.     public String getDocName() {
  37.         return docName;
  38.     }
  39.  
  40.     public int getSection() {
  41.         return section;
  42.     }
  43.  
  44.     public String getCollaborator() {
  45.         return collaborator;
  46.     }
  47.  
  48.     public static Command buildLoginCommand(String username, String password) {
  49.         Command command = new Command(COMMAND_LOGIN, username);
  50.         command.password = password;
  51.         return command;
  52.     }
  53.  
  54.     public static Command buildLogoutCommand(String username) {
  55.         return new Command(COMMAND_LOGOUT, username);
  56.     }
  57.  
  58.     public static Command buildListCommand(String username) {
  59.         return new Command(COMMAND_LIST, username);
  60.     }
  61.  
  62.     public static Command buildCreateCommand(String username, String docName, int numSections) {
  63.         Command command = new Command(COMMAND_CREATE, username);
  64.         command.docName = docName;
  65.         command.numSections = numSections;
  66.         return command;
  67.     }
  68.  
  69.     public static Command buildShareCommand(String username, String docName, String collaborator) {
  70.         Command command = new Command(COMMAND_SHARE, username);
  71.         command.docName = docName;
  72.         command.collaborator = collaborator;
  73.         return command;
  74.     }
  75.  
  76.     public static Command buildShowSectionCommand(String username, String docName, int section) {
  77.         Command command = new Command(COMMAND_SHOW_SECTION, username);
  78.         command.docName = docName;
  79.         command.section = section;
  80.         return command;
  81.     }
  82.  
  83.     public static Command buildEditSectionCommand(String username, String docName, int section) {
  84.         Command command = new Command(COMMAND_EDIT_SECTION, username);
  85.         command.docName = docName;
  86.         command.section = section;
  87.         return command;
  88.     }
  89.  
  90.     public static Command buildEndEditSectionCommand(
  91.             String username, String docName, int section, String srcFileAttachment, String dstFileAttachment) {
  92.         Command command = new Command(COMMAND_END_EDIT_SECTION, username);
  93.         command.docName = docName;
  94.         command.section = section;
  95.         command.fileAttachment = new FileAttachment(srcFileAttachment, dstFileAttachment);
  96.         return command;
  97.     }
  98.  
  99.     public static Command buildShowDocumentCommand(String username, String docName) {
  100.         Command command = new Command(COMMAND_SHOW_DOCUMENT, username);
  101.         command.docName = docName;
  102.         return command;
  103.     }
  104.  
  105.     public int getNumSections() {
  106.         return numSections;
  107.     }
  108.  
  109.     public FileAttachment getFileAttachment() {
  110.         return fileAttachment;
  111.     }
  112.  
  113.     public boolean hasFileAttachment() {
  114.         return fileAttachment != null;
  115.     }
  116.  
  117.     public boolean hasEmptyAttachment() {
  118.             return fileAttachment.getSize() > 0;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement