📄 agendaimpl.java
字号:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;
public class AgendaImpl extends UnicastRemoteObject implements AgendaInterface{
public AgendaImpl() throws RemoteException{
}
public String register(String userID, String password) throws RemoteException{
//判断用户是否存在
int flag = 0;
System.out.println("invoke function register.");
if(Server.userList.isEmpty()){
User userNew = new User();
userNew.setUserID(userID);
userNew.setPassword(password);
Server.userList.add(userNew);
return "register success";
}
else{
for(Iterator<User> it = Server.userList.iterator(); it.hasNext();){
User userOld = it.next();
if(userID.compareTo(userOld.getUserID()) == 0){
flag = 1;
return "register fail";
}
}
}
if(flag == 0){
User userNew = new User();
userNew.setUserID(userID);
userNew.setPassword(password);
Server.userList.add(userNew);
return "register success";
}
return "hello"; //useful?
}
public String addAgenda(Calendar start, Calendar end, String userInit, String userSched, String password) throws RemoteException{
System.out.println("invoke function addConf.");
int flagT = 1;
if(Server.userList.isEmpty()){
return "Nonexist user initialing the conference";
}
else{
for(Iterator<User> it1 = Server.userList.iterator(); it1.hasNext();){
User userInitL = it1.next();
if(userInit.compareTo(userInitL.getUserID()) == 0 && password.compareTo(userInitL.getPassword()) == 0){
if(!(userInitL.getConfList().isEmpty())){
for(Iterator<Agenda> it2 = userInitL.getConfList().iterator(); it2.hasNext();){
Agenda agenda = it2.next();
if((agenda.getStartD().compareTo(start) <= 0 && agenda.getEndD().compareTo(start) >= 0) || (agenda.getStartD().compareTo(end) <= 0 && agenda.getEndD().compareTo(end) >= 0)){
flagT = 0;
break;
}
}
}
if(flagT == 1){
for(Iterator<User> it3 = Server.userList.iterator(); it3.hasNext();){
User userSchedL = it3.next();
if(userSched.compareTo(userSchedL.getUserID()) == 0){
if(userSchedL.getConfList().isEmpty()){
Agenda agendaNew = new Agenda();
agendaNew.setEndD(end);
agendaNew.setStartD(start);
agendaNew.setUserInit(userInit);
agendaNew.setUserSched(userSched);
userInitL.addAgenda(agendaNew);
userSchedL.addAgenda(agendaNew);
return "Add conf success";
}
for(Iterator<Agenda> it4 = userSchedL.getConfList().iterator(); it4.hasNext();){
Agenda conf = it4.next();
if(!((conf.getStartD().compareTo(start) <= 0 && conf.getEndD().compareTo(start) >= 0) || (conf.getStartD().compareTo(end) <= 0 && conf.getEndD().compareTo(end) >= 0))){
Agenda agendaNew = new Agenda();
agendaNew.setEndD(end);
agendaNew.setStartD(start);
agendaNew.setUserInit(userInit);
agendaNew.setUserSched(userSched);
userInitL.addAgenda(agendaNew);
userSchedL.addAgenda(agendaNew);
return "Add conf success";
}
}
}
}
}
}
}
}
return "Add conf fail";
}
public List<Agenda> checkAgenda(int flagC, Calendar start, Calendar end, String userID) throws RemoteException{
List<Agenda> retList = new ArrayList<Agenda>();
System.out.println("invoke function checkConf.");
switch(flagC){
case 1:
if(Server.userList.isEmpty()){
Agenda temp = new Agenda();
temp.setconfID(0);
retList.add(temp);
}
else{
for(Iterator<User> it = Server.userList.iterator(); it.hasNext();){
User userL = it.next();
if(userID.compareTo(userL.getUserID()) == 0){
return userL.getConfList();
}
}
}
return retList;
default:
if(Server.userList.isEmpty()){
Agenda temp = new Agenda();
temp.setconfID(0);
retList.add(temp);
}
else{
for(Iterator<User> it1 = Server.userList.iterator(); it1.hasNext();){
User userInitL = it1.next();
if(userID.compareTo(userInitL.getUserID()) == 0){
for(Iterator<Agenda> it2 = userInitL.getConfList().iterator(); it2.hasNext();){
Agenda conf = it2.next();
if(conf.getStartD().compareTo(start) >= 0 && conf.getEndD().compareTo(end) <= 0){
retList.add(conf);
}
}
}
}
}
return retList;
}
}
public String DeleteAgenda(int confID, String userID, String password) throws RemoteException{
String userSched = new String();
System.out.println("invoke function deleteConf.");
if(Server.userList.isEmpty()){
return "No user exist";
}
else{
for(Iterator<User> it = Server.userList.iterator(); it.hasNext();){
User userInitL = it.next();
if(userID.compareTo(userInitL.getUserID()) == 0 && password.compareTo(userInitL.getPassword()) == 0){
if(!(userInitL.getConfList().isEmpty())){
for(Iterator<Agenda> it2 = userInitL.getConfList().iterator(); it2.hasNext();){
Agenda conf = it2.next();
if(conf.getConfID() == confID){
userSched = conf.getUserSched();
userInitL.getConfList().remove(conf); //There is a problem here. shallow clone?
break;
}
}
}
else{
return ("The" + userID + "has no conference");
}
break;
}
}
}
return "Delete fail";
}
public String ClearAgenda(String userID,String password,int sum) throws RemoteException{
String judge = new String();
System.out.println("invoke function clearConf.");
if(Server.userList.isEmpty()){
return "No user exist";
}
else{
for(int i = 1; i <= sum; i++){
judge = DeleteAgenda(i, userID, password);
}
return "Clear complete";
/*if(judge.compareTo("Delete fail") == 0){
return "Clear fail";
}
else{
return "Clear success";
}*/
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -