//File: User.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The User class is used when an instance of a user is created. //The user class also contains a subclass UserMsgBox that //handles messaging between users. //The user class also contains an array of the handles that this //particular user controls. import java.util.Vector; public class User { private String username; private Vector VMHandles = new Vector(5,1); private int handlecount = 0; public boolean isClosing = false; private String curpath; UserMsgBox usrmsgbox = new UserMsgBox(); public User(String name) { username = name; } public void setcurrentPath(String newpath) { curpath = newpath; } public String getcurrentPath() { return curpath; } public String getName() { return username; } public synchronized void addHandle(Handle vmh) { int i; for(i=0;i < VMHandles.size() && ((Handle)VMHandles.get(i)).getID().compareTo(vmh.getID()) != 0;i++); if(i >= VMHandles.size()) { VMHandles.add(vmh); handlecount++; } } public synchronized Object removeHandle(Handle vmh) {// Returns Removed object, if not found returns null int i = 0; try { for(i=0;((Handle)VMHandles.get(i)).getID() != vmh.getID();i++); //Matches Handle ID's } catch(ArrayIndexOutOfBoundsException ex) { return null; } handlecount--; return VMHandles.remove(i); } public int getCount() { return handlecount; } public Handle get(int index) { return ((Handle)VMHandles.get(index)); } public void sendmsg(String msg) { usrmsgbox.newmsg(msg); } public String[] getmsgs() { return usrmsgbox.getmsgs(); } class UserMsgBox { private Vector msgbox = new Vector(5,1); public UserMsgBox() { } void newmsg(String msg) { msgbox.add(msg); } String[] getmsgs() { String[] msgs = new String[msgbox.size()]; for(int i = 0;i < msgs.length;i++) { msgs[i] = (String)msgbox.remove(0); } return msgs; } } }