package quiz5;
import java.util.ArrayList;
public class MemberDAOImpl implements IMemberDAO {
ArrayList<MemberDTO> members = new ArrayList<>();
@Override
public int getIdx(String id) {
int idx = -1;
for (MemberDTO member : members) {
if (member.getId().equals(id)) {
idx = members.indexOf(member);
return idx;
}
}
return idx;
}
@Override
public void insert(MemberDTO member) {
members.add(member);
}
@Override
public MemberDTO selectId(String id) {
MemberDTO tmp = new MemberDTO();
for (MemberDTO cmp : members) {
if (cmp.getId().equals(id)) {
tmp.setId(cmp.getId());
tmp.setName(cmp.getName());
tmp.setPw(cmp.getPw());
}
}
return tmp;
}
@Override
public void delete(MemberDTO deleteMember) {
int idx = this.getIdx(deleteMember.getId());
if (idx == -1) {
System.out.println(deleteMember.getId() + "는 존재하지 않는 정보입니다.");
return;
}
System.out.println("삭제가 완료되었습니다.");
members.remove(idx);
}
@Override
public ArrayList<MemberDTO> selectAll() {
return members;
}
@Override
public void update(int index, MemberDTO updateMember) {
members.get(index).setPw(updateMember.getPw());
}
}
'Class > 220801' 카테고리의 다른 글
Class 예제(2_MemberDTO) (0) | 2022.08.01 |
---|---|
Class 예제(2_MemberDAOInterface) (0) | 2022.08.01 |
Class 예제(2_Service) (0) | 2022.08.01 |
Class 예제(2_ServiceInterface) (0) | 2022.08.01 |
Class 예제(2_Main) (0) | 2022.08.01 |