PhoneBookRecord.java :  » Database-JDBC-Connection-Pool » Space4J » org » space4j » demos » phonebook » Java Open Source

Java Open Source » Database JDBC Connection Pool » Space4J 
Space4J » org » space4j » demos » phonebook » PhoneBookRecord.java
// Space4J(TM) - Object Persistence in RAM
// Copyright (C) 2003 Sergio Oliveira Junior
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
package org.space4j.demos.phonebook;

import java.io.*;
import java.util.*;

/**
 * This is a mutable version of a phone book record.
 * This will illustrate how you can use an Observable to
 * notify the IndexManager about changes, so it can reindex the object.
 */
public class PhoneBookRecord extends Observable implements Serializable {
    
    private int oid = -1;
    private String name = null;
    private String number = null;
    
    public PhoneBookRecord(int oid) {
        super();
        this.oid = oid;
    }
    
    public int hashCode() {
        return oid;
    }
    
    public boolean equals(Object obj) {
        if (obj instanceof PhoneBookRecord) {
            PhoneBookRecord pbr = (PhoneBookRecord) obj;
            if (pbr.oid == this.oid) return true;
        }
        return false;
    }
    
    public void setName(String name) {
        this.name = name;
        setChanged();
        notifyObservers("name");
    }
    
    public void setNumber(String number) {
        this.number = number;
        setChanged();
        notifyObservers("number");
    }
    
    public int getId() {
        return oid;
    }
    
    public String getName() {
        return name;
    }
    
    public String getNumber() {
        return number;
    }
    
    public String toString() {
        return oid + "/" + name + "/" + number;
    }
}

    
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.