FileDocCategorySizeDatePackage
TimeInterval.javaAPI DocphoneME MR2 API (J2ME)6172Wed May 02 18:00:34 BST 2007com.sun.perseus.model

TimeInterval

public final class TimeInterval extends Object
A TimeInterval models a specific 'run' of a TimedElement. It has a begin and end time and a list of IntervalTimeInstances depending on its begin or end time.
version
$Id: TimeInterval.java,v 1.3 2006/04/21 06:39:30 st125089 Exp $

Fields Summary
Time
begin
The interval's begin time.
Time
end
The interval's end time
Time
lastDur
The end of the last simple duration
Vector
beginDependents
The list of dependent begin time instances. Contains IntervalTimeInstance objects.
Vector
endDependents
The list of end dependents. Contains IntervalTimeInstance objects.
Constructors Summary
TimeInterval(Time begin, Time end)
Creates a new interval with a specific begin and end times.

param
begin the initial begin time. This time should be resolved. Otherwise, an IllegalStateException is thrown. Should not be null.
param
end the initial end time. Should not be null.

        if (begin == null || end == null) {
            throw new NullPointerException();
        }

        setBegin(begin);
        setEnd(end);
    
Methods Summary
voidaddDependent(IntervalTimeInstance timeInstance)
Adds a new IntervalTimeInstance dependent. If timeInstance synchronizes on begin, it is added to the beginDependent list. Otherwise, it is added to the endDependent list.

param
timeInstance the new IntervalTimeInstance. If null, throws a NullPointerException.

        Vector dependents = beginDependents;
        if (!timeInstance.isBeginSync) {
            dependents = endDependents;
        }

        if (dependents == null) {
            dependents = new Vector(1);
            if (timeInstance.isBeginSync) {
                beginDependents = dependents;
            } else {
                endDependents = dependents;
            }
        }

        dependents.addElement(timeInstance);
    
voidprune()
Called when the interval is pruned from a timed element. The result is that all dependent time instances should be removed from their respective instance lists.

        int n = beginDependents != null ? beginDependents.size() : 0;
        for (int i = n - 1; i >= 0; i--) {
            IntervalTimeInstance iti = 
                (IntervalTimeInstance) beginDependents.elementAt(i);
            iti.timedElement.removeTimeInstance(iti);
            iti.dispose();
        }

        n = endDependents != null ? endDependents.size() : 0;
        for (int i = n - 1; i >= 0; i--) {
            IntervalTimeInstance iti = 
                (IntervalTimeInstance) endDependents.elementAt(i);
            iti.timedElement.removeTimeInstance(iti);
            iti.dispose();
        }
    
voidremoveDependent(IntervalTimeInstance timeInstance)
Removes the input IntervalTimeInstance dependent.

param
timeInstance the IntervalTimeInstance to remove from this interval. Throws a NullPointerException if null.

        Vector dependents = beginDependents;
        if (!timeInstance.isBeginSync) {
            dependents = endDependents;
        }

        if (dependents == null) {
            return;
        }

        dependents.removeElement(timeInstance);
    
voidsetBegin(Time newBegin)
Updates the begin time. Note that an unresolved begin time is illegal. Trying to set one will cause an exception to be thrown (an IllegalArgumentException). Dependent end conditions are notified of begin time change.

param
newBegin the new begin time.

        if (!newBegin.isResolved()) {
            throw new IllegalArgumentException("" + newBegin);
        }

        this.begin = newBegin;
        if (beginDependents != null) {
            int n = beginDependents.size();
            for (int i = 0; i < n; i++) {
                ((IntervalTimeInstance) beginDependents.elementAt(i))
                    .onIntervalUpdate();
            }
        }
    
voidsetEnd(Time newEnd)
Updates the end time. Dependent end conditions are notified of the end time change. A

param
newEnd the new end time.

        if (newEnd == null) {
            throw new NullPointerException();
        }
        this.end = newEnd;
        if (endDependents != null) {
            int n = endDependents.size();
            for (int i = 0; i < n; i++) {
                ((IntervalTimeInstance) endDependents.elementAt(i))
                    .onIntervalUpdate();
            }
        }