Package threading

Source Code of threading.SearchThread

package threading;

import java.util.Vector;

import nodes.MileStone;

import javax.swing.event.EventListenerList;

import person.Person;

public class SearchThread implements Runnable
{
  private Person person = null;
  private Comparable low;
  private Comparable high;
  private Vector<MileStone> result = null;
  private EventListenerList listeners = new EventListenerList();
  private boolean runningState = true;

  public SearchThread(Person person, Comparable low, Comparable high)
  {
    this.person = person;
    this.low = low;
    this.high = high;
  }

  public void run()
  {
    synchronized (person)
    {
      result = person.lifeHistory.search(low, high);

      for (SearcherListener w : this.listeners
          .getListeners(SearcherListener.class))
      {
        w.foundElement(new FoundElementEvent(this, new Person(person
            .getFirstName(), person.getLastName(), result)));
      }
     
      this.runningState = false;
    }
  }

  public Person getResult()
  {
    return new Person(person.getFirstName(), person.getLastName(), result);
  }

  // add listener to list
  public void addListener(SearcherListener listener)
  {
    this.listeners.add(SearcherListener.class, listener);
  }

  // remove listener from list
  public void removeListener(SearcherListener listener)
  {
    this.listeners.remove(SearcherListener.class, listener);
  }

  public boolean isRunning()
  {
    return runningState;
  }
}
TOP

Related Classes of threading.SearchThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.