Examples of DiscreteInterval


Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }

    public boolean set(long duration, long error) {
        if (error < clock.getGranularity()) return false;
        wasSet = true;
        targetElapsedTime = new DiscreteInterval(duration - error, duration + error);
        return true;
    }
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }

    public DiscreteInterval getTimeRemaining() {
        if (!wasSet) throw new IllegalStateException("cannot compute time remaining without having duration set");
        if (startTime == null) return targetElapsedTime;
        DiscreteInterval diff = targetEndTime.minus(clock.getNanoTime());
        return (diff.getMin() <= 0L) ? new DiscreteInterval(0L,0L) : diff;
    }
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }
   
    @Test
    public void canStartATimerThatHasBeenSet() {
        expect(mockClock.getGranularity()).andReturn(1000L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(3L,4L)).anyTimes();
        replay(mockClock);
        impl.set(40000L,3000L);
        impl.start();
        verify(mockClock);
    }
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }

    @Test
    public void hasNotElapsedIfNotStarted() {
        expect(mockClock.getGranularity()).andReturn(1000L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(3L,4L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,1000L);
        assertFalse(impl.hasElapsed());
    }
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }
   
    @Test
    public void hasNotElapsedIfClockHasNotTicked() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,6L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertFalse(impl.hasElapsed());
        verify(mockClock);
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }
   
    @Test
    public void hasElapsedIfCurrentClockReadingIsWithinTargetRange() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L));
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(1010L,1015L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertTrue(impl.hasElapsed());
        verify(mockClock);
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }
   
    @Test
    public void hasNotElapsedIfCurrentClockReadingIsNotEntirelyWithinTargetRange() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L));
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(900L,1015L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertFalse(impl.hasElapsed());
        verify(mockClock);
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }

    @Test
    public void hasElapsedIfCurrentClockReadingPartiallyExceedsTargetRange() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L));
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(1015L,2000L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertTrue(impl.hasElapsed());
        verify(mockClock);
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }

    @Test
    public void hasElapsedIfCurrentClockReadingCompletelyExceedsTargetRange() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L));
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(2000L,2015L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertTrue(impl.hasElapsed());
        verify(mockClock);
View Full Code Here

Examples of org.fishwife.jrugged.interval.DiscreteInterval

    }
   
    @Test
    public void isNotLateIfCurrentClockReadingIsBeforeTargetRange() {
        expect(mockClock.getGranularity()).andReturn(1L).anyTimes();
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L));
        expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(200L,205L)).anyTimes();
        replay(mockClock);
        impl.set(1000L,100L);
        impl.start();
        assertFalse(impl.isLate());
        verify(mockClock);
View Full Code Here
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.