/** * 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 ); }
/** * 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 ); }
/** * 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 ); }
/** * 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 ); }
if ( isPowerOfTwo( aBitCount ) ) int mask = getBitMask( aBitCount ); while ( ( s >>= 1 ) > 0 )
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 )
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 );
symbol = reverseBits( symbol, bitCount ); setProgress( getPercentage( start, startOfDecode, endOfDecode ) );
/** * 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 ); }
/** * 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; }
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 )
/** * 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 ); }
/** * 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 ); }
/** * 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 ); }
/** * Returns the number of channels in each sample. * * @return the channel count, >= 0. */ public int getChannelCount() { return NumberUtils.safeParseInt( this.channelCount.getText(), 8 ); }
/** * 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 ); }
this.progressListener.setProgress( getPercentage( sampleIdx, aStartOfDecode, aEndOfDecode ) ); this.progressListener.setProgress( getPercentage( sampleIdx, aStartOfDecode, aEndOfDecode ) );
/** * 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 ); }
/** * Returns the number of samples to take. * * @return the sample depth, >= 0. */ public int getSampleDepth() { return NumberUtils.smartParseInt( this.sampleDepth.getText(), 1024 ); }
this.progressListener.setProgress( getPercentage( idx, startOfDecode, endOfDecode ) );