本文整理了Java中nl.lxtreme.ols.util.NumberUtils
类的一些代码示例,展示了NumberUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NumberUtils
类的具体详情如下:
包路径:nl.lxtreme.ols.util.NumberUtils
类名称:NumberUtils
[英]Provides some utility methods for parsing numbers, etc.
[中]提供一些解析数字等的实用方法。
代码示例来源:origin: jawi/ols
/**
* Parses the given text as an integer, avoiding runtime exceptions.
*
* @param aText
* the text to parse as an integer, can be <code>null</code> or
* empty.
* @return the numeric representation of the given text, or -1 if the text
* could not be parsed correctly as integer.
* @see #safeParseInt(String, int)
*/
public static int safeParseInt( final String aText )
{
return safeParseInt( aText, -1 );
}
代码示例来源:origin: jawi/ols
/**
* Calculates the percentage for the given value in the range denoted by the
* given lower and upper bounds.
*
* @param aValue
* the value;
* @param aLowerBound
* the lower bound of the range;
* @param aUpperBound
* the upper bound of the range.
* @return the percentage (= value * 100.0 / range).
*/
public static int getPercentage( final int aValue, final int aLowerBound, final int aUpperBound )
{
int range;
int value = aValue;
if ( aLowerBound > aUpperBound )
{
range = aLowerBound - aUpperBound;
value = Math.max( 0, value - aUpperBound );
}
else
{
range = aUpperBound - aLowerBound;
value = Math.max( 0, value - aLowerBound );
}
return getPercentage( value, range );
}
代码示例来源:origin: jawi/ols
/**
* Provides a "smart" integer parsing routine that allows (decimal) numbers in
* string form with all kind of trailing characters to be parsed into an
* integer. Some trailing characters are understood as being part of the
* number, like "k" to denote a value in thousands, or "m" to denote a value
* in millions.
* <p>
* Characters recognized are: "k" and "M" to denote units of 1024, 1024*1024.
* </p>
*
* @param aText
* the text to parse into an integer value, cannot be
* <code>null</code>.
* @return the integer value part of the given text, or 0 if the text couldn't
* be parsed.
*/
public static int smartParseInt( final String aText )
{
return smartParseInt( aText, 0 );
}
代码示例来源:origin: jawi/ols
/**
* Converts the given value into a desired bit order.
*
* @param aValue
* the value to convert;
* @param aBitCount
* the number of bits that are supposed to be in the given value;
* @param aBitOrder
* the desired bit order.
* @return the converted value.
*/
public static int convertBitOrder( final int aValue, final int aBitCount, final BitOrder aBitOrder )
{
if ( ( aBitCount <= 0 ) || ( aBitCount > 32 ) )
{
throw new IllegalArgumentException( "Bit count cannot be zero, negative or beyond 32-bits!" );
}
// We already have the most significant bit first, convert only if the bit
// order is LSB first...
if ( aBitOrder == BitOrder.MSB_FIRST )
{
return ( aValue & getBitMask( aBitCount ) );
}
return reverseBits( aValue, aBitCount );
}
代码示例来源:origin: jawi/ols
if ( isPowerOfTwo( aBitCount ) )
int mask = getBitMask( aBitCount );
while ( ( s >>= 1 ) > 0 )
代码示例来源:origin: jawi/ols
size = safeParseInt( instrValue );
rate = safeParseInt( instrValue );
channels = safeParseInt( instrValue );
enabledChannels = safeParseInt( instrValue );
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
代码示例来源:origin: jawi/ols
size = safeParseInt( instrValue );
rate = safeParseInt( instrValue );
channels = safeParseInt( instrValue );
enabledChannels = safeParseInt( instrValue );
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
final int idx = safeParseInt( instrKey.substring( 6 ) );
final long pos = Long.parseLong( instrValue );
if ( pos > Long.MIN_VALUE )
enabledChannels = NumberUtils.getBitMask( channels );
代码示例来源:origin: jawi/ols
symbol = reverseBits( symbol, bitCount );
setProgress( getPercentage( start, startOfDecode, endOfDecode ) );
代码示例来源:origin: jawi/ols
/**
* Parses the given text as an integer, avoiding runtime exceptions.
*
* @param aText
* the text to parse as an integer, can be <code>null</code> or
* empty.
* @return the numeric representation of the given text, or -1 if the text
* could not be parsed correctly as integer.
* @see #safeParseLong(String, long)
*/
public static long safeParseLong( final String aText )
{
return safeParseLong( aText, -1L );
}
代码示例来源:origin: jawi/ols
/**
* Creates a mocked data set with a given number of sample/time values.
*
* @param aDataSize
* the number of sample/time values in the returned data container, >
* 0;
* @param aChannelCount
* the number of <em>enabled</em> channels in the returned data
* container, > 0 && < 32;
* @param aSampleRate
* the sample rate (in Hertz), > 0;
* @param aProvider
* the test data provider to use, cannot be <code>null</code>.
* @return a mocked data container, never <code>null</code>.
*/
public static DataSet createStubDataSet( final int aDataSize, final int aChannelCount, final int aSampleRate,
final TestDataProvider aProvider )
{
final int[] values = new int[aDataSize];
final long[] timestamps = new long[aDataSize];
aProvider.fillData( values, timestamps, aDataSize );
final StubDataSet project = new StubDataSet();
project.setCapturedData( new CapturedData( values, timestamps, 0, aSampleRate, aChannelCount, NumberUtils
.getBitMask( aChannelCount ), timestamps[aDataSize - 1] + 1L ) );
return project;
}
代码示例来源:origin: jawi/ols
size = safeParseInt( instrValue );
rate = safeParseInt( instrValue );
channels = safeParseInt( instrValue );
enabledChannels = safeParseInt( instrValue );
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
final long value = safeParseLong( instrValue );
if ( value > Long.MIN_VALUE )
final int idx = safeParseInt( instrKey.substring( 6 ) );
final long pos = Long.parseLong( instrValue );
if ( pos > Long.MIN_VALUE )
代码示例来源:origin: jawi/ols
/**
* Returns the width (in bytes) of each sample.
*
* @return the sample width, in bytes, >= 0.
*/
public int getSampleWidth()
{
return NumberUtils.safeParseInt( this.sampleWidth.getText(), 1 );
}
代码示例来源:origin: jawi/ols
/**
* Provides a "smart" integer parsing routine that allows (decimal) numbers in
* string form with all kind of trailing characters to be parsed into an
* integer. Some trailing characters are understood as being part of the
* number, like "k" to denote a value in thousands, or "m" to denote a value
* in millions.
*
* @param aText
* the text to parse into an integer value, cannot be
* <code>null</code>;
* @param aUnitDefinition
* the unit definition for "k" and "M" characters, should be either
* SI (units of 1000) or BINARY (units of 1024).
* @return the integer value part of the given text, or 0 if the text couldn't
* be parsed.
*/
public static int smartParseInt( final String aText, final UnitDefinition aUnitDefinition )
{
return smartParseInt( aText, aUnitDefinition, 0 );
}
代码示例来源:origin: jawi/ols
/**
* Calculates the percentage for the given value in the range denoted by the
* given lower and upper bounds.
*
* @param aValue
* the value;
* @param aLowerBound
* the lower bound of the range;
* @param aUpperBound
* the upper bound of the range.
* @return the percentage (= value * 100.0 / range).
*/
public static int getPercentage( final long aValue, final long aLowerBound, final long aUpperBound )
{
long range;
long value = aValue;
if ( aLowerBound > aUpperBound )
{
range = aLowerBound - aUpperBound;
value = Math.max( 0, value - aUpperBound );
}
else
{
range = aUpperBound - aLowerBound;
value = Math.max( 0, value - aLowerBound );
}
return getPercentage( value, range );
}
代码示例来源:origin: jawi/ols
/**
* Returns the number of channels in each sample.
*
* @return the channel count, >= 0.
*/
public int getChannelCount()
{
return NumberUtils.safeParseInt( this.channelCount.getText(), 8 );
}
代码示例来源:origin: jawi/ols
/**
* Provides a "smart" integer parsing routine that allows (decimal) numbers in
* string form with all kind of trailing characters to be parsed into an
* integer. Some trailing characters are understood as being part of the
* number, like "k" to denote a value in thousands, or "m" to denote a value
* in millions.
* <p>
* Characters recognized are: "k" and "M" to denote units of 1024, 1024*1024.
* </p>
*
* @param aText
* the text to parse into an integer value, cannot be
* <code>null</code>;
* @param aDefault
* the default value to return in case the given text couldn't be
* parsed into a valid number.
* @return the integer value part of the given text, or the given default
* value if the text couldn't be parsed.
*/
public static int smartParseInt( final String aText, final int aDefault )
{
return smartParseInt( aText, UnitDefinition.BINARY, aDefault );
}
代码示例来源:origin: jawi/ols
this.progressListener.setProgress( getPercentage( sampleIdx, aStartOfDecode, aEndOfDecode ) );
this.progressListener.setProgress( getPercentage( sampleIdx, aStartOfDecode, aEndOfDecode ) );
代码示例来源:origin: jawi/ols
/**
* Returns the new element height.
*
* @return the new element height, in pixels.
*/
public int getElementHeight()
{
int defaultValue = UIManager.getInt( UIManagerKeys.CHANNEL_HEIGHT );
return NumberUtils.safeParseInt( this.heightEditor.getText(), defaultValue );
}
代码示例来源:origin: jawi/ols
/**
* Returns the number of samples to take.
*
* @return the sample depth, >= 0.
*/
public int getSampleDepth()
{
return NumberUtils.smartParseInt( this.sampleDepth.getText(), 1024 );
}
代码示例来源:origin: jawi/ols
this.progressListener.setProgress( getPercentage( idx, startOfDecode, endOfDecode ) );
内容来源于网络,如有侵权,请联系作者删除!