| Home >> All >> com >> sample >> tutorial >> update >> [ database Javadoc ] |
Source code: com/sample/tutorial/update/database/Database.java
1 /* 2 * Database.java 3 * 4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved. 5 * 6 * See the file LICENSE for terms of use. 7 * 8 */ 9 10 package com.sample.tutorial.update.database; 11 12 import java.util.ArrayList; 13 14 /** 15 * Simulates a database of contact records. 16 * 17 * @author Trevor Milne 18 * 19 */ 20 21 public class Database 22 { 23 /** Single instance of database. */ 24 protected static Database singleton = new Database(); 25 26 27 /* Attributes */ 28 29 30 /** Contact records. */ 31 protected ArrayList contacts; 32 33 34 /* Constructors */ 35 36 37 protected Database() 38 { 39 contacts = new ArrayList(); 40 41 contacts.add(new Contact(1, "first A", "last A", "email A")); 42 } 43 44 45 /* Operations */ 46 47 48 public Contact getContact(int contactId) 49 { 50 Contact result = new Contact(); 51 result.setData((Contact)contacts.get(contactId - 1)); 52 53 return result; 54 } 55 56 public void setContact(Contact contact) 57 { 58 Contact update = (Contact)contacts.get(contact.getId() - 1); 59 update.setData(contact); 60 } 61 62 63 /* Singleton */ 64 65 66 public static Database getInstance() 67 { 68 return singleton; 69 } 70 } 71