home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 4.3 KB | 181 lines |
- /* ****************************************************************
- ** @(#)RoloApi.java 1.2 97/05/27
- **
- ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
- **
- ** ****************************************************************
- */
-
- import java.io.*;
- import java.util.Vector;
- import java.util.StringTokenizer;
-
- public class RoloApi {
-
- protected SortedList sl;
- public RoloEntry recurrent;
- public int current;
- public File filename;
- public boolean saved;
-
- private Vector search;
-
- public RoloApi() {
- sl = new SortedList();
- filename=null;
- saved=false;
- current= -1;
- recurrent=null;
- }
-
- public void open(File file) {
- sl = new SortedList();
- sl.load(file, RoloEntry.roloobj);
- filename=file;
- saved=true;
- current=0;
- updateCurrent();
- }
-
- public void updateCurrent() {
- recurrent=getEntry(current);
- }
-
- public void save() {
- sl.save(filename);
- }
-
- public RoloEntry getEntry(int key) {
- RoloEntry rolo;
- if (key== -1 || key>=getSize())
- return new RoloEntry();
- rolo = (RoloEntry)sl.getItem(key);
- return rolo;
- }
-
- public int addEntry( String name, String address1, String address2,
- String phone, String email, String other) {
- recurrent=new RoloEntry( name, address1, address2, phone, email, other);
- return putEntry( recurrent );
- }
-
- public int putEntry(RoloEntry rolo) {
- RoloEntry r=(RoloEntry)rolo.clone();
- return sl.putItem(r.name, new ListItem(r.name,r));
- }
-
- public void showEntry(int i) {
- current=i;
- updateCurrent();
- }
-
- public void removeEntry(int key) {
- sl.removeItem(key);
- }
-
- public int getSize() {
- return sl.size();
- }
-
- public String[] getAllKeys() {
- String[] keys;
- keys = sl.getKeys();
- return keys;
- }
-
- private void addparam(int sel,String contains) {
- int i;
- String s;
- StringTokenizer st=new StringTokenizer( contains );
- while (st.hasMoreTokens()) {
- s=st.nextToken().toLowerCase();
- if (sel==0) {
- for(i=0;i<6;i++)
- ((Vector)search.elementAt(i)).addElement(s);
- } else {
- ((Vector)search.elementAt(sel-1)).addElement(s);
- }
- }
- }
-
- public Vector searchIt(int cat, String searchStr) {
- int ientry,isearch;
- String match;
- boolean found;
- Vector foundindex=new Vector();
-
- search=new Vector(6);
- for(int i=0;i<7;i++) {
- search.addElement(new Vector());
- }
-
- addparam(cat,searchStr);
- RoloEntry entry;
- for (ientry=0;ientry<getSize();ientry++) {
- found=false;
- entry=getEntry( ientry );
-
- for (isearch=0;isearch<((Vector)search.elementAt(0)).size();isearch++) {
- match=(String)((Vector)search.elementAt(0)).elementAt(isearch);
- if (entry.name.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
-
- if (found==false) {
- for (isearch=0;isearch<((Vector)search.elementAt(1)).size();isearch++) {
- match=(String)((Vector)search.elementAt(1)).elementAt(isearch);
- if (entry.address1.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
- }
-
- if (found==false) {
- for (isearch=0;isearch<((Vector)search.elementAt(2)).size();isearch++) {
- match=(String)((Vector)search.elementAt(2)).elementAt(isearch);
- if (entry.address2.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
- }
- if (found==false) {
- for (isearch=0;isearch<((Vector)search.elementAt(3)).size();isearch++) {
- match=(String)((Vector)search.elementAt(3)).elementAt(isearch);
- if (entry.phone.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
- }
-
- if (found==false) {
- for (isearch=0;isearch<((Vector)search.elementAt(4)).size();isearch++) {
- match=(String)((Vector)search.elementAt(4)).elementAt(isearch);
- if (entry.email.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
- }
- if (found==false) {
- for (isearch=0;isearch<((Vector)search.elementAt(5)).size();isearch++) {
- match=(String)((Vector)search.elementAt(5)).elementAt(isearch);
- if (entry.other.toLowerCase().indexOf(match)!=(-1)) {
- found=true;
- break;
- }
- }
- }
- if (found==true) {
- foundindex.addElement(new Integer(ientry));
- }
- }
- return foundindex;
- }
-
- }
-