📄 userdata.java
字号:
package agendaServer.systemDatabase;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Iterator;
import commonResource.Person;
/**
* 用户管理的数据层,提供用户资料的管理和注册
* @author Crise.Lee
* @version 1.0
*/
public class UserData {
static ArrayList<Person> userDatas=new ArrayList<Person>();
static ArrayList<Integer> numlist=new ArrayList<Integer>();
/**
* 注册一个用户
* @param person
* @return
* @throws RemoteException
* @throws Exception
*/
public Boolean addUser(Person person) throws RemoteException
{
/** */ System.out.println(" 在UserDatabase中执行添加用户");
// int userNum=0;
if(!notExist(person))
{
///** */ System.out.println("error: User have exist");
throw new RemoteException("错误:此用户已经在系统中注册");
}
// //维护用户内部标识的唯一
// if(numlist.size()!=0)
// {
// userNum=numlist.get(0);
// numlist.remove(0);
// }else
// {
// //标识从1开始
// userNum=userDatas.size()+1;
// }
// person.setNum(userNum);
userDatas.add(person);
System.out.println("当前已有 "+userDatas.size()+"个人注册!");
System.out.println("Register success");
System.out.println();
return true;
}
/**
* 检查此用户是否已经注册,如果不存在返回true,否则返回false。
* @param name
* @return
*/
public Boolean notExist(Person person)
{
Person userExist=null;
// System.out.println("int the noExist person="+person.getName());
Iterator<Person> iterator=userDatas.iterator();
while(iterator.hasNext())
{
userExist=iterator.next();
///** */ System.out.println("int the while p.name="+userExist.getName());
if(userExist.getName().equalsIgnoreCase(person.getName()))
{
///** */ System.out.println("该用户已经存在。。"+person.getName());
return false;
}
//if(iterator.next().getName().equalsIgnoreCase(person.getName()));
}
return true;
}
public Person getPerson(String userName)
{
Person person=null;
Iterator<Person> iterator=userDatas.iterator();
while(iterator.hasNext())
{
person=iterator.next();
if(person.getName().equals(userName))
{
///** */ System.out.println("in getPerson 该用户已经找到"+person.getName());
return person;
}
}
return null;
}
public int getUserID(Person person)
{
return person.getNum();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -