FileDocCategorySizeDatePackage
FormattersImpl.javaAPI DocAzureus 3.0.3.44671Fri Mar 23 14:10:36 GMT 2007org.gudy.azureus2.pluginsimpl.local.utils

FormattersImpl

public class FormattersImpl extends Object implements Formatters
author
parg

Fields Summary
Constructors Summary
public FormattersImpl()

	
Methods Summary
public java.util.MapbDecode(byte[] data)

		return( BDecoder.decode( data ));
	
public byte[]bEncode(java.util.Map map)

		return( BEncoder.encode( map ));
	
public byte[]base32Decode(java.lang.String data)

		return( Base32.decode( data ));
	
public java.lang.Stringbase32Encode(byte[] data)

		return( Base32.encode( data ));
	
public byte[]decodeBytesFromString(java.lang.String str)

		return( ByteFormatter.decodeString( str ));
	
public java.lang.StringencodeBytesToString(byte[] bytes)

		return( ByteFormatter.encodeString( bytes ));
	
public java.lang.StringformatByteArray(byte[] data, boolean no_spaces)

		return( ByteFormatter.nicePrint( data, no_spaces ));
	
public java.lang.StringformatByteCountToKiBEtc(long bytes)

		return( DisplayFormatters.formatByteCountToKiBEtc( bytes ));
	
public java.lang.StringformatByteCountToKiBEtcPerSec(long bytes)

		return( DisplayFormatters.formatByteCountToKiBEtcPerSec( bytes ));
	
public java.lang.StringformatDate(long millis)

		return( DisplayFormatters.formatDate( millis ));
	
public java.lang.StringformatETAFromSeconds(long seconds)

		return TimeFormatter.format( seconds );
	
public java.lang.StringformatPercentFromThousands(long thousands)

		return( DisplayFormatters.formatPercentFromThousands( (int)thousands ));
	
public java.lang.StringformatTimeFromSeconds(long seconds)

		return( DisplayFormatters.formatTime( seconds*1000 ));
	
public java.util.ComparatorgetAlphanumericComparator(boolean ignore_case)

		return( 
			new Comparator()
			{
				public int
				compare(
					Object	o1,
					Object	o2 )
				{
					if ( 	o1 instanceof String &&
							o2 instanceof String ){
						
						String	s1 = (String)o1;
						String	s2 = (String)o2;
						
						if ( s1 == null ){
							
							return( -1 );
						}
						
						if ( s2 == null ){
							
							return( -1 );
						}
						
						int	l1 = s1.length();
						int	l2 = s2.length();
								
						int	c1_pos	= 0;
						int c2_pos	= 0;
						
						while( c1_pos < l1 && c2_pos < l2 ){
							
							char	c1 = s1.charAt( c1_pos++ );
							char	c2 = s2.charAt( c2_pos++ );
														
							if ( Character.isDigit(c1) && Character.isDigit(c2)){
								
								int	n1_pos = c1_pos-1;
								int n2_pos = c2_pos-1;
								
								while( c1_pos < l1 ){
								
									if ( !Character.isDigit( s1.charAt( c1_pos ))){
										
										break;
									}
									
									c1_pos++;
								}
								
								while(c2_pos<l2){
								
									if ( !Character.isDigit( s2.charAt( c2_pos ))){
										
										break;
									}
									
									c2_pos++;
								}
							
								int	n1_length = c1_pos - n1_pos;
								int n2_length = c2_pos - n2_pos;
																
								if ( n1_length != n2_length ){
									
									return( n1_length - n2_length );
								}

								for (int i=0;i<n1_length;i++){
									
									char	nc1 = s1.charAt( n1_pos++ );
									char	nc2 = s2.charAt( n2_pos++ );
									
									if ( nc1 != nc2 ){
										
										return( nc1 - nc2 );
									}
								}
							}else{
							
								if ( ignore_case ){
									
									 c1 = Character.toLowerCase( c1 );
									 
									 c2 = Character.toLowerCase( c2 );
								}

								if ( c1 != c2 ){
									
									return( c1 - c2 );
								}
							}
						}
						
						return( l1 - l2);					
						
					}else{
						
						return( 0 );
					}
				}
			});