signature:
public class Iterables { /** * Returns a cyclic { @ code Iterable } that cycles indefinitely over the
 * given { @ code Iterable } ' s elements . The returned { @ code Iterable } ' s
 * { @ code Iterator } supports { @ code Iterator # remove ( ) } .
 * @ param < T > the type of the returned { @ code Iterable } ' s elements .
 * @ param iterable the { @ code Iterable } containing the elements to
 * cycle over .
 * @ return the cyclic { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } . */
public static < T > Iterable < T > cycle ( Iterable < ? extends T > iterable ) { } }

implementation: return new CyclicIterable < T > ( toList ( iterable ) ) ;


signature:
public class Iterables { /** * Returns an { @ code Iterable } that cycles indefinitely over the given
 * elements . The returned { @ code Iterable } ' s { @ code Iterator } supports
 * { @ link Iterator # remove ( ) } .
 * @ param < T > the type of the returned { @ code Iterable } ' s elements .
 * @ param elements the elements to cycle over .
 * @ return the cyclic { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } . */
public static < T > Iterable < T > cycle ( T ... elements ) { } }

implementation: return new CyclicIterable < T > ( new ArrayList < T > ( Arrays . asList ( elements ) ) ) ;


signature:
public class Iterables { /** * Returns whether the given { @ code Iterable } s contain equal elements in
 * the same order .
 * @ param i1 the first { @ code Iterable } .
 * @ param i2 the second { @ code Iterable } .
 * @ return whether the given { @ code Iterables } have the same content . */
public static boolean equal ( Iterable < ? > i1 , Iterable < ? > i2 ) { } }

implementation: if ( i1 == i2 ) { return true ; } if ( i1 == null || i2 == null ) { return false ; } return Iterators . equal ( i1 . iterator ( ) , i2 . iterator ( ) ) ;


signature:
public class Iterables { /** * Returns an { @ code Iterable } view of the given { @ code Iterable } that
 * will only return its first { @ code limit } items . The returned view ' s
 * { @ code Iterator } s support { @ link Iterator # remove ( ) } if the original
 * { @ code Iterator } does .
 * @ param < T > the type of the returned { @ code Iterable } ' s elements .
 * @ param iterable the { @ code Iterable } to limit .
 * @ param limit the number of elements in the returned { @ code Iterable } .
 * @ return the limited { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } .
 * @ throws IllegalArgumentException if ( { @ code limit } is negative . */
public static < T > Iterable < T > limit ( Iterable < ? extends T > iterable , int limit ) { } }

implementation: return new LimitIterable < T > ( iterable , limit ) ;


signature:
public class Iterables { /** * Returns an { @ code Iterable } view of the given { @ code Iterable } that
 * skips its first { @ code n } elements . The returned { @ code Iterable } ' s
 * { @ code Iterator } supports { @ link Iterator # remove ( ) } if the original
 * { @ code Iterator } does .
 * @ param < T > the type of the { @ code Iterable } ' s elements .
 * @ param iterable the input { @ code Iterable } .
 * @ param n the number of items to skip .
 * @ return the skipping { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } .
 * @ throws IllegalArgumentException if ( { @ code n } is negative . */
public static < T > Iterable < T > skip ( Iterable < T > iterable , int n ) { } }

implementation: return new SkipIterable < T > ( iterable , n ) ;


signature:
public class Iterables { /** * Returns a { @ code List } containing all the given { @ code Iterable } ' s
 * elements .
 * @ param < T > the type of the returned { @ code List } ' s elements .
 * @ param iterable the source { @ code Iterable } .
 * @ return the { @ code List } created from the given { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } . */
public static < T > List < T > toList ( Iterable < ? extends T > iterable ) { } }

implementation: List < T > list = new ArrayList < T > ( ) ; for ( T e : iterable ) { list . add ( e ) ; } return list ;


signature:
public class Iterables { /** * Returns a { @ code Set } containing all the given { @ code Iterable } ' s
 * elements . The returned { @ code Set } has the same iteration order as
 * the source { @ code Iterable } .
 * @ param < T > the type of the returned { @ code Set } ' s elements .
 * @ param iterable the source { @ code Iterable } .
 * @ return the { @ code Set } created from the given { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } . */
public static < T > Set < T > toSet ( Iterable < ? extends T > iterable ) { } }

implementation: Set < T > set = new LinkedHashSet < T > ( ) ; for ( T e : iterable ) { set . add ( e ) ; } return set ;


signature:
public class Iterables { /** * Returns a { @ code Bag } containing all the given { @ code Iterable } ' s
 * elements . The returned { @ code Bag } has the same iteration order as
 * the source { @ code Iterable } .
 * @ param < T > the type of the returned { @ code Bag } ' s elements .
 * @ param iterable the source { @ code Iterable } .
 * @ return the { @ code Bag } created from the given { @ code Iterable } .
 * @ throws NullPointerException if { @ code iterable } is { @ code null } . */
public static < T > Bag < T > toBag ( Iterable < ? extends T > iterable ) { } }

implementation: return new ArrayBag < T > ( iterable ) ;


signature:
public class MD4 { /** * Adds the padding bits and the message length to the input data . */
private void addPadding ( ) { } }

implementation: int len = BLOCK_LENGTH - bufferLen ; if ( len < 9 ) { len += BLOCK_LENGTH ; } byte [ ] buf = new byte [ len ] ; buf [ 0 ] = ( byte ) 0x80 ; for ( int i = 1 ; i < len - 8 ; i ++ ) { buf [ i ] = ( byte ) 0x00 ; } counter = ( counter + ( long ) bufferLen ) * 8L ; LittleEndian . encode ( counter , buf , len - 8 ) ; update ( buf ) ;


signature:
public class ImmutableList { /** * Creates a new { @ code ImmutableList } from the given { @ code Collection } .
 * @ param < E > the type of the { @ code List } ' s elements .
 * @ param c the source { @ code Collection } .
 * @ return the created { @ code ImmutableList } .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static < E > List < E > copyOf ( Collection < ? extends E > c ) { } }

implementation: return new ImmutableList < E > ( new ArrayList < E > ( c ) ) ;


signature:
public class ImmutableList { /** * Creates a new { @ code ImmutableList } from the given { @ code Iterable } .
 * @ param < E > the type of the { @ code List } ' s elements .
 * @ param i the source { @ code Iterable } .
 * @ return the created { @ code ImmutableList } .
 * @ throws NullPointerException if { @ code i } is { @ code null } . */
public static < E > List < E > copyOf ( Iterable < ? extends E > i ) { } }

implementation: return new ImmutableList < E > ( Iterables . toList ( i ) ) ;


signature:
public class ImmutableList { /** * Creates a new { @ code ImmutableList } from the given { @ code Iterator } .
 * @ param < E > the type of the { @ code List } ' s elements .
 * @ param i the source { @ code Iterator } .
 * @ return the created { @ code ImmutableList } .
 * @ throws NullPointerException if { @ code i } is { @ code null } . */
public static < E > List < E > copyOf ( Iterator < ? extends E > i ) { } }

implementation: return new ImmutableList < E > ( Iterators . toList ( i ) ) ;


signature:
public class ImmutableList { /** * Creates a new { @ code ImmutableList } containing the given elements .
 * @ param < E > the type of the { @ code List } ' s elements .
 * @ param values the { @ code List } ' s elements .
 * @ return the created { @ code ImmutableList } .
 * @ throws NullPointerException if { @ code values } is { @ code null } . */
public static < E > List < E > copyOf ( E [ ] values ) { } }

implementation: return new ImmutableList < E > ( Arrays . asList ( values ) ) ;


signature:
public class ImmutableList { /** * Creates a new { @ code ImmutableList } containing the given elements .
 * @ param < E > the type of the { @ code List } ' s elements .
 * @ param values the { @ code List } ' s elements .
 * @ return the created { @ code ImmutableList } .
 * @ throws NullPointerException if { @ code values } is { @ code null } . */
public static < E > List < E > of ( E ... values ) { } }


signature:
public class TextFiles { /** * Returns the first ( up to 10 ) lines of the given { @ code File } using
 * the specified charset . Named after the Unix command of the same name .
 * @ param f the { @ code File } to read .
 * @ param charset the charset to use .
 * @ return the first lines of the given { @ code File } .
 * @ throws NullPointerException if { @ code f } is { @ code null } .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > head ( File f , Charset charset ) throws IOException { } }

implementation: return head ( f , 10 , charset ) ;


signature:
public class TextFiles { /** * Returns the first ( up to { @ code n } ) lines of the given { @ code File }
 * using the system ' s default charset . Named after the Unix command of
 * the same name .
 * @ param f the { @ code File } to read .
 * @ param n the maximum number of lines to read .
 * @ return the first lines of the given { @ code File } .
 * @ throws NullPointerException if { @ code f } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > head ( File f , int n ) throws IOException { } }

implementation: return head ( f , n , Charsets . DEFAULT ) ;


signature:
public class TextFiles { /** * Returns the first ( up to { @ code n } ) lines of the given { @ code File }
 * using the specified charset . Named after the Unix command of the same
 * name .
 * @ param f the { @ code File } to read .
 * @ param n the maximum number of lines to read .
 * @ param charset the charset to use .
 * @ return the first lines of the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > head ( File f , int n , Charset charset ) throws IOException { } }

implementation: Parameters . checkCondition ( n >= 0 ) ; List < String > lines = new ArrayList < String > ( ) ; BufferedReader reader = newReader ( f , charset ) ; try { String line = reader . readLine ( ) ; while ( line != null && lines . size ( ) < n ) { lines . add ( line ) ; line = reader . readLine ( ) ; } } finally { IO . close ( reader ) ; } return Collections . unmodifiableList ( lines ) ;


signature:
public class TextFiles { /** * Returns the last ( up to 10 ) lines of the given { @ code File } using the
 * specified charset . Named after the Unix command of the same name .
 * @ param f the { @ code File } to read .
 * @ param charset the charset to use .
 * @ return the last lines of the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > tail ( File f , Charset charset ) throws IOException { } }

implementation: return tail ( f , 10 , charset ) ;


signature:
public class TextFiles { /** * Returns the last ( up to n ) lines of the given { @ code File } using the
 * specified charset . Named after the Unix command of the same name .
 * @ param f the { @ code File } to read .
 * @ param n the maximum number of lines to read .
 * @ param charset the charset to use .
 * @ return the last lines of the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > tail ( File f , int n , Charset charset ) throws IOException { } }

implementation: Parameters . checkCondition ( n >= 0 ) ; if ( n == 0 ) { return Collections . emptyList ( ) ; } List < String > lines = new LinkedList < String > ( ) ; BufferedReader reader = newReader ( f , charset ) ; try { String line = reader . readLine ( ) ; while ( line != null ) { lines . add ( line ) ; if ( lines . size ( ) > n ) { lines . remove ( 0 ) ; } line = reader . readLine ( ) ; } } finally { IO . close ( reader ) ; } return Collections . unmodifiableList ( lines ) ;


signature:
public class TextFiles { /** * Returns a new { @ code BufferedReader } to read the given { @ code File }
 * using the specified charset .
 * @ param f the file to read from .
 * @ param charset the charset to use .
 * @ return a { @ code BufferedReader } to read the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws FileNotFoundException if { @ code f } doesn ' t exist , or if it is
 * a directory rather than a regular file , or if it can ' t be opened
 * for reading .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static BufferedReader newReader ( File f , Charset charset ) throws FileNotFoundException { } }

implementation: InputStream in = new FileInputStream ( f ) ; return new BufferedReader ( new InputStreamReader ( in , charset ) ) ;


signature:
public class TextFiles { /** * Returns a new { @ code BufferedWriter } to write to the given
 * { @ code File } using the system ' s default charset .
 * @ param f the file to write to .
 * @ param options the write options .
 * @ return a { @ code BufferedWriter } to write to the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if incompatible options are given .
 * @ throws FileNotFoundException if { @ code f } exists but is a directory
 * rather than a regular file , or if it does not exist but cannot
 * be created , or if it cannot be opened for any other reason .
 * @ throws IOException if the { @ link WriteOption # CREATE } option is given
 * and the specified file already exists .
 * @ throws SecurityException if a security manager exists and denies
 * write access to { @ code f } . */
public static BufferedWriter newWriter ( File f , WriteOption ... options ) throws IOException { } }

implementation: return newWriter ( f , Charsets . DEFAULT , options ) ;


signature:
public class TextFiles { /** * Returns a new { @ code BufferedWriter } to write to the given
 * { @ code File } using the specified charset .
 * @ param f the file to write to .
 * @ param charset the charset to use .
 * @ param options the write options .
 * @ return a { @ code BufferedWriter } to write to the given { @ code File } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if incompatible options are given .
 * @ throws FileNotFoundException if { @ code f } exists but is a directory
 * rather than a regular file , or if it does not exist but cannot
 * be created , or if it cannot be opened for any other reason .
 * @ throws IOException if the { @ link WriteOption # CREATE } option is given
 * and the specified file already exists .
 * @ throws SecurityException if a security manager exists and denies
 * write access to { @ code f } . */
public static BufferedWriter newWriter ( File f , Charset charset , WriteOption ... options ) throws IOException { } }

implementation: OutputStream out = XFiles . newOutputStream ( f , options ) ; return new BufferedWriter ( new OutputStreamWriter ( out , charset ) ) ;


signature:
public class TextFiles { /** * Reads the whole content of the given { @ code File } as a { @ code String }
 * using the specified charset .
 * @ param f the file to read .
 * @ param charset the charset to use .
 * @ return the file ' s content as a { @ code String } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static String read ( File f , Charset charset ) throws IOException { } }

implementation: BufferedReader in = newReader ( f , charset ) ; try { return CharStreams . read ( in ) ; } finally { IO . close ( in ) ; }


signature:
public class TextFiles { /** * Reads all the lines from the given { @ code File } using the system ' s
 * default charset . Note that the returned { @ code List } is immutable .
 * @ param f the file to read .
 * @ return the file ' s lines .
 * @ throws NullPointerException if { @ code f } is { @ code null } .
 * @ throws IOException if { @ code f } does not exist , or if it is a
 * directory rather than a regular file , or if it can ' t be read .
 * @ throws SecurityException if a security manager exists and denies
 * read access to { @ code f } . */
public static List < String > readLines ( File f ) throws IOException { } }

implementation: return readLines ( f , Charsets . DEFAULT ) ;


signature:
public class URN { /** * Creates a new { @ code URN } by parsing the given { @ code String } . This
 * function invokes the { @ link URN # URN ( java . lang . String ) } constructor ;
 * any { @ code URNSyntaxException } thrown by the constructor is caught
 * and wrapped in a new { @ code IllegalArgumentException } , which is then
 * thrown . This method is provided for use in situations where it is
 * known that the given { @ code String } is a legal { @ code URN } .
 * @ param urn the { @ code String } to be parsed into a { @ code URN } .
 * @ return the created { @ code URN } .
 * @ throws NullPointerException if { @ code urn } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code urn } violates RFC 2141. */
public static URN create ( String urn ) { } }

implementation: try { return new URN ( urn ) ; } catch ( URNSyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; }


signature:
public class Resource { /** * Finds and returns the resource having the given name using the
 * { @ linkplain Thread # getContextClassLoader ( ) context class loader } .
 * Note that if the context class loader is { @ code null } , the class
 * loader that loaded this class will be used instead .
 * @ param name the resource ' s name .
 * @ return the requested resource .
 * @ throws NullPointerException if { @ code name } is { @ code null } .
 * @ throws NotFoundException if the resource can ' t be found . */
public static Resource find ( String name ) { } }

implementation: Parameters . checkNotNull ( name ) ; ClassLoader loader = XObjects . firstNonNull ( Thread . currentThread ( ) . getContextClassLoader ( ) , Resource . class . getClassLoader ( ) ) ; URL url = loader . getResource ( name ) ; if ( url != null ) { return new Resource ( url ) ; } throw new NotFoundException ( name ) ;


signature:
public class Resource { /** * Finds and returns the resource having the given name ( relative to
 * the specified class ) .
 * @ param name the resource ' s name .
 * @ param contextClass the context class .
 * @ return the requested resource .
 * @ throws NullPointerException if { @ code name } is { @ code null } .
 * @ throws NotFoundException if the resource can ' t be found . */
public static Resource find ( String name , Class < ? > contextClass ) { } }

implementation: Parameters . checkNotNull ( name ) ; URL url = contextClass . getResource ( name ) ; if ( url != null ) { return new Resource ( url ) ; } throw new NotFoundException ( name ) ;


signature:
public class Resource { /** * Copies the content of this resource to the specified stream .
 * @ param out the stream to copy to .
 * @ throws NullPointerException if { @ code out } is { @ code null } .
 * @ throws IOException if an I / O error occurs during the process . */
public void copyTo ( OutputStream out ) throws IOException { } }

implementation: InputStream in = url . openStream ( ) ; try { ByteStreams . copy ( in , out ) ; } finally { IO . close ( in ) ; }


signature:
public class Resource { /** * Copies the content of this resource to the specified stream .
 * @ param out the stream to copy to .
 * @ param charset the charset to use .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IOException if an I / O error occurs during the process . */
public void copyTo ( Writer out , Charset charset ) throws IOException { } }

implementation: InputStream in = url . openStream ( ) ; try { CharStreams . copy ( in , out , charset ) ; } finally { IO . close ( in ) ; }


signature:
public class Resource { /** * Reads and returns this resource ' s content as a { @ code byte [ ] } .
 * @ return this resource ' s content .
 * @ throws IOException if an I / O error occurs during the process . */
public byte [ ] read ( ) throws IOException { } }

implementation: InputStream in = url . openStream ( ) ; try { return ByteStreams . read ( in ) ; } finally { IO . close ( in ) ; }


signature:
public class Resource { /** * Reads and returns this resource ' s content as a { @ code String } .
 * @ param charset the charset to use .
 * @ return this resource ' s content .
 * @ throws NullPointerException if { @ code charset } is { @ code null } .
 * @ throws IOException if an I / O error occurs during the process . */
public String read ( Charset charset ) throws IOException { } }

implementation: InputStream in = url . openStream ( ) ; try { return CharStreams . read ( in , charset ) ; } finally { IO . close ( in ) ; }


signature:
public class Resource { /** * Reads and returns all this resource ' s lines . Note that the returned
 * { @ code List } is immutable .
 * @ param charset the charset to use .
 * @ return this resource ' s lines .
 * @ throws NullPointerException if { @ code charset } is { @ code null } .
 * @ throws IOException if an I / O error occurs during the process . */
public List < String > readLines ( Charset charset ) throws IOException { } }

implementation: InputStream in = url . openStream ( ) ; try { return CharStreams . readLines ( in , charset ) ; } finally { IO . close ( in ) ; }


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same instant .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same instant .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameInstant ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return isSameInstant ( cal1 . getTime ( ) , cal2 . getTime ( ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Date } s represent the same local time .
 * @ param date1 the first { @ code Date } .
 * @ param date2 the second { @ code Date } .
 * @ return whether the given { @ code Date } s represent the same local time .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameLocalTime ( Date date1 , Date date2 ) { } }

implementation: return isSameLocalTime ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same local time .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same local time .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameLocalTime ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return cal1 . get ( MILLISECOND ) == cal2 . get ( MILLISECOND ) && cal1 . get ( SECOND ) == cal2 . get ( SECOND ) && cal1 . get ( MINUTE ) == cal2 . get ( MINUTE ) && cal1 . get ( HOUR_OF_DAY ) == cal2 . get ( HOUR_OF_DAY ) && cal1 . get ( DAY_OF_YEAR ) == cal2 . get ( DAY_OF_YEAR ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( ERA ) == cal2 . get ( ERA ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Date } s represent the same day .
 * @ param date1 the first { @ code Date } .
 * @ param date2 the second { @ code Date } .
 * @ return whether the given { @ code Date } s represent the same day .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameDay ( Date date1 , Date date2 ) { } }

implementation: return isSameDay ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same day .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same day .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameDay ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( DAY_OF_YEAR ) == cal2 . get ( DAY_OF_YEAR ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Date } s represent the same week .
 * @ param date1 the first { @ code Date } .
 * @ param date2 the second { @ code Date } .
 * @ return whether the given { @ code Date } s represent the same week .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameWeek ( Date date1 , Date date2 ) { } }

implementation: return isSameWeek ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same week .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same week .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameWeek ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( WEEK_OF_YEAR ) == cal2 . get ( WEEK_OF_YEAR ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Date } s represent the same month .
 * @ param date1 the first { @ code Date } .
 * @ param date2 the second { @ code Date } .
 * @ return whether the given { @ code Date } s represent the same month .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameMonth ( Date date1 , Date date2 ) { } }

implementation: return isSameMonth ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same month .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same month .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameMonth ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( MONTH ) == cal2 . get ( MONTH ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Date } s represent the same year .
 * @ param date1 the first { @ code Date } .
 * @ param date2 the second { @ code Date } .
 * @ return whether the given { @ code Date } s represent the same year .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameYear ( Date date1 , Date date2 ) { } }

implementation: return isSameYear ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ;


signature:
public class Dates { /** * Returns whether the given { @ code Calendar } s represent the same year .
 * @ param cal1 the first { @ code Calendar } .
 * @ param cal2 the second { @ code Calendar } .
 * @ return whether the given { @ code Calendar } s represent the same year .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean isSameYear ( Calendar cal1 , Calendar cal2 ) { } }

implementation: return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) ;


signature:
public class Dates { /** * Parses a { @ code String } representing a date into a { @ code Date }
 * instance . The given formats will be used sequentially until a
 * successful parsing is obtained . A parsing is considered successful
 * if it parses the whole input { @ code String } .
 * @ param date the { @ code String } to parse .
 * @ param formats the date format patterns to use .
 * @ return the parsed { @ code Date } .
 * @ throws NullPointerException if one of the arguments is { @ code null }
 * or if { @ code formats } contains a { @ code null } reference .
 * @ throws IllegalArgumentException if { @ code formats } is empty or if
 * { @ code date } can ' t be parsed with any of the specified formats . */
public static Date parse ( String date , String ... formats ) { } }

implementation: return parse ( date , Locale . getDefault ( ) , formats ) ;


signature:
public class Dates { /** * Parses a { @ code String } representing a date into a { @ code Date }
 * instance . The given formats will be used sequentially until a
 * successful parsing is obtained . A parsing is considered successful
 * if it parses the whole input { @ code String } .
 * @ param date the { @ code String } to parse .
 * @ param locale the { @ code Locale } to use .
 * @ param formats the date format patterns to use .
 * @ return the parsed { @ code Date } .
 * @ throws NullPointerException if one of the arguments is { @ code null }
 * or if { @ code formats } contains a { @ code null } reference .
 * @ throws IllegalArgumentException if { @ code formats } is empty or if
 * { @ code date } can ' t be parsed with any of the specified formats . */
public static Date parse ( String date , Locale locale , String ... formats ) { } }

implementation: Parameters . checkNotNull ( date ) ; Parameters . checkCondition ( formats . length > 0 ) ; for ( String format : formats ) { DateFormat df = new SimpleDateFormat ( format , locale ) ; df . setLenient ( true ) ; ParsePosition position = new ParsePosition ( 0 ) ; Date d = df . parse ( date , position ) ; if ( d != null && position . getIndex ( ) == date . length ( ) ) { return d ; } } throw new IllegalArgumentException ( "Unparseable date: " + date ) ;


signature:
public class Dates { /** * Returns the { @ code String } representation of the given { @ code Date }
 * according to the specified format pattern .
 * @ param date the { @ code Date } to format .
 * @ param format the format pattern to use .
 * @ return the { @ code String } representation of { @ code date } .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static String format ( Date date , String format ) { } }

implementation: Parameters . checkNotNull ( date ) ; return new SimpleDateFormat ( format ) . format ( date ) ;


signature:
public class Dates { /** * Converts a { @ code Date } into a { @ code Calendar } .
 * @ param date the { @ code Date } to convert to a { @ code Calendar } .
 * @ return the created { @ code Calendar } instance .
 * @ throws NullPointerException if { @ code date } is { @ code null } . */
public static Calendar toCalendar ( Date date ) { } }

implementation: Calendar calendar = getInstance ( ) ; calendar . setTime ( date ) ; return calendar ;


signature:
public class Iterators { /** * Concatenates all the given { @ code Iterator } s into a single one . The
 * source { @ code Iterator } s aren ' t polled until necessary . The returned
 * { @ code Iterator } supports { @ link Iterator # remove ( ) } when the
 * corresponding input { @ code Iterator } supports it .
 * @ param < E > the type of the returned { @ code Iterator } ' s elements .
 * @ param iterators the { @ code Iterator } s to concatenate .
 * @ return the concatenated { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterators } is { @ code null } or
 * if it contains a { @ code null } reference . */
public static < E > Iterator < E > concat ( Iterator < ? extends E > ... iterators ) { } }

implementation: return concat ( Arrays . asList ( iterators ) . iterator ( ) ) ;


signature:
public class Iterators { /** * Concatenates all the given { @ code Iterator } s into a single one . The
 * source { @ code Iterator } s aren ' t polled until necessary . The returned
 * { @ code Iterator } supports { @ link Iterator # remove ( ) } when the
 * corresponding input { @ code Iterator } supports it .
 * @ param < E > the type of the returned { @ code Iterator } ' s elements .
 * @ param iterators the { @ code Iterator } s to concatenate .
 * @ return the concatenated { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterators } is { @ code null } or
 * if it contains a { @ code null } reference . */
public static < E > Iterator < E > concat ( Iterator < ? extends Iterator < ? extends E > > iterators ) { } }

implementation: return new ConcatIterator < E > ( iterators ) ;


signature:
public class Iterators { /** * Returns an { @ code Iterator } that cycles indefinitely over the content
 * of the given source { @ code Iterator } . The source { @ code Iterator } is
 * not polled until necessary . The returned { @ code Iterator } supports
 * { @ link Iterator # remove ( ) } .
 * @ param < E > the type of the returned { @ code Iterator } ' s elements .
 * @ param iterator the source { @ code Iterator } .
 * @ return the cyclic { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterator } is { @ code null } . */
public static < E > Iterator < E > cycle ( Iterator < ? extends E > iterator ) { } }

implementation: return new LazyCyclicIterator < E > ( iterator ) ;


signature:
public class Iterators { /** * Returns an { @ code Iterator } that cycles indefinitely over the given
 * elements . The returned { @ code Iterator } supports { @ link Iterator # remove ( ) } .
 * @ param < E > the type of the returned { @ code Iterator } ' s elements .
 * @ param elements the elements to cycle over .
 * @ return the cyclic { @ code Iterator } .
 * @ throws NullPointerException if { @ code elements } is { @ code null } . */
public static < E > Iterator < E > cycle ( E ... elements ) { } }

implementation: return new CyclicIterator < E > ( Arrays . asList ( elements ) ) ;


signature:
public class Iterators { /** * Returns whether the given { @ code Iterator } s contain equal elements in
 * the same order . Note that this method consumes entirely the input
 * { @ code Iterator } s .
 * @ param i1 the first { @ code Iterator } .
 * @ param i2 the second { @ code Iterator } .
 * @ return whether the given { @ code Iterator } have the same content . */
public static boolean equal ( Iterator < ? > i1 , Iterator < ? > i2 ) { } }

implementation: if ( i1 == i2 ) { return true ; } if ( i1 == null || i2 == null ) { return false ; } while ( i1 . hasNext ( ) && i2 . hasNext ( ) ) { if ( ! XObjects . equal ( i1 . next ( ) , i2 . next ( ) ) ) { return false ; } } return ! ( i1 . hasNext ( ) || i2 . hasNext ( ) ) ;


signature:
public class Iterators { /** * Creates an { @ code Iterator } returning only the first { @ code limit }
 * elements of the given { @ code Iterator } . The source { @ code Iterator }
 * is not polled until necessary . The returned { @ code Iterator } supports
 * { @ link Iterator # remove ( ) } if the source { @ code Iterator } supports it .
 * @ param < E > the type of the returned { @ code Iterator } ' s elements .
 * @ param iterator the { @ code Iterator } to limit .
 * @ param limit the number of elements in the returned { @ code Iterator } .
 * @ return the limited { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterator } is { @ code null } .
 * @ throws IllegalArgumentException if ( { @ code limit } is negative . */
public static < E > Iterator < E > limit ( Iterator < ? extends E > iterator , int limit ) { } }

implementation: return new LimitIterator < E > ( iterator , limit ) ;


signature:
public class Iterators { /** * Skips { @ code n } elements from the given { @ code Iterator } .
 * @ param iterator the { @ code Iterator } .
 * @ param n the number of elements to skip .
 * @ return the actual number of elements that has been skipped .
 * @ throws NullPointerException if { @ code iterator } is { @ code null } .
 * @ throws IllegalArgumentException if ( { @ code n } is negative . */
public static int skip ( Iterator < ? > iterator , int n ) { } }

implementation: Parameters . checkCondition ( n >= 0 ) ; int skipped = 0 ; while ( skipped < n && iterator . hasNext ( ) ) { iterator . next ( ) ; skipped ++ ; } return skipped ;


signature:
public class Iterators { /** * Returns a { @ code Set } containing all the given { @ code Iterator } ' s
 * elements . The returned { @ code Set } has the same iteration order as
 * the given { @ code Iterator } . This method consumes entirely the input
 * { @ code Iterator } .
 * @ param < E > the type of the returned { @ code Set } ' s elements .
 * @ param iterator the { @ code Iterator } to consume .
 * @ return the { @ code Set } created from the given { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterator } is { @ code null } . */
public static < E > Set < E > toSet ( Iterator < ? extends E > iterator ) { } }

implementation: Set < E > set = new LinkedHashSet < E > ( ) ; while ( iterator . hasNext ( ) ) { set . add ( iterator . next ( ) ) ; } return set ;


signature:
public class Iterators { /** * Returns a { @ code Bag } containing all the given { @ code Iterator } ' s
 * elements . The returned { @ code Bag } has the same iteration order as
 * the given { @ code Iterator } . This method consumes entirely the input
 * { @ code Iterator } .
 * @ param < E > the type of the returned { @ code Bag } ' s elements .
 * @ param iterator the { @ code Iterator } to consume .
 * @ return the { @ code Bag } created from the given { @ code Iterator } .
 * @ throws NullPointerException if { @ code iterator } is { @ code null } . */
public static < E > Bag < E > toBag ( Iterator < ? extends E > iterator ) { } }

