src\com\groundside\jsf\Neighbors.java
src\com\groundside\jsf\Neighbors.java
06-Apr-2005 11:48:13
1 package com.groundside.jsf;
2
3 import java.util.ArrayList;
4 public class Neighbors
5 {
6
7 ArrayList _contacts = new ArrayList();
8 int _maxContactId;
9
10 public Neighbors()
11 {
12 _contacts.add(new Contact(1,"Fred","Flintstone",35));
13 _contacts.add(new Contact(2,"Wilma","Flintstone",32));
14 _contacts.add(new Contact(3,"Barney","Rubble",33));
15 _contacts.add(new Contact(4,"Betty","Rubble",33));
16 _maxContactId = 4;
17 }
18
19
20 public void setContacts(ArrayList contacts)
21 {
22 _contacts = contacts;
23 }
24
25
26 public ArrayList getContacts()
27 {
28 return _contacts;
29 }
30
31 public void updateContact(Contact updatedContact)
32 {
33 int targetContact = updatedContact.getContactId();
34
35 if (targetContact == 0)
36 {
37 addContact(updatedContact);
38
39 }
40 else
41 {
42 for (int i = 0 ;i < _contacts.size() ;i++ )
43 {
44 Contact contact = (Contact)_contacts.get(i);
45 if (contact.getContactId() == updatedContact.getContactId())
46 {
47 _contacts.set(i,updatedContact);
48 return;
49 }
50 }
51 }
52 }
53
54 public void addContact(Contact newContact)
55 {
56 newContact.setContactId(++_maxContactId);
57 _contacts.add(newContact);
58 }
59
60 public void deleteContact(int contactId)
61 {
62 for (int i = 0 ;i < _contacts.size() ;i++ )
63 {
64
65 Contact contact = (Contact)_contacts.get(i);
66 if (contact.getContactId() == contactId)
67 {
68 _contacts.remove(i);
69 return;
70 }
71 }
72 }
73 }
|