Skip to content

Commit

Permalink
Added convenience method to create a tool-context with two time markers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawi committed Jan 10, 2012
1 parent 13a7997 commit 151c942
Showing 1 changed file with 20 additions and 2 deletions.
Expand Up @@ -249,9 +249,9 @@ public static DataContainer createMockDataContainer( final int aDataSize, final
public static ToolContext createToolContext( final AcquisitionResult aData, final int aStartSampleIdx,
final int aLastSampleIdx )
{
final Integer size = Integer.valueOf( aLastSampleIdx - Math.max( 0, aStartSampleIdx ) );
final Integer first = Integer.valueOf( Math.max( 0, aStartSampleIdx ) );
final Integer last = Integer.valueOf( aLastSampleIdx );
final Integer last = Integer.valueOf( Math.min( aLastSampleIdx, aData.getValues().length - 1 ) );
final Integer size = Integer.valueOf( last.intValue() - first.intValue() );

// Do NOT use Mockito#mock for this; it appears to slow things down *really*
// much...
Expand Down Expand Up @@ -301,6 +301,24 @@ public int getStartSampleIndex()
};
}

/**
* Creates a (mocked) tool context starting and ending at the given sample
* indexes.
*
* @param aStartSampleIdx
* the starting sample index of the returned tool context;
* @param aLastSampleIdx
* the ending sample index of the returned tool context.
* @return a mocked tool context, never <code>null</code>.
*/
public static ToolContext createToolContext( final AcquisitionResult aData, final long aStartTimestamp,
final long aLastTimestamp )
{
int startIdx = aData.getSampleIndex( aStartTimestamp );
int endIdx = aData.getSampleIndex( aLastTimestamp );
return createToolContext( aData, startIdx, endIdx );
}

/**
* Creates a (mocked) tool context starting at the given sample index and
* ending at the last available sample index.
Expand Down

0 comments on commit 151c942

Please sign in to comment.