// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   ResultSet.java

package lt.ktu.gmj.ui;

import java.util.Vector;
import lt.ktu.gmj.*;

// Referenced classes of package lt.ktu.gmj.ui:
//            ResultNotifyer

public class ResultSet extends ResultNotifyer
    implements ResultLogger
{

    public void startLog()
    {
        lastResult = new Result();
        log.removeAllElements();
        progressLog.removeAllElements();
        progress = 1.7976931348623157E+308D;
        minValue = 1.7976931348623157E+308D;
        maxValue = (-1.0D / 0.0D);
        fireLogStarted();
    }

    public void dispose()
    {
        fireLogDisposed();
    }

    public void setResult(Result result)
    {
        lastResult = result;
        progressLog.addElement(new Result(method.iterations(), result.point, result.value));
        fireFinalResult();
    }

    public synchronized void blockOn(Object obj)
    {
        blockingMonitor = obj;
    }

    public synchronized void resume()
    {
        blockingMonitor = null;
        notify();
    }

    public synchronized void log(Result result)
    {
        lastResult = result;
        log.addElement(result);
        if (result.value < minValue)
            minValue = result.value;
        if (result.value > maxValue)
            maxValue = result.value;
        if (result.value < progress)
        {
            progress = result.value;
            progressLog.addElement(result);
            fireNewProgressResult();
        }
        fireNewResult();
        Thread.yield();
        if (blockingMonitor != null)
        {
            synchronized (blockingMonitor)
            {
                blockingMonitor.notify();
            }
            if (Thread.interrupted())
                throw new lt.ktu.gmj.ResultLogger.AbortedError();
            try
            {
                wait();
            }
            catch (InterruptedException interruptedexception)
            {
                throw new lt.ktu.gmj.ResultLogger.AbortedError();
            }
        }
    }

    public synchronized Result logAt(int i)
    {
        return (Result)log.elementAt(i);
    }

    public Result lastResult()
    {
        return lastResult;
    }

    public synchronized int resultCount()
    {
        return log.size();
    }

    public synchronized Result resultAt(int i)
    {
        return (Result)log.elementAt(i);
    }

    public synchronized int progressResultCount()
    {
        return progressLog.size();
    }

    public synchronized Result progressResultAt(int i)
    {
        return (Result)progressLog.elementAt(i);
    }

    public Task task()
    {
        return task;
    }

    public Method method()
    {
        return method;
    }

    public double minValue()
    {
        return minValue;
    }

    public double maxValue()
    {
        return maxValue;
    }

    public ResultSet(Method method1, Task task1)
    {
        log = new Vector(1000, 1000);
        progressLog = new Vector(1000, 1000);
        blockingMonitor = null;
        method = method1;
        task = task1;
        startLog();
    }

    protected Method method;
    protected Task task;
    protected Result lastResult;
    protected Vector log;
    protected Vector progressLog;
    protected double progress;
    protected double minValue;
    protected double maxValue;
    Object blockingMonitor;
}