implementation: return new ArrayBag < E > ( iterator ) ;


signature:
public class Strings { /** * Returns whether the given { @ code String } only contains space , ' \ n ' ,
 * ' \ r ' or ' \ t ' characters .
 * @ param str the { @ code String } to test .
 * @ return whether the given { @ code String } is blank .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static boolean isBlank ( String str ) { } }

implementation: for ( char c : str . toCharArray ( ) ) { if ( c != ' ' && c != '\r' && c != '\n' && c != '\t' ) { return false ; } } return true ;


signature:
public class Strings { /** * Abbreviates the given { @ code String } using the specified ellipsis so
 * that the returned { @ code String } ' s length is equal to { @ code length } .
 * @ param str the { @ code String } to abbreviate .
 * @ param length the desired length for the abbreviated { @ code String } .
 * @ param ellipsis the ellipsis to use to mark abbreviation .
 * @ return the abbreviated { @ code String } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if { @ code length } is too small . */
public static String abbreviate ( String str , int length , String ellipsis ) { } }

implementation: Parameters . checkCondition ( length > ellipsis . length ( ) ) ; if ( str . length ( ) <= length ) { return str ; } return str . substring ( 0 , length - ellipsis . length ( ) ) + ellipsis ;


signature:
public class Strings { /** * Concatenates the given { @ code String } s .
 * @ param strings the { @ code String } s to concatenate .
 * @ return the concatenated { @ code String } .
 * @ throws NullPointerException if { @ code strings } is { @ code null } . */
public static String concat ( String ... strings ) { } }

implementation: StringBuilder sb = new StringBuilder ( strings . length * 10 ) ; for ( String string : strings ) { sb . append ( string ) ; } return sb . toString ( ) ;


signature:
public class Strings { /** * Computes and returns the Damerau - Levenshtein distance between the
 * given { @ code String } s . This distance is obtained by counting the
 * minimum number of operations needed to transform one { @ code String }
 * into the other , where an operation is defined as an insertion ,
 * deletion , or substitution of a single character , or a transposition
 * of two adjacent characters .
 * @ param str1 the first { @ code String } .
 * @ param str2 the second { @ code String } .
 * @ return the distance between { @ code str1 } and { @ code str2 } .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static int distance ( String str1 , String str2 ) { } }


signature:
public class Strings { /** * Returns a random { @ code String } using the given characters and the
 * specified source of randomness . All characters have equal likelihood
 * to appear in the resulting { @ code String } assuming that the source of
 * randomness is fair .
 * @ param length the length of the { @ code String } to produce .
 * @ param rnd the source of randomness to use .
 * @ param chars the characters to use to build the { @ code String } .
 * @ return a random { @ code String } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if { @ code length } is negative or if
 * { @ code chars } is empty . */
public static String random ( int length , Random rnd , char ... chars ) { } }

implementation: Parameters . checkCondition ( length >= 0 ) ; Parameters . checkCondition ( chars . length > 0 ) ; StringBuilder sb = new StringBuilder ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { sb . append ( chars [ rnd . nextInt ( chars . length ) ] ) ; } return sb . toString ( ) ;


signature:
public class Strings { /** * Returns the { @ code String } obtained by repeating { @ code count } times
 * the given { @ code String } .
 * @ param str the { @ code String } to repeat .
 * @ param count the number of times the { @ code str } has to be repeared .
 * @ return the created { @ code String } .
 * @ throws IllegalArgumentException if { @ code count } is negative .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String repeat ( String str , int count ) { } }

implementation: Parameters . checkCondition ( count >= 0 ) ; StringBuilder sb = new StringBuilder ( str . length ( ) * count ) ; for ( int i = 0 ; i < count ; i ++ ) { sb . append ( str ) ; } return sb . toString ( ) ;


signature:
public class Strings { /** * Randomly permutes the characters from the given { @ code String } using
 * the specified source of randomness . All permutations occur with equal
 * likelihood assuming that the source of randomness is fair . This
 * implementation uses the optimized version of the Fisher - Yates shuffle
 * algorithm ( Fisher , Yates , Durstenfeld , Knuth ) and thus runs in linear
 * time .
 * @ param str the { @ code String } to be shuffled .
 * @ param rnd the source of randomness to use .
 * @ return the shuffled { @ code String } .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static String shuffle ( String str , Random rnd ) { } }

implementation: return new String ( XArrays . shuffle ( str . toCharArray ( ) , rnd ) ) ;


signature:
public class Strings { /** * Returns the new { @ code String } obtained by stripping the first and
 * last { @ code n } characters from the given one .
 * @ param str the { @ code String } to be stripped .
 * @ param n the number of characters to strip .
 * @ return the stripped { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative . */
public static String strip ( String str , int n ) { } }

implementation: return stripRight ( stripLeft ( str , n ) , n ) ;


signature:
public class Strings { /** * Returns the new { @ code String } obtained by stripping the first
 * { @ code n } characters from the given one .
 * @ param str the { @ code String } to be stripped .
 * @ param n the number of characters to strip .
 * @ return the stripped { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative . */
public static String stripLeft ( String str , int n ) { } }

implementation: Parameters . checkCondition ( n >= 0 ) ; int start = Math . min ( str . length ( ) , n ) ; return str . substring ( start ) ;


signature:
public class Strings { /** * Returns the new { @ code String } obtained by stripping the last
 * { @ code n } characters from the given one .
 * @ param str the { @ code String } to be stripped .
 * @ param n the number of characters to strip .
 * @ return the stripped { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code n } is negative . */
public static String stripRight ( String str , int n ) { } }

implementation: Parameters . checkCondition ( n >= 0 ) ; int end = Math . max ( 0 , str . length ( ) - n ) ; return str . substring ( 0 , end ) ;


signature:
public class Strings { /** * Returns a copy of the given { @ code String } with leading whitespaces
 * omitted .
 * @ param str the { @ code String } to trim .
 * @ return the trimmed { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String trimLeft ( String str ) { } }

implementation: int start = 0 ; for ( char c : str . toCharArray ( ) ) { if ( c != ' ' ) { break ; } start ++ ; } return str . substring ( start ) ;


signature:
public class Strings { /** * Returns a copy of the given { @ code String } with trailing whitespaces
 * omitted .
 * @ param str the { @ code String } to trim .
 * @ return the trimmed { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String trimRight ( String str ) { } }

implementation: int end = str . length ( ) ; for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) != ' ' ) { break ; } end -- ; } return str . substring ( 0 , end ) ;


signature:
public class Strings { /** * Returns a { @ code String } of length at least { @ code len } created by
 * prepending as many copies of { @ code padChar } as necessary to reach
 * that length .
 * @ param str the { @ code String } to pad .
 * @ param len the result ' s minimum length .
 * @ param padChar the padding character .
 * @ return the padded { @ code String } .
 * @ throws IllegalArgumentException if { @ code len } is negative .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String padLeft ( String str , int len , char padChar ) { } }

implementation: Parameters . checkCondition ( len >= 0 ) ; StringBuilder sb = new StringBuilder ( len ) ; while ( sb . length ( ) < len - str . length ( ) ) { sb . append ( padChar ) ; } sb . append ( str ) ; return sb . toString ( ) ;


signature:
public class Strings { /** * Returns a { @ code String } of length at least { @ code len } created by
 * appending as many copies of { @ code padChar } as necessary to reach
 * that length .
 * @ param str the { @ code String } to pad .
 * @ param len the result ' s minimum length .
 * @ param padChar the padding character .
 * @ return the padded { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code len } is negative . */
public static String padRight ( String str , int len , char padChar ) { } }

implementation: Parameters . checkNotNull ( str ) ; Parameters . checkCondition ( len >= 0 ) ; StringBuilder sb = new StringBuilder ( len ) ; sb . append ( str ) ; while ( sb . length ( ) < len ) { sb . append ( padChar ) ; } return sb . toString ( ) ;


signature:
public class Strings { /** * Quotes the given { @ code String } with double quotes . If the given
 * { @ code String } has multiple quotes , only one of them is kept .
 * @ param str the { @ code String } to quote .
 * @ return the quoted { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String quote ( String str ) { } }

implementation: return new StringBuilder ( str . length ( ) + 2 ) . append ( "\"" ) . append ( unquote ( str ) ) . append ( "\"" ) . toString ( ) ;


signature:
public class Strings { /** * Unquotes the given { @ code String } , that is , this method removes any
 * leading or trailing double quotes . If the given { @ code String } is not
 * quoted , returns it unmodified .
 * @ param str the { @ code String } to unquote .
 * @ return the unquoted { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String unquote ( String str ) { } }

implementation: String unquoted = str ; while ( unquoted . startsWith ( "\"" ) ) { unquoted = unquoted . substring ( 1 ) ; } while ( unquoted . endsWith ( "\"" ) ) { unquoted = unquoted . substring ( 0 , unquoted . length ( ) - 1 ) ; } return unquoted ;


signature:
public class Strings { /** * Counts the occurrences of the substring { @ code sub } in { @ code str } .
 * @ param str { @ code String } to search in .
 * @ param sub { @ code String } to search for .
 * @ return the number of occurrences of { @ code sub } in { @ code str } .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static int countOccurrences ( String str , String sub ) { } }

implementation: Parameters . checkNotNull ( str ) ; int n = 0 ; if ( ! sub . isEmpty ( ) ) { int start = 0 ; while ( true ) { start = str . indexOf ( sub , start ) ; if ( start == - 1 ) { break ; } start += sub . length ( ) ; n ++ ; } } return n ;


signature:
public class URLs { /** * Creates a new { @ code URL } by parsing the given { @ code String } . This
 * function invokes the { @ link URL # URL ( java . lang . String ) } constructor ;
 * any { @ code MalformedURLException } thrown by the constructor is caught
 * and wrapped in a new { @ code IllegalArgumentException } , which is then
 * thrown . This method is provided for use in situations where it is
 * known that the given { @ code String } is a legal { @ code URL } .
 * @ param url the { @ code String } to be parsed into a { @ code URL } .
 * @ return the created { @ code URL } .
 * @ throws NullPointerException if { @ code url } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code url } is not a valid URL . */
public static URL create ( String url ) { } }

