package FeiGe;
import java.util.Arrays;
public class CustomerData {
private static int SIZE = 10; // SIZE 数组
private static int COUNT = 0;
private static Customer[] CUSTOMERDATA = new Customer[SIZE];
// 保存用户的信息
public static void save( Customer customer){
// 当时用量count和数组的最大容量size想等,空间用完了,扩容为原大小的两倍
if ( COUNT == SIZE){
CUSTOMERDATA = Arrays.copyOf(CUSTOMERDATA , SIZE*2);
SIZE *= 2;
}
for (int i =0; i<CUSTOMERDATA.length; i++){
if ( null == CUSTOMERDATA[i] ){
CUSTOMERDATA[i] = customer;
COUNT++;
}
}
}
// 查询客户的信息
public static Customer get( String customerId) {
for (Customer c : CUSTOMERDATA){
if ( customerId.equals(c.getCustomerId() ) ){
return c;
}
}
return null;
}
// 重载查询方法
public static Customer get(String customerId , String pwd){
for (int i=0; i<CUSTOMERDATA.length; i++){
if (customerId.equals(CUSTOMERDATA[i] .getCustomerId()) && pwd.equals(CUSTOMERDATA[i].getPwd() ) ){
return CUSTOMERDATA[i];
}
}
return null;
}
}