asn1s-api/src/main/java/org/asn1s/api/util/CollectionUtils.java
/**
	 * Convert list of named bits to string of 0 and 1.
	 *
	 * @param valueList   the list of named bits
	 * @param desiredSize the size of result or -1
	 * @return bit string
	 * @throws IllegalArgumentException if actual result is bigger than desiredSize
	 */
Convert list of named bits to string of 0 and 1.
@param valueList   the list of named bits
@param desiredSize the size of result or -1
@return bit string
@throws IllegalArgumentException if actual result is bigger than desiredSize
Convert list of named bits to string of 0 and 1 . @param valueList the list of named bits @param desiredSize the size of result or - 1 @return bit string @throws IllegalArgumentException if actual result is bigger than desiredSize
@NotNull
	public static String convertToBString( Iterable<? extends Ref<Value>> valueList, int desiredSize )
	{
		Collection<Long> values = new HashSet<>();
		Long maxValue = 0L;
		for( Ref<Value> valueRef : valueList )
		{
			NamedValue value = (NamedValue)valueRef;
			if( value.getReferenceKind() != Kind.INTEGER || !value.toIntegerValue().isLong() )
				throw new IllegalStateException();
			Long longValue = value.toIntegerValue().asLong();
			values.add( longValue );
			maxValue = Math.max( maxValue, longValue );
		}
		if( desiredSize > -1 )
		{
			if( maxValue > ( desiredSize - 1 ) )
				throw new IllegalArgumentException( "Unable to truncate data. Desired size is smaller than expected: current = " + ( maxValue + 1 ) + " desired = " + desiredSize );
			maxValue = (long)desiredSize - 1;
		}
		StringBuilder sb = new StringBuilder();
		sb.append( '\'' );
		for( long value = 0; value <= maxValue; value++ )
			sb.append( values.contains( value ) ? '1' : '0' );
		sb.append( "'B" );
		return sb.toString();
	}
@ NotNull public static String convertToBString ( Iterable < ? extends Ref < Value > > valueList , int desiredSize ) { Collection < Long > values = new HashSet < > ( ) ; Long maxValue = 0L ; for ( Ref < Value > valueRef : valueList ) { NamedValue value = ( NamedValue ) valueRef ; if ( value . getReferenceKind ( ) != Kind . INTEGER || ! value . toIntegerValue ( ) . isLong ( ) ) throw new IllegalStateException ( ) ; Long longValue = value . toIntegerValue ( ) . asLong ( ) ; values . add ( longValue ) ; maxValue = Math . max ( maxValue , longValue ) ; } if ( desiredSize > - 1 ) { if ( maxValue > ( desiredSize - 1 ) ) throw new IllegalArgumentException ( "Unable to truncate data. Desired size is smaller than expected: current = " + ( maxValue + 1 ) + " desired = " + desiredSize ) ; maxValue = ( long ) desiredSize - 1 ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( '\'' ) ; for ( long value = 0 ; value <= maxValue ; value ++ ) sb . append ( values . contains ( value ) ? '1' : '0' ) ; sb . append ( "'B" ) ; return sb . toString ( ) ; }
Convert list of named bits to string of 0 and 1.
Convert list of named bits to string of 0 and 1 .