implementation: Parameters . checkNotNull ( url ) ; try { return new URL ( url ) ; } catch ( MalformedURLException ex ) { throw new IllegalArgumentException ( ex ) ; }


signature:
public class URLs { /** * Relativizes the specified full { @ code URL } against the given base .
 * Behaves as { @ link java . net . URI # relativize ( java . net . URI ) } .
 * @ param base the base { @ code URL } .
 * @ param full the full { @ code URL } .
 * @ return the relativized path .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if the relativization fails . */
public static String relativize ( URL base , URL full ) { } }

implementation: try { return base . toURI ( ) . relativize ( full . toURI ( ) ) . normalize ( ) . toString ( ) ; } catch ( URISyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; }


signature:
public class URLs { /** * Resolves the specified path against the given base { @ code URL } .
 * Behaves as { @ link java . net . URI # resolve ( java . lang . String ) } .
 * @ param base the base { @ code URL } .
 * @ param path the path to resolve .
 * @ return the resolved { @ code URL } .
 * @ throws NullPointerException if one of the arguments is { @ code null } .
 * @ throws IllegalArgumentException if the path can ' t be resolved . */
public static URL resolve ( URL base , String path ) { } }

implementation: try { return base . toURI ( ) . resolve ( path ) . normalize ( ) . toURL ( ) ; } catch ( URISyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; } catch ( MalformedURLException ex ) { throw new IllegalArgumentException ( ex ) ; }


signature:
public class Classes { /** * Returns the qualified name of the given class ( package name followed
 * by a dot , followed by the class name ) . For array classes , this method
 * returns the component type class name followed by as many " [ ] " as
 * the array ' s dimension .
 * @ param c the class .
 * @ return the qualified name of the given class .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static String getQualifiedName ( Class < ? > c ) { } }

implementation: if ( c . isArray ( ) ) { StringBuilder qname = new StringBuilder ( ) ; while ( c . isArray ( ) ) { c = c . getComponentType ( ) ; qname . append ( "[]" ) ; } qname . insert ( 0 , c . getName ( ) ) ; return qname . toString ( ) ; } return c . getName ( ) ;


signature:
public class Classes { /** * Returns only the name of the given class , that is , without its
 * package name and without its eventual " outer " class name .
 * @ param c the class .
 * @ return the short name of the given class .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static String getShortName ( Class < ? > c ) { } }

implementation: String qname = getQualifiedName ( c ) ; int start = qname . lastIndexOf ( '$' ) ; if ( start == - 1 ) { start = qname . lastIndexOf ( '.' ) ; } return qname . substring ( start + 1 ) ;


signature:
public class Classes { /** * Returns the name of the package of the given class or the empty
 * { @ code String } if the class is defined in the default package .
 * @ param c the class .
 * @ return the package name of the given class .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static String getPackageName ( Class < ? > c ) { } }

implementation: String name = c . getName ( ) ; int i = name . lastIndexOf ( '.' ) ; return i != - 1 ? name . substring ( 0 , i ) : "" ;


signature:
public class Classes { /** * Returns all the super types of the given class , that is , all the
 * classes in which any instance of the given class can be cast into .
 * @ param c the class .
 * @ return all the given class ' s super types .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static Set < Class < ? > > getSuperTypes ( Class < ? > c ) { } }

implementation: Set < Class < ? > > classes = new HashSet < Class < ? > > ( ) ; for ( Class < ? > clazz : c . getInterfaces ( ) ) { classes . add ( clazz ) ; classes . addAll ( getSuperTypes ( clazz ) ) ; } Class < ? > sup = c . getSuperclass ( ) ; if ( sup != null ) { classes . add ( sup ) ; classes . addAll ( getSuperTypes ( sup ) ) ; } return Collections . unmodifiableSet ( classes ) ;


signature:
public class Classes { /** * Returns the { @ code Set } of common super types of the given classes ,
 * that is , all the classes in which any instance of the given classes
 * can be cast into .
 * @ param classes the classes .
 * @ return the common super types of the given classes .
 * @ throws NullPointerException if { @ code classes } is { @ code null } , or
 * if it contains a { @ code null } reference .
 * @ throws IllegalArgumentException if { @ code classes } is empty . */
public static Set < Class < ? > > getCommonSuperTypes ( Iterable < Class < ? > > classes ) { } }

implementation: Iterator < Class < ? > > i = classes . iterator ( ) ; Parameters . checkCondition ( i . hasNext ( ) ) ; Set < Class < ? > > common = new HashSet < Class < ? > > ( getSuperTypes ( i . next ( ) ) ) ; while ( i . hasNext ( ) ) { common . retainAll ( getSuperTypes ( i . next ( ) ) ) ; } return Collections . unmodifiableSet ( common ) ;


signature:
public class Passwords { /** * Verifies that the given password matches the hashed one .
 * @ param password the password to verify .
 * @ param hash the hashed password .
 * @ return whether the given password matches the hashed one .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static boolean verify ( String password , byte [ ] hash ) { } }

implementation: byte [ ] h = Arrays . copyOf ( hash , HASH_LENGTH + SALT_LENGTH + 3 ) ; int n = 1 << ( h [ HASH_LENGTH + SALT_LENGTH ] & 0xFF ) ; int r = h [ HASH_LENGTH + SALT_LENGTH + 1 ] & 0xFF ; int p = h [ HASH_LENGTH + SALT_LENGTH + 2 ] & 0xFF ; if ( n > N || n < N_MIN || r > R || r < R_MIN || p > P || p < P_MIN ) { n = N ; r = R ; p = P ; } byte [ ] salt = new byte [ SALT_LENGTH ] ; System . arraycopy ( h , HASH_LENGTH , salt , 0 , SALT_LENGTH ) ; byte [ ] expected = hash ( password , salt , r , n , p ) ; int result = 0 ; for ( int i = 0 ; i < h . length ; i ++ ) { result |= h [ i ] ^ expected [ i ] ; } return result == 0 ;


signature:
public class Scanf { /** * Reads the next line from the standard input using the given charset .
 * @ param charset the charset to use .
 * @ return the next line read from the standard input .
 * @ throws NullPointerException if { @ code charset } is { @ code null } .
 * @ throws IOException if the standard input cannot be read . */
public static String readString ( Charset charset ) throws IOException { } }

implementation: Reader in = new InputStreamReader ( System . in , charset ) ; BufferedReader reader = new BufferedReader ( in ) ; try { return reader . readLine ( ) ; } finally { reader . close ( ) ; }


signature:
public class ByteBuffer { /** * Writes the given byte to this buffer .
 * @ param b the byte to write .
 * @ return this object . */
public ByteBuffer append ( byte b ) { } }

implementation: int newCount = count + 1 ; ensureCapacity ( newCount ) ; buf [ count ] = b ; count = newCount ; return this ;


signature:
public class ByteBuffer { /** * Writes the given data to this buffer .
 * @ param bytes the data to write .
 * @ param off the offset .
 * @ param len the number of bytes to write .
 * @ return this object .
 * @ throws NullPointerException if { @ code bytes } is { @ code null } .
 * @ throws IndexOutOfBoundsException if { @ code off } or { @ code len } is
 * negative or if { @ code off + len } is greater than the length of
 * the { @ code bytes } array . */
public ByteBuffer append ( byte [ ] bytes , int off , int len ) { } }

implementation: int newCount = count + len ; ensureCapacity ( newCount ) ; System . arraycopy ( bytes , off , buf , count , len ) ; count = newCount ; return this ;


signature:
public class ByteBuffer { /** * Returns { @ code len } bytes from this buffer , starting at { @ code off } .
 * @ param off the starting offset .
 * @ param len the number of bytes to return .
 * @ return the requested data bytes .
 * @ throws IndexOutOfBoundsException if { @ code off } or { @ code len } is
 * negative or if { @ code off + len } is greater than { @ code size ( ) } . */
public byte [ ] toByteArray ( int off , int len ) { } }

implementation: if ( off < 0 || len < 0 || off + len > count ) { throw new IndexOutOfBoundsException ( ) ; } byte [ ] data = new byte [ len ] ; System . arraycopy ( buf , off , data , 0 , len ) ; return data ;


signature:
public class XArrays { /** * Concatenates the given arrays into a single one .
 * @ param arrays the arrays to concatenate .
 * @ return the concatenated array .
 * @ throws NullPointerException if { @ code arrays } is { @ code null } or if
 * it contains a { @ code null } reference . */
public static long [ ] concat ( long [ ] ... arrays ) { } }

implementation: int len = 0 ; for ( long [ ] array : arrays ) { len += array . length ; } long [ ] concat = new long [ len ] ; int i = 0 ; for ( long [ ] array : arrays ) { System . arraycopy ( array , 0 , concat , i , array . length ) ; i = array . length ; } return concat ;


signature:
public class XArrays { /** * Concatenates the given arrays into a single one .
 * @ param < T > the type of the elements in the arrays to concatenate .
 * @ param arrays the arrays to concatenate .
 * @ return the concatenated array .
 * @ throws IllegalArgumentException if { @ code arrays } is empty .
 * @ throws NullPointerException if { @ code arrays } is { @ code null } or if
 * it contains a { @ code null } reference . */
public static < T > T [ ] concat ( T [ ] ... arrays ) { } }

implementation: Parameters . checkCondition ( arrays . length > 0 ) ; int len = 0 ; for ( T [ ] array : arrays ) { len += array . length ; } T [ ] concat = newArray ( arrays [ 0 ] . getClass ( ) . getComponentType ( ) , len ) ; int i = 0 ; for ( T [ ] array : arrays ) { System . arraycopy ( array , 0 , concat , i , array . length ) ; i = array . length ; } return concat ;


signature:
public class XArrays { /** * Copies the specified range of elements from the given array into a
 * new array . The returned array will be padded with { @ code 0 } , if
 * necessary , so that it has an exact length of { @ code len } .
 * @ param a the source array .
 * @ param off the starting position in the source array .
 * @ param len the number of elements to copy ( returned array ' s length ) .
 * @ return a new array containing the specified range of the source array .
 * @ throws NullPointerException if { @ code a } is { @ code null } .
 * @ throws ArrayIndexOutOfBoundsException if { @ code off } is negative .
 * @ throws NegativeArraySizeException if { @ code len } is negative . */
public static long [ ] copyOf ( long [ ] a , int off , int len ) { } }

implementation: long [ ] copy = new long [ len ] ; if ( len > a . length - off ) { System . arraycopy ( a , off , copy , 0 , a . length - off ) ; } else { System . arraycopy ( a , off , copy , 0 , len ) ; } return copy ;


signature:
public class XArrays { /** * Copies the specified range of elements from the given array into a
 * new array . The returned array will be padded with { @ code null } , if
 * necessary , so that it has an exact length of { @ code len } .
 * @ param < T > the type of the elements in the array to copy .
 * @ param a the source array .
 * @ param off the starting position in the source array .
 * @ param len the number of elements to copy ( returned array ' s length ) .
 * @ return a new array containing the specified range of the source array .
 * @ throws NullPointerException if { @ code a } is { @ code null } .
 * @ throws ArrayIndexOutOfBoundsException if { @ code off } is negative .
 * @ throws NegativeArraySizeException if { @ code len } is negative . */
public static < T > T [ ] copyOf ( T [ ] a , int off , int len ) { } }

implementation: T [ ] copy = newArray ( a . getClass ( ) . getComponentType ( ) , len ) ; if ( len > a . length - off ) { System . arraycopy ( a , off , copy , 0 , a . length - off ) ; } else { System . arraycopy ( a , off , copy , 0 , len ) ; } return copy ;


signature:
public class XArrays { /** * Returns a copy of the given array . The original array and the
 * returned copy will have identical length and content .
 * @ param < T > the type of the elements in the array to copy .
 * @ param original the array to be copied .
 * @ return a copy of the original array .
 * @ throws NullPointerException if { @ code original } is { @ code null } . */
public static < T > T [ ] copyOf ( T [ ] original ) { } }

implementation: return Arrays . copyOf ( original , original . length ) ;


signature:
public class XArrays { /** * Returns a new array containing the same elements as the given one ,
 * but in reverse order .
 * @ param a the array to reverse .
 * @ return the reversed array .
 * @ throws NullPointerException if { @ code a } is { @ code null } . */
public static long [ ] reverse ( long ... a ) { } }

implementation: int len = a . length ; long [ ] copy = new long [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { copy [ i ] = a [ len - i - 1 ] ; } return copy ;


signature:
public class XArrays { /** * Returns a new array containing the same elements as the given one ,
 * but in reverse order .
 * @ param < T > the type of the elements in the array to reverse .
 * @ param a the array to reverse .
 * @ return the reversed array .
 * @ throws NullPointerException if { @ code a } is { @ code null } . */
public static < T > T [ ] reverse ( T [ ] a ) { } }

implementation: int len = a . length ; T [ ] copy = newArray ( a . getClass ( ) . getComponentType ( ) , len ) ; for ( int i = 0 ; i < len ; i ++ ) { copy [ i ] = a [ len - i - 1 ] ; } return copy ;


signature:
public class XArrays { /** * Returns a new array containing the same elements as the given one ,
 * but rotated by the given distance . The element at index { @ code i } in
 * the returned array corresponds to the element in the original array
 * at index { @ code ( i - distance ) } mod { @ code a . length } , for all values
 * of { @ code i } between { @ code 0 } and { @ code a . length - 1 } , inclusive .
 * Note that rotation by { @ code 0 } or by a multiple of { @ code a . length }
 * is a no - op .
 * @ param a the array to rotate .
 * @ param distance the distance to rotate .
 * @ return the rotated array .
 * @ throws NullPointerException if { @ code a } is { @ code null } . */
public static long [ ] rotate ( long [ ] a , int distance ) { } }

implementation: int len = a . length ; long [ ] copy = new long [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { copy [ i ] = a [ index ( i - distance , len ) ] ; } return copy ;


signature:
public class XArrays { /** * Returns a new array containing the same elements as the given one ,
 * but rotated by the given distance . The element at index { @ code i } in
 * the returned array corresponds to the element in the original array
 * at index { @ code ( i - distance ) } mod { @ code a . length } , for all values
 * of { @ code i } between { @ code 0 } and { @ code a . length - 1 } , inclusive .
 * Note that rotation by { @ code 0 } or by a multiple of { @ code a . length }
 * is a no - op .
 * @ param < T > the type of the elements in the array to rotate .
 * @ param a the array to rotate .
 * @ param distance the distance to rotate .
 * @ return the rotated array .
 * @ throws NullPointerException if { @ code a } is { @ code null } . */
public static < T > T [ ] rotate ( T [ ] a , int distance ) { } }

implementation: int len = a . length ; T [ ] copy = newArray ( a . getClass ( ) . getComponentType ( ) , len ) ; for ( int i = 0 ; i < len ; i ++ ) { copy [ i ] = a [ index ( i - distance , len ) ] ; } return copy ;


signature:
public class XArrays { /** * Returns a copy of the given array where its element have been randomly
 * permuted using the specified source of randomness . All permutations
 * occur with equal likelihood assuming that the source of randomness is
 * fair . This method uses the optimized version of the Fisher - Yates shuffle
 * algorithm ( Fisher , Yates , Durstenfeld , Knuth ) and thus runs in linear
 * time .
 * @ param a the array whose content will be shuffled .
 * @ param rnd the source of randomness to use .
 * @ return the shuffled array .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static int [ ] shuffle ( int [ ] a , Random rnd ) { } }

implementation: int [ ] copy = copyOf ( a ) ; for ( int i = copy . length ; i > 1 ; i -- ) { swap ( copy , i - 1 , rnd . nextInt ( i ) ) ; } return copy ;


signature:
public class XArrays { /** * Returns a sorted copy of the given array of objects into ascending
 * order , according to the natural ordering of its elements ( all
 * elements in the array must implement the { @ link Comparable }
 * interface ) .
 * @ param < T > the type of the elements in the array to sort .
 * @ param a the array to be sorted .
 * @ return a sorted copy of the given array .
 * @ throws NullPointerException if { @ code a } is { @ code null } .
 * @ throws ClassCastException if the array contains elements that are
 * not mutually comparable ( for example , Strings and Integers ) .
 * @ throws IllegalArgumentException if the natural ordering of the array
 * elements is found to violate the { @ link Comparable } contract .
 * @ see Arrays # sort ( java . lang . Object [ ] ) */
public static < T > T [ ] sort ( T [ ] a ) { } }

implementation: T [ ] copy = copyOf ( a ) ; Arrays . sort ( copy ) ; return copy ;


signature:
public class XArrays { /** * Returns a sorted copy of the given array of objects into ascending
 * order , according to the order induced by the given { @ code Comparator } .
 * @ param < T > the type of the elements in the array to sort .
 * @ param a the array to be sorted .
 * @ param c the comparator to determine the order of the array .
 * @ return a sorted copy of the given array .
 * @ throws NullPointerException if { @ code a } or { @ code c } is { @ code null } .
 * @ throws ClassCastException if the array contains elements that are
 * not mutually comparable ( for example , Strings and Integers ) .
 * @ see Arrays # sort ( java . lang . Object [ ] , java . util . Comparator ) */
public static < T > T [ ] sort ( T [ ] a , Comparator < ? super T > c ) { } }

implementation: T [ ] copy = Arrays . copyOf ( a , a . length ) ; Arrays . sort ( copy , c ) ; return copy ;


signature:
public class XArrays { /** * Converts an array of { @ code Long } s to an array of { @ code long } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Long } array to convert .
 * @ return the corresponding { @ code long } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static long [ ] toPrimitive ( Long ... a ) { } }

implementation: if ( a != null ) { long [ ] p = new long [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Integer } s to an array of { @ code int } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Integer } array to convert .
 * @ return the corresponding { @ code int } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static int [ ] toPrimitive ( Integer ... a ) { } }

implementation: if ( a != null ) { int [ ] p = new int [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Short } s to an array of { @ code short } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Short } array to convert .
 * @ return the corresponding { @ code short } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static short [ ] toPrimitive ( Short ... a ) { } }

implementation: if ( a != null ) { short [ ] p = new short [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Character } s to an array of { @ code char } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Character } array to convert .
 * @ return the corresponding { @ code char } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static char [ ] toPrimitive ( Character ... a ) { } }

implementation: if ( a != null ) { char [ ] p = new char [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Byte } s to an array of { @ code byte } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Byte } array to convert .
 * @ return the corresponding { @ code byte } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static byte [ ] toPrimitive ( Byte ... a ) { } }

implementation: if ( a != null ) { byte [ ] p = new byte [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Boolean } s to an array of { @ code boolean } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Boolean } array to convert .
 * @ return the corresponding { @ code boolean } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static boolean [ ] toPrimitive ( Boolean ... a ) { } }

implementation: if ( a != null ) { boolean [ ] p = new boolean [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Float } s to an array of { @ code float } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Float } array to convert .
 * @ return the corresponding { @ code float } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static float [ ] toPrimitive ( Float ... a ) { } }

implementation: if ( a != null ) { float [ ] p = new float [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code Double } s to an array of { @ code double } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Double } array to convert .
 * @ return the corresponding { @ code double } array .
 * @ throws NullPointerException if { @ code a } contains a { @ code null } value . */
public static double [ ] toPrimitive ( Double ... a ) { } }

implementation: if ( a != null ) { double [ ] p = new double [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { p [ i ] = a [ i ] ; } return p ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code long } s to an array of { @ code Long } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code long } array to convert .
 * @ return the corresponding { @ code Long } array . */
public static Long [ ] toObject ( long ... a ) { } }

implementation: if ( a != null ) { Long [ ] w = new Long [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code int } s to an array of { @ code Integer } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code int } array to convert .
 * @ return the corresponding { @ code Integer } array . */
public static Integer [ ] toObject ( int ... a ) { } }

implementation: if ( a != null ) { Integer [ ] w = new Integer [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code short } s to an array of { @ code Short } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code short } array to convert .
 * @ return the corresponding { @ code Short } array . */
public static Short [ ] toObject ( short ... a ) { } }

implementation: if ( a != null ) { Short [ ] w = new Short [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code char } s to an array of { @ code Character } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code char } array to convert .
 * @ return the corresponding { @ code Character } array . */
public static Character [ ] toObject ( char ... a ) { } }

implementation: if ( a != null ) { Character [ ] w = new Character [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code byte } s to an array of { @ code Byte } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code byte } array to convert .
 * @ return the corresponding { @ code Byte } array . */
public static Byte [ ] toObject ( byte ... a ) { } }

implementation: if ( a != null ) { Byte [ ] w = new Byte [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code boolean } s to an array of { @ code Boolean } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code boolean } array to convert .
 * @ return the corresponding { @ code Boolean } array . */
public static Boolean [ ] toObject ( boolean ... a ) { } }

implementation: if ( a != null ) { Boolean [ ] w = new Boolean [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code float } s to an array of { @ code Float } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code Float } array to convert .
 * @ return the corresponding { @ code Short } array . */
public static Float [ ] toObject ( float ... a ) { } }

implementation: if ( a != null ) { Float [ ] w = new Float [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class XArrays { /** * Converts an array of { @ code double } s to an array of { @ code Double } s .
 * Returns { @ code null } if the given array is { @ code null } . Does not
 * modify the input array .
 * @ param a the { @ code double } array to convert .
 * @ return the corresponding { @ code Double } array . */
public static Double [ ] toObject ( double ... a ) { } }

implementation: if ( a != null ) { Double [ ] w = new Double [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { w [ i ] = a [ i ] ; } return w ; } return null ;


signature:
public class ASCII { /** * Decodes { @ code len } ASCII encoded bytes from the given input buffer ,
 * starting at { @ code off } .
 * @ param input the input buffer .
 * @ param off the starting offset .
 * @ param len the number of bytes to decode .
 * @ return the decoded characters .
 * @ throws NullPointerException if { @ code input } is { @ code null } .
 * @ throws IndexOutOfBoundsException if { @ code off } or { @ code len } is
 * negative or if { @ code off + len } is greater than { @ code input } ' s
 * length .
 * @ throws IllegalArgumentException if the specified bytes do not
 * represent valid ASCII encoded characters . */
public static String decode ( byte [ ] input , int off , int len ) { } }

implementation: CharsetDecoder decoder = Charsets . US_ASCII . newDecoder ( ) ; ByteBuffer buf = ByteBuffer . wrap ( input , off , len ) ; try { CharBuffer out = decoder . decode ( buf ) ; char [ ] chars = new char [ out . limit ( ) ] ; out . get ( chars ) ; return new String ( chars ) ; } catch ( CharacterCodingException ex ) { throw new IllegalArgumentException ( ex ) ; }


signature:
public class ASCII { /** * Returns whether the given { @ code String } is an alphabetic sequence ,
 * that is , a sequence which only contains letters .
 * @ param str the { @ code String } to test .
 * @ return whether the given { @ code String } is an alphabetic sequence .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static boolean isAlphabetic ( String str ) { } }

implementation: for ( char c : str . toCharArray ( ) ) { if ( ! isLetter ( c ) ) { return false ; } } return true ;


signature:
public class ASCII { /** * Returns whether the given { @ code String } is an alphanumeric sequence ,
 * that is , a sequence which only contains letters and digits .
 * @ param str the { @ code String } to test .
 * @ return whether the given { @ code String } is an alphanumeric sequence .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static boolean isAlphaNumeric ( String str ) { } }

implementation: for ( char c : str . toCharArray ( ) ) { if ( ! isDigit ( c ) && ! isLetter ( c ) ) { return false ; } } return true ;


signature:
public class ASCII { /** * Returns a { @ code String } in which all uppercase ASCII characters have
 * been replaced by their lowercase equivalent ( all other characters are
 * unchanged ) .
 * @ param str the { @ code String } to convert into lowercase .
 * @ return the converted { @ code String } .
 * @ throws NullPointerException if { @ code str } is { @ code null } . */
public static String toLowerCase ( String str ) { } }

implementation: StringBuilder sb = new StringBuilder ( str . length ( ) ) ; for ( char c : str . toCharArray ( ) ) { sb . append ( toLowerCase ( c ) ) ; } return sb . toString ( ) ;


signature:
public class BaseEncoding { /** * Returns a { @ code BaseEncoding } that behaves as this one except that
 * it adds the specified separator after every { @ code n } characters when
 * encoding data and ignores any occurence of the specified separator
 * when decoding encoded data .
 * See < a href = " http : / / tools . ietf . org / html / rfc4648 # section - 3.1 " > RFC 4648
 * section 3.1 < / a > for more details .
 * @ param separator the separator to use .
 * @ param n the number of characters between two successive separators .
 * @ return a { @ code BaseEncoding } with the desired configuration .
 * @ throws NullPointerException if { @ code separator } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code separator } contains any
 * alphabet or padding characters or if { @ code n < = 0 } . */
public BaseEncoding withSeparator ( String separator , int n ) { } }

implementation: Parameters . checkCondition ( n > 0 ) ; for ( char c : separator . toCharArray ( ) ) { if ( isPaddingChar ( c ) || isInAlphabet ( c ) ) { throw new IllegalArgumentException ( "Invalid separator character: '" + c + "'" ) ; } } return new BaseEncoding ( alphabet , separator , n , omitPadding , ignoreUnknownChars ) ;


signature:
public class BaseEncoding { /** * Encodes the given data bytes according to this { @ code BaseEncoding } ' s
 * configuration .
 * @ param in the input buffer .
 * @ param off the input offset .
 * @ param len the number of bytes to encode .
 * @ return the encoded { @ code String } .
 * @ throws NullPointerException if { @ code in } is { @ code null } .
 * @ throws IndexOutOfBoundsException if { @ code off } or { @ code len } is
 * negative or if { @ code off + len } is greater than { @ code in } ' s
 * length . */
public String encode ( byte [ ] in , int off , int len ) { } }

implementation: checkBounds ( in , off , len ) ; StringBuilder sb = new StringBuilder ( maxEncodedLength ( len ) ) ; int accu = 0 ; int count = 0 ; int b = alphabet . bitsPerChar ( ) ; for ( int i = off ; i < off + len ; i ++ ) { accu = ( accu << 8 ) | ( in [ i ] & 0xFF ) ; count += 8 ; while ( count >= b ) { count -= b ; sb . append ( alphabet . encode ( accu >>> count ) ) ; } } if ( count > 0 ) { accu = ( accu & ( 0xFF >>> ( 8 - count ) ) ) << ( b - count ) ; sb . append ( alphabet . encode ( accu ) ) ; if ( ! omitPadding ) { int c = alphabet . charsPerBlock ( ) ; int pad = c - ( sb . length ( ) % c ) ; for ( int i = 0 ; i < pad ; i ++ ) { sb . append ( PADDING_CHAR ) ; } } } insertSeparators ( sb ) ; return sb . toString ( ) ;


signature:
public class BaseEncoding { /** * Decodes the given encoded { @ code String } according to this
 * { @ code BaseEncoding } ' s configuration . Decoding is not case - sensitive
 * when possible ( namely for Base16 , Base32 and Base32Hex schemes ) .
 * @ param in the input { @ code String } .
 * @ return the decoded data .
 * @ throws NullPointerException if { @ code in } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code in } is not a valid
 * base - encoded { @ code String } according to this
 * { @ code BaseEncoding } ' s configuration . */
public byte [ ] decode ( String in ) { } }

implementation: String encoded = n > 0 ? in . replace ( separator , "" ) : in ; ByteBuffer buf = new ByteBuffer ( maxDecodedLength ( encoded . length ( ) ) ) ; int accu = 0 ; int count = 0 ; int decoded = 0 ; for ( int i = 0 ; i < encoded . length ( ) ; i ++ ) { char c = encoded . charAt ( i ) ; if ( isPaddingChar ( c ) && ! omitPadding ) { break ; } int v = decode ( c ) ; if ( v != - 1 ) { decoded ++ ; accu = ( accu << alphabet . bitsPerChar ( ) ) | v ; count += alphabet . bitsPerChar ( ) ; while ( count >= 8 ) { count -= 8 ; buf . append ( ( byte ) ( accu >>> count ) ) ; } } } if ( ! omitPadding || ! alphabet . requiresPadding ( ) ) { decoded += getPaddingLength ( encoded ) ; int blockSize = alphabet . charsPerBlock ( ) ; Parameters . checkCondition ( decoded % blockSize == 0 ) ; } return buf . toByteArray ( ) ;


signature:
public class BaseEncoding { /** * Decodes the specified range from the given encoded { @ code String }
 * according to this { @ code BaseEncoding } ' s configuration . Decoding is
 * not case - sensitive when possible ( namely for Base16 , Base32 and
 * Base32Hex schemes ) .
 * @ param in the input { @ code String } .
 * @ param off the input offset .
 * @ param len the number of characters to decode .
 * @ return the decoded data .
 * @ throws NullPointerException if { @ code in } is { @ code null } .
 * @ throws IndexOutOfBoundsException if { @ code off } or { @ code len } is
 * negative or if { @ code off + len } is greater than { @ code in } ' s
 * length .
 * @ throws IllegalArgumentException if the specified character range in
 * { @ code in } is not a valid base - encoded { @ code String } according
 * to this { @ code BaseEncoding } ' s configuration . */
public byte [ ] decode ( String in , int off , int len ) { } }

implementation: return decode ( in . substring ( off , off + len ) ) ;


signature:
public class Fraction { /** * Returns the { @ code Fraction } representation of the given value .
 * @ param val an { @ link Integer } value .
 * @ return the { @ code Fraction } representation of the given value .
 * @ throws NullPointerException if { @ code val } is { @ code null } . */
public static Fraction valueOf ( Integer val ) { } }

implementation: return new Fraction ( BigInteger . valueOf ( val ) , BigInteger . ONE ) ;


signature:
public class Fraction { /** * Creates a { @ code Fraction } from its { @ code String } representation .
 * @ param str the { @ code Fraction } ' s { @ code String } representation .
 * @ return the created { @ code Fraction } .
 * @ throws IllegalArgumentException if { @ code str } doesn ' t represent a
 * { @ code Fraction } or if its denominator equals zero . */
public static Fraction parse ( String str ) { } }

implementation: String fraction = str . replaceAll ( "\\s" , "" ) ; int index = fraction . indexOf ( '/' ) ; if ( index < 0 ) { return valueOf ( new BigInteger ( fraction ) ) ; } BigInteger n = new BigInteger ( fraction . substring ( 0 , index ) ) ; BigInteger d = new BigInteger ( fraction . substring ( index + 1 ) ) ; return new Fraction ( n , d ) ;


signature:
public class Fraction { /** * Adds the given value to this one and returns the result in reduced
 * form .
 * @ param f the fraction to add to this one .
 * @ return { @ code this + f } in reduced form .
 * @ throws NullPointerException if { @ code f } is { @ code null } . */
public Fraction plus ( Fraction f ) { } }

implementation: return new Fraction ( n . multiply ( f . d ) . add ( f . n . multiply ( d ) ) , d . multiply ( f . d ) ) . reduced ( ) ;


signature:
public class Fraction { /** * Subtracts the given value from this one and returns the result in
 * reduced form .
 * @ param f the fraction to subtract from this one .
 * @ return { @ code this - f } in reduced form .
 * @ throws NullPointerException if { @ code f } is { @ code null } . */
public Fraction minus ( Fraction f ) { } }

implementation: return new Fraction ( n . multiply ( f . d ) . subtract ( f . n . multiply ( d ) ) , d . multiply ( f . d ) ) . reduced ( ) ;


signature:
public class Fraction { /** * Multiplies this value by the given one and returns the result in
 * reduced form .
 * @ param f the fraction to multiply this one with .
 * @ return { @ code this * f } in reduced form .
 * @ throws NullPointerException if { @ code f } is { @ code null } . */
public Fraction multipliedBy ( Fraction f ) { } }

implementation: return new Fraction ( n . multiply ( f . n ) , d . multiply ( f . d ) ) . reduced ( ) ;


signature:
public class Fraction { /** * Divides this value by the given one and returns the result in reduced
 * form .
 * @ param f the fraction to divide this one with .
 * @ return { @ code this / f } in reduced form .
 * @ throws NullPointerException if { @ code f } is { @ code null } .
 * @ throws ArithmeticException if { @ code f } equals zero . */
public Fraction dividedBy ( Fraction f ) { } }

implementation: if ( ZERO . equals ( f ) ) { throw new ArithmeticException ( "Division by zero" ) ; } return new Fraction ( n . multiply ( f . d ) , d . multiply ( f . n ) ) . reduced ( ) ;


signature:
public class Fraction { /** * Returns the { @ code Fraction } obtained by raising this to the given
 * power , in reduced form .
 * @ param exponent the power to raise this fraction to .
 * @ return { @ code this ^ exponent } in reduced form .
 * @ throws ArithmeticException if { @ code exponent } is negative . */
public Fraction power ( int exponent ) { } }

implementation: return new Fraction ( n . pow ( exponent ) , d . pow ( exponent ) ) . reduced ( ) ;


signature:
public class Fraction { /** * Returns the opposite of this { @ code Fraction } . The result is not
 * reduced before being returned .
 * @ return { @ code - this } . */
public Fraction negated ( ) { } }

implementation: if ( d . signum ( ) < 0 ) { return new Fraction ( n , d . negate ( ) ) ; } return new Fraction ( n . negate ( ) , d ) ;


signature:
public class Fraction { /** * Returns the reduced form of this { @ code Fraction } . Also , note that
 * the sign information will be held by the numerator .
 * @ return the reduced form of this { @ code Fraction } . */
public Fraction reduced ( ) { } }

implementation: BigInteger gcd = n . gcd ( d ) ; if ( d . signum ( ) < 0 ) { BigInteger numerator = n . divide ( gcd ) . negate ( ) ; BigInteger denominator = d . divide ( gcd ) . negate ( ) ; return new Fraction ( numerator , denominator ) ; } return new Fraction ( n . divide ( gcd ) , d . divide ( gcd ) ) ;


signature:
public class ImmutableSet { /** * Creates a new { @ code ImmutableSet } from the given { @ code Collection } .
 * @ param < E > the type of the { @ code Set } ' s elements .
 * @ param c the source { @ code Collection } .
 * @ return the created { @ code ImmutableSet } .
 * @ throws NullPointerException if { @ code c } is { @ code null } . */
public static < E > Set < E > copyOf ( Collection < ? extends E > c ) { } }

implementation: return new ImmutableSet < E > ( new LinkedHashSet < E > ( c ) ) ;


signature:
public class ImmutableSet { /** * Creates a new { @ code ImmutableSet } from the given { @ code Iterable } .
 * @ param < E > the type of the { @ code Set } ' s elements .
 * @ param i the source { @ code Iterable } .
 * @ return the created { @ code ImmutableSet } .
 * @ throws NullPointerException if { @ code i } is { @ code null } . */
public static < E > Set < E > copyOf ( Iterable < ? extends E > i ) { } }

implementation: return new ImmutableSet < E > ( Iterables . toSet ( i ) ) ;


signature:
public class ImmutableSet { /** * Creates a new { @ code ImmutableSet } from the given { @ code Iterator } .
 * @ param < E > the type of the { @ code Set } ' s elements .
 * @ param i the source { @ code Iterator } .
 * @ return the created { @ code ImmutableSet } .
 * @ throws NullPointerException if { @ code i } is { @ code null } . */
public static < E > Set < E > copyOf ( Iterator < ? extends E > i ) { } }

implementation: return new ImmutableSet < E > ( Iterators . toSet ( i ) ) ;


signature:
public class ImmutableSet { /** * Creates a new { @ code ImmutableSet } containing the given elements .
 * @ param < E > the type of the { @ code Set } ' s elements .
 * @ param values the { @ code Set } ' s elements .
 * @ return the created { @ code ImmutableSet } .
 * @ throws NullPointerException if { @ code values } is { @ code null } . */
public static < E > Set < E > copyOf ( E [ ] values ) { } }

implementation: return new ImmutableSet < E > ( new LinkedHashSet < E > ( Arrays . asList ( values ) ) ) ;


signature:
public class ImmutableSet { /** * Creates a new { @ code ImmutableSet } containing the given elements .
 * @ param < E > the type of the { @ code Set } ' s elements .
 * @ param values the { @ code Set } ' s elements .
 * @ return the created { @ code ImmutableSet } .
 * @ throws NullPointerException if { @ code values } is { @ code null } . */
public static < E > Set < E > of ( E ... values ) { } }


signature:
public class Duration { /** * Parses the given duration ' s { @ code String } representation into a
 * { @ code Duration } instance . The given { @ code String } must be a list
 * of value / unit pairs separated by ' ' , ' + ' , ' - ' , ' \ n ' , ' \ t ' , ' \ r ' ,
 * { @ code ' & ' } or ' , ' characters or by the " and " { @ code String } . Values
 * must be integer ( either positive or negative ) values . Valid units are :
 * " milliseconds " , " millisecond " , " millis " and " ms " for milliseconds ,
 * " seconds " , " second " , " sec " , " secs " and " s " for seconds , " minutes " ,
 * " minute " , " min " , " mins " and " m " for minutes , " hours " , " hour " and " h "
 * for hours , " days " , " day " and " d " for days . Values must be separated
 * from their unit by a whitespace character . Parsing is not case
 * sensitive .
 * @ param duration the { @ code String } to parse into a { @ code Duration } .
 * @ return the parsed { @ code Duration } .
 * @ throws NullPointerException if { @ code duration } is { @ code null } .
 * @ throws IllegalArgumentException if { @ code duration } can ' t be parsed .
 * @ throws ArithmeticException if the total duration value overflows the
 * storage capacity of this class . */
public static Duration parse ( String duration ) { } }

implementation: String [ ] tokens = duration . toLowerCase ( ) . replace ( "and" , "" ) . replaceAll ( "[,&\\+]" , " " ) . replaceAll ( "-\\s+" , "-" ) . replace ( "--" , "" ) . replaceAll ( "[\n\t\r]" , " " ) . trim ( ) . replaceAll ( "\\s+" , " " ) . split ( "\\s" ) ; Parameters . checkCondition ( tokens . length % 2 == 0 ) ; long ms = 0L ; for ( int i = 0 ; i < tokens . length ; i += 2 ) { long v = Long . parseLong ( tokens [ i ] ) ; TimeUnit u = parseTimeUnit ( tokens [ i + 1 ] ) ; ms = safeAdd ( ms , MILLISECONDS . convert ( v , u ) ) ; } return new Duration ( ms ) ;


signature:
public class Duration { /** * Creates a new { @ code Duration } representing the given amount in the
 * given unit .
 * @ param amount the amount .
 * @ param unit the unit in which the amout is given .
 * @ return the created { @ code Duration } instance .
 * @ throws NullPointerException if { @ code unit } is { @ code null } .
 * @ throws ArithmeticException if the resulting duration is too large . */
public static Duration of ( long amount , TimeUnit unit ) { } }

implementation: long duration = MILLISECONDS . convert ( amount , unit ) ; if ( unit . convert ( duration , MILLISECONDS ) != amount ) { throw new ArithmeticException ( "Too large duration: " + amount + " " + unit ) ; } return new Duration ( duration ) ;


signature:
public class Duration { /** * Creates a new { @ code Duration } instance by summing all the given
 * { @ code Duration } s ' values .
 * @ param durations the { @ code Duration } s to sum .
 * @ return the created { @ code Duration } .
 * @ throws NullPointerException if { @ code durations } is { @ code null } or
 * if it contains { @ code null } reference .
 * @ throws ArithmeticException if the resulting duration is too large . */
public static Duration of ( Duration ... durations ) { } }

implementation: if ( durations . length == 0 ) { return new Duration ( 0L ) ; } long ms = durations [ 0 ] . milliseconds ; for ( int i = 1 ; i < durations . length ; i ++ ) { ms = safeAdd ( ms , durations [ i ] . milliseconds ) ; } return new Duration ( ms ) ;


signature:
public class Duration { /** * Creates a new { @ code Duration } instance representing the amount of
 * time elapsed between the given dates .
 * @ param start the start date .
 * @ param end the end date .
 * @ return the duration between { @ code start } and { @ code end } .
 * @ throws NullPointerException if one of the arguments is { @ code null } . */
public static Duration between ( Date start , Date end ) { } }

implementation: return new Duration ( end . getTime ( ) - start . getTime ( ) ) ;