c408h003.omnieditor
Class OmniEditorBuffer

java.lang.Object
  extended byc408h003.omnieditor.OmniEditorBuffer

public class OmniEditorBuffer
extends java.lang.Object


Constructor Summary
OmniEditorBuffer()
          Constructs a OmniEditorBuffer.
 
Method Summary
 void addFile(int userId, java.lang.String filename, java.lang.String content)
          Adds a file into the editing buffer.
 int find(int userId, int start, java.lang.String target, java.lang.String fileName, boolean forward, boolean caseSensitive)
          Finds a string in a file.
 java.lang.String[] getChanges(int userId, java.lang.String fileName)
          Gets all changes (actions) performed.
 java.lang.String[] getFileContent(int userId, java.lang.String[] fileNames)
          Returns the content of a file in the buffer specified by file ID.
 java.lang.String[] getFileNames()
          Gets all names of the files currently in the buffer.
 boolean isFileOnline(java.lang.String filename)
          Checks whether the file is in the editing buffer.
 boolean isUserOnline(int userId)
          Checks whether the user is registered.
static void main(java.lang.String[] args)
           
 int registerUser()
          Resgisters a user and assign an identification number to him/her.
 void removeFile(File file)
          Removes a file from the buffer.
 void removeFileByName(java.lang.String fileName)
           
 void removeUser(int userId)
          Removes a user from the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OmniEditorBuffer

public OmniEditorBuffer()
Constructs a OmniEditorBuffer.

Method Detail

main

public static void main(java.lang.String[] args)

registerUser

public int registerUser()
Resgisters a user and assign an identification number to him/her.

Returns:
a integer of the user's Id number

removeUser

public void removeUser(int userId)
Removes a user from the buffer. This happens when the user quits. Pre-condition: userId must be loggedIn

Parameters:
userId - the to-be-removed user's id

isUserOnline

public boolean isUserOnline(int userId)
Checks whether the user is registered.

Parameters:
userId - the name or ID of a user
Returns:
true, if the userId is an id number in the user list false, otherwise

isFileOnline

public boolean isFileOnline(java.lang.String filename)
Checks whether the file is in the editing buffer.

Parameters:
filename - the name of a file
Returns:
true, if the file is opened in the buffer false, otherwise

addFile

public void addFile(int userId,
                    java.lang.String filename,
                    java.lang.String content)
Adds a file into the editing buffer.

Parameters:
userId - the id number who's adding file
filename - the name of the file
content - the content of the file
Returns:
the file name assigned by the editor buffer, as a string

getFileContent

public java.lang.String[] getFileContent(int userId,
                                         java.lang.String[] fileNames)
Returns the content of a file in the buffer specified by file ID.

Parameters:
userId - the id number of the user
fileNames - the name of the files whose contents are required
Returns:
the contents of the file, null if file(s) does not exist

find

public int find(int userId,
                int start,
                java.lang.String target,
                java.lang.String fileName,
                boolean forward,
                boolean caseSensitive)
Finds a string in a file.

Parameters:
userId - the id number of the user
start - the position from where we search for the string
target - the target string to be looked for
fileName - the file in which the string should be searched
forward - true if search forwards, false for backwards
caseSensitive - true if need to search case sensitive, false otherwise
Returns:
an object of the current postion

getFileNames

public java.lang.String[] getFileNames()
Gets all names of the files currently in the buffer.

Returns:
a string array of file names

getChanges

public java.lang.String[] getChanges(int userId,
                                     java.lang.String fileName)
Gets all changes (actions) performed.

Parameters:
userId - the user who wants the change of the file
fileName - the name of the file which the changes want to be fetched
Returns:
a string array represents the actions performed need to be updated

removeFile

public void removeFile(File file)
Removes a file from the buffer.

Parameters:
file - the file wants to be removed.

removeFileByName

public void removeFileByName(java.lang.String fileName)