Input: Encodes the given { @code long } value using little - endian byte ordering convention into the given array starting at the given offset . [CODESPLIT] public static void encode ( long n , byte [ ] out , int off ) { out [ off ] = ( byte ) n ; out [ off + 1 ] = ( byte ) ( n >>> 8 ) ; out [ off + 2 ] = ( byte ) ( n >>> 16 ) ; out [ off + 3 ] = ( byte ) ( n >>> 24 ) ; out [ off + 4 ] = ( byte ) ( n >>> 32 ) ; out [ off + 5 ] = ( byte ) ( n >>> 40 ) ; out [ off + 6 ] = ( byte ) ( n >>> 48 ) ; out [ off + 7 ] = ( byte ) ( n >>> 56 ) ; }


Input: Decodes the first 4 bytes starting at { @code off } of the given array into an { @code int } value using little - endian byte ordering convention . [CODESPLIT] public static int decodeInt ( byte [ ] in , int off ) { return ( in [ off ] & 0xFF ) | ( ( in [ off + 1 ] & 0xFF ) << 8 ) | ( ( in [ off + 2 ] & 0xFF ) << 16 ) | ( ( in [ off + 3 ] & 0xFF ) << 24 ) ; }


Input: Decodes the first 8 bytes starting at { @code off } of the given array into a { @code long } value using little - endian byte ordering convention . [CODESPLIT] public static long decodeLong ( byte [ ] in , int off ) { return ( long ) ( in [ off ] & 0xFF ) | ( ( long ) ( in [ off + 1 ] & 0xFF ) << 8 ) | ( ( long ) ( in [ off + 2 ] & 0xFF ) << 16 ) | ( ( long ) ( in [ off + 3 ] & 0xFF ) << 24 ) | ( ( long ) ( in [ off + 4 ] & 0xFF ) << 32 ) | ( ( long ) ( in [ off + 5 ] & 0xFF ) << 40 ) | ( ( long ) ( in [ off + 6 ] & 0xFF ) << 48 ) | ( ( long ) ( in [ off + 7 ] & 0xFF ) << 56 ) ; }


Input: Copies the content of the given { @code InputStream } into the given { @code Writer } using the system s default charset . [CODESPLIT] public static void copy ( InputStream in , Writer out ) throws IOException { copy ( new InputStreamReader ( in , Charsets . DEFAULT ) , out ) ; }


Input: Copies the content of the given { @code InputStream } into the given { @code Writer } using the specified charset . [CODESPLIT] public static void copy ( InputStream in , Writer out , Charset charset ) throws IOException { copy ( new InputStreamReader ( in , charset ) , out ) ; }


Input: Copies the content of the given { @code Reader } into the given { @code OutputStream } using the system s default charset . [CODESPLIT] public static void copy ( Reader in , OutputStream out ) throws IOException { copy ( in , new OutputStreamWriter ( out , Charsets . DEFAULT ) ) ; }


Input: Copies the content of the given { @code Reader } into the given { @code OutputStream } using the specified charset . [CODESPLIT] public static void copy ( Reader in , OutputStream out , Charset charset ) throws IOException { copy ( in , new OutputStreamWriter ( out , charset ) ) ; }


Input: Returns whether the given streams have the same content . [CODESPLIT] public static boolean equal ( Reader in1 , Reader in2 ) throws IOException { if ( in1 == in2 ) { return true ; } if ( in1 == null || in2 == null ) { return false ; } in1 = buffer ( in1 ) ; in2 = buffer ( in2 ) ; int c1 = in1 . read ( ) ; int c2 = in2 . read ( ) ; while ( c1 != - 1 && c2 != - 1 && c1 == c2 ) { c1 = in1 . read ( ) ; c2 = in2 . read ( ) ; } return in1 . read ( ) == - 1 && in2 . read ( ) == - 1 ; }


Input: Reads the whole content of the given { @code Reader } into a { @code String } . [CODESPLIT] public static String read ( Reader in ) throws IOException { Writer out = new StringWriter ( ) ; copy ( in , out ) ; return out . toString ( ) ; }


Input: Reads the whole content of the given { @code InputStream } into a { @code String } using the system s default charset . [CODESPLIT] public static String read ( InputStream in ) throws IOException { return read ( new InputStreamReader ( in , Charsets . DEFAULT ) ) ; }


Input: Reads the whole content of the given { @code InputStream } into a { @code String } using the specified charset . [CODESPLIT] public static String read ( InputStream in , Charset charset ) throws IOException { return read ( new InputStreamReader ( in , charset ) ) ; }


Input: Reads all the lines from the given source { @code Reader } . Note that the returned { @code List } is immutable . [CODESPLIT] public static List < String > readLines ( Reader in ) throws IOException { BufferedReader reader = buffer ( in ) ; List < String > lines = new ArrayList < String > ( ) ; String line = reader . readLine ( ) ; while ( line != null ) { lines . add ( line ) ; line = reader . readLine ( ) ; } return Collections . unmodifiableList ( lines ) ; }


Input: Reads all the lines from the given source { @code InputStream } using the system s default charset . Note that the returned { @code List } is immutable . [CODESPLIT] public static List < String > readLines ( InputStream in ) throws IOException { return readLines ( in , Charsets . DEFAULT ) ; }


Input: Reads all the lines from the given source { @code InputStream } using the specified charset . Note that the returned { @code List } is immutable . [CODESPLIT] public static List < String > readLines ( InputStream in , Charset charset ) throws IOException { return readLines ( new InputStreamReader ( in , charset ) ) ; }


Input: Creates and returns a new immutable { @code KDF } instance implementing the PBKDF1 algorithm ( RFC 2898 ) . [CODESPLIT] public static KDF pbkdf1 ( Algorithm < Digest > digest , int iterationCount , int dkLen ) { return new PBKDF1 ( digest , iterationCount , dkLen ) ; }


Input: Creates and returns a new immutable { @code KDF } instance implementing the PBKDF2 algorithm ( RFC 2898 ) . [CODESPLIT] public static KDF pbkdf2 ( Algorithm < MAC > mac , int iterationCount , int dkLen ) { return new PBKDF2 ( mac , iterationCount , dkLen ) ; }


Input: Creates and returns a new immutable { @code KDF } instance implementing the HKDF algorithm ( RFC 5869 ) . [CODESPLIT] public static KDF hkdf ( Algorithm < MAC > mac , byte [ ] info , int dkLen ) { return new HKDF ( mac , info , dkLen ) ; }


Input: Creates and returns a new immutable { @code KDF } instance implementing the SCrypt algorithm ( RFC 7914 ) . [CODESPLIT] public static KDF scrypt ( int r , int n , int p , int dkLen ) { return new SCrypt ( r , n , p , dkLen ) ; }


Input: Copies the contents of { @code src } to { @code dst } . If { @code dst } doesn t exist it will be created . If it already exists it can be either a directory or a regular file if { @code src } is also a regular file . Named after the Unix command of the same name . [CODESPLIT] public static void cp ( File src , File dst ) throws IOException { if ( ! src . exists ( ) ) { throw new FileNotFoundException ( src + " doesn't exist" ) ; } Parameters . checkCondition ( ( ! dst . exists ( ) || dst . isDirectory ( ) ) || ( src . isFile ( ) && dst . isFile ( ) ) ) ; if ( src . isDirectory ( ) ) { copyDirectory ( src , dst ) ; } else if ( src . isFile ( ) ) { copyFile ( src , dst ) ; } else { throw new IOException ( src + " is neither a directory nor a regular file" ) ; } }


Input: Copies the contents of the given input { @code File } to the given { @code OutputStream } . Named after the Unix command of the same name . [CODESPLIT] public static void cp ( File src , OutputStream dst ) throws IOException { InputStream in = newInputStream ( src ) ; try { ByteStreams . copy ( in , dst ) ; } finally { IO . close ( in ) ; } }


Input: Copies the contents of the given { @code InputStream } to the given output { @code File } . Named after the Unix command of the same name . [CODESPLIT] public static void cp ( InputStream src , File dst ) throws IOException { OutputStream out = newOutputStream ( dst ) ; try { ByteStreams . copy ( src , out ) ; } finally { IO . close ( out ) ; } }


Input: Moves a file from one path to another . Named after the Unix command of the same name . [CODESPLIT] public static void mv ( File src , File dst ) throws IOException { Parameters . checkNotNull ( dst ) ; if ( ! src . equals ( dst ) ) { cp ( src , dst ) ; try { rm ( src ) ; } catch ( IOException e ) { rm ( dst ) ; throw new IOException ( "Can't move " + src , e ) ; } } }


Input: Deletes the given { @code File } s . Directories will be recursively deleted . Named after the Unix command of the same name . [CODESPLIT] public static void rm ( File ... files ) throws IOException { for ( File f : files ) { if ( f . exists ( ) ) { if ( f . isDirectory ( ) ) { rm ( f . listFiles ( ) ) ; } if ( ! f . delete ( ) ) { throw new IOException ( "Can't delete " + f ) ; } } } }


Input: Creates empty files at the specified paths or updates the last modification time of the files at the specified paths . Named after the Unix command of the same name . [CODESPLIT] public static void touch ( File ... files ) throws IOException { long now = System . currentTimeMillis ( ) ; for ( File f : files ) { if ( ! f . createNewFile ( ) && ! f . setLastModified ( now ) ) { throw new IOException ( "Failed to touch " + f ) ; } } }


Input: Reads the first ( up to { @code n } ) bytes of the given { @code File } . Named after the Unix command of the same name . [CODESPLIT] public static byte [ ] head ( File f , int n ) throws IOException { Parameters . checkCondition ( n >= 0 ) ; InputStream in = newInputStream ( f ) ; byte [ ] buf = new byte [ n ] ; try { return XArrays . copyOf ( buf , 0 , in . read ( buf ) ) ; } finally { IO . close ( in ) ; } }


Input: Reads the last ( up to { @code n } ) bytes of the given { @code File } . Named after the Unix command of the same name . [CODESPLIT] public static byte [ ] tail ( File f , int n ) throws IOException { Parameters . checkCondition ( n >= 0 ) ; RandomAccessFile file = new RandomAccessFile ( f , "r" ) ; file . seek ( file . length ( ) - n ) ; byte [ ] data = new byte [ n ] ; file . read ( data ) ; return data ; }


Input: Returns whether the given { @code File } s have the same content . Two regular files are considered equal if they contain the same bytes . Two directories are considered equal if they both contain the same items where an item is either a directory or a regular file ( items must have the same name and content in both directories ) . [CODESPLIT] public static boolean equal ( File f1 , File f2 ) throws IOException { if ( f1 == f2 ) { return true ; } if ( f1 == null || f2 == null || ! haveSameType ( f1 , f2 ) ) { return false ; } return f1 . equals ( f2 ) ? true : haveSameContent ( f1 , f2 ) ; }


Input: Returns the file name without its path or extension . This method is named after the basename Unix command . [CODESPLIT] public static String getBaseName ( File f ) { String fileName = f . getName ( ) ; int index = fileName . lastIndexOf ( ' ' ) ; return index == - 1 ? fileName : fileName . substring ( 0 , index ) ; }


Input: Returns an { @code OutputStream } to write to the given { @code File } . [CODESPLIT] public static BufferedOutputStream newOutputStream ( File f , WriteOption ... options ) throws IOException { Set < WriteOption > opts = ImmutableSet . of ( options ) ; checkWriteOptions ( opts ) ; checkFileExistence ( f , opts ) ; return new BufferedOutputStream ( newOutputStream ( f , opts ) ) ; }


Input: Reads the content of the given { @code File } . [CODESPLIT] public static byte [ ] read ( File f ) throws IOException { InputStream in = newInputStream ( f ) ; try { return ByteStreams . read ( in ) ; } finally { IO . close ( in ) ; } }


Input: Parses a { @code MediaType } from its { @code String } representation . [CODESPLIT] public static MediaType parse ( String input ) { Parameters . checkNotNull ( input ) ; Matcher m = MEDIA_TYPE_PATTERN . matcher ( input ) ; Parameters . checkCondition ( m . matches ( ) ) ; String type = m . group ( 1 ) ; String subtype = m . group ( 2 ) ; String params = m . group ( 3 ) ; ParametersParser parser = new ParametersParser ( ) ; return create ( type , subtype , parser . parse ( params ) ) ; }


Input: Creates a new { @code MediaType } with the given type and subtype . [CODESPLIT] public static MediaType create ( String type , String subtype ) { Map < String , String > params = Collections . emptyMap ( ) ; return create ( type , subtype , params ) ; }


Input: Returns the value of the charset parameter if it is specified or { @code null } otherwise . [CODESPLIT] public Charset charset ( ) { String charset = parameters . get ( CHARSET ) ; return charset == null ? null : Charset . forName ( charset ) ; }


Input: Returns a new { @code MediaType } instance similar to this one but with the specified parameter set to the given value . [CODESPLIT] public MediaType withParameter ( String attribute , String value ) { Map < String , String > params = new HashMap < String , String > ( ) ; params . put ( attribute , value ) ; return withParameters ( params ) ; }


Input: Returns a new { @code MediaType } instance having the same type and subtype as this one but whose parameters is the union of this instances parameters with the given ones ( the given parameters have precedence over this instance s parameters ) . [CODESPLIT] public MediaType withParameters ( Map < String , String > parameters ) { Map < String , String > params = new LinkedHashMap < String , String > ( ) ; params . putAll ( this . parameters ) ; params . putAll ( normalizeParameters ( parameters ) ) ; return new MediaType ( type , subtype , params ) ; }


Input: Returns a new { @code MediaType } instance similar to this one but without the specified parameter . [CODESPLIT] public MediaType withoutParameter ( String attribute ) { Parameters . checkNotNull ( attribute ) ; Map < String , String > params = new LinkedHashMap < String , String > ( ) ; params . putAll ( parameters ) ; params . remove ( attribute ) ; return new MediaType ( type , subtype , params ) ; }


Input: Returns a new { @code MediaType } instance with the same type and subtype as this instance but without any parameters . [CODESPLIT] public MediaType withoutParameters ( ) { Map < String , String > params = Collections . emptyMap ( ) ; return new MediaType ( type , subtype , params ) ; }


Input: Returns whether this media type is within the specified media range . Namely it returns { @code true } if the type of { @code range } is the wildcard or is equal to the type of this instance and if the subtype of { @code range } is the wildcard or is equal to the subtype of this instance and if all the parameters present in { @code range } are also present in this instance . [CODESPLIT] public boolean is ( MediaType range ) { return ( range . type . equals ( WILDCARD ) || range . type . equals ( type ) ) && ( range . subtype . equals ( WILDCARD ) || range . subtype . equals ( subtype ) ) && parameters . entrySet ( ) . containsAll ( range . parameters . entrySet ( ) ) ; }


Input: Concatenates the given { @code Iterable } s into a single one . Note that the returned { @code Iterable } is only a view that is any subsequent update on any of the input { @code Iterable } s will affect the returned view . The input { @code Iterable } s will not be polled until necessary . The returned view s { @code Iterator } supports { @link Iterator#remove () } when the corresponding input { @code Iterator } supports it . [CODESPLIT] public static < T > Iterable < T > concat ( Iterable < ? extends Iterable < ? extends T > > iterables ) { return new ConcatIterable < T > ( iterables ) ; }


Input: 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 () } . [CODESPLIT] public static < T > Iterable < T > cycle ( Iterable < ? extends T > iterable ) { return new CyclicIterable < T > ( toList ( iterable ) ) ; }


Input: Returns an { @code Iterable } that cycles indefinitely over the given elements . The returned { @code Iterable } s { @code Iterator } supports { @link Iterator#remove () } . [CODESPLIT] public static < T > Iterable < T > cycle ( T ... elements ) { return new CyclicIterable < T > ( new ArrayList < T > ( Arrays . asList ( elements ) ) ) ; }


Input: Returns whether the given { @code Iterable } s contain equal elements in the same order . [CODESPLIT] public static boolean equal ( Iterable < ? > i1 , Iterable < ? > i2 ) { if ( i1 == i2 ) { return true ; } if ( i1 == null || i2 == null ) { return false ; } return Iterators . equal ( i1 . iterator ( ) , i2 . iterator ( ) ) ; }


Input: 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 . [CODESPLIT] public static < T > Iterable < T > limit ( Iterable < ? extends T > iterable , int limit ) { return new LimitIterable < T > ( iterable , limit ) ; }


Input: 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 . [CODESPLIT] public static < T > Iterable < T > skip ( Iterable < T > iterable , int n ) { return new SkipIterable < T > ( iterable , n ) ; }


Input: Returns a { @code List } containing all the given { @code Iterable } s elements . [CODESPLIT] public static < T > List < T > toList ( Iterable < ? extends T > iterable ) { List < T > list = new ArrayList < T > ( ) ; for ( T e : iterable ) { list . add ( e ) ; } return list ; }


Input: 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 } . [CODESPLIT] public static < T > Set < T > toSet ( Iterable < ? extends T > iterable ) { Set < T > set = new LinkedHashSet < T > ( ) ; for ( T e : iterable ) { set . add ( e ) ; } return set ; }


Input: 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 } . [CODESPLIT] public static < T > Bag < T > toBag ( Iterable < ? extends T > iterable ) { return new ArrayBag < T > ( iterable ) ; }


Input: Adds the padding bits and the message length to the input data . [CODESPLIT] private void addPadding ( ) { 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 ) ; }


Input: Creates a new { @code ImmutableList } from the given { @code Collection } . [CODESPLIT] public static < E > List < E > copyOf ( Collection < ? extends E > c ) { return new ImmutableList < E > ( new ArrayList < E > ( c ) ) ; }


Input: Creates a new { @code ImmutableList } from the given { @code Iterable } . [CODESPLIT] public static < E > List < E > copyOf ( Iterable < ? extends E > i ) { return new ImmutableList < E > ( Iterables . toList ( i ) ) ; }


Input: Creates a new { @code ImmutableList } from the given { @code Iterator } . [CODESPLIT] public static < E > List < E > copyOf ( Iterator < ? extends E > i ) { return new ImmutableList < E > ( Iterators . toList ( i ) ) ; }


Input: Creates a new { @code ImmutableList } containing the given elements . [CODESPLIT] public static < E > List < E > copyOf ( E [ ] values ) { return new ImmutableList < E > ( Arrays . asList ( values ) ) ; }


Input: Creates a new { @code ImmutableList } containing the given elements . [CODESPLIT] public static < E > List < E > of ( E ... values ) { return new ImmutableList < E > ( Arrays . asList ( values ) ) ; }


Input: 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 . [CODESPLIT] public static List < String > head ( File f , Charset charset ) throws IOException { return head ( f , 10 , charset ) ; }


Input: 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 . [CODESPLIT] public static List < String > head ( File f , int n ) throws IOException { return head ( f , n , Charsets . DEFAULT ) ; }


Input: 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 . [CODESPLIT] public static List < String > head ( File f , int n , Charset charset ) throws IOException { 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 ) ; }


Input: 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 . [CODESPLIT] public static List < String > tail ( File f , Charset charset ) throws IOException { return tail ( f , 10 , charset ) ; }


Input: 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 . [CODESPLIT] public static List < String > tail ( File f , int n , Charset charset ) throws IOException { 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 ) ; }


Input: Returns a new { @code BufferedReader } to read the given { @code File } using the specified charset . [CODESPLIT] public static BufferedReader newReader ( File f , Charset charset ) throws FileNotFoundException { InputStream in = new FileInputStream ( f ) ; return new BufferedReader ( new InputStreamReader ( in , charset ) ) ; }


Input: Returns a new { @code BufferedWriter } to write to the given { @code File } using the system s default charset . [CODESPLIT] public static BufferedWriter newWriter ( File f , WriteOption ... options ) throws IOException { return newWriter ( f , Charsets . DEFAULT , options ) ; }


Input: Returns a new { @code BufferedWriter } to write to the given { @code File } using the specified charset . [CODESPLIT] public static BufferedWriter newWriter ( File f , Charset charset , WriteOption ... options ) throws IOException { OutputStream out = XFiles . newOutputStream ( f , options ) ; return new BufferedWriter ( new OutputStreamWriter ( out , charset ) ) ; }


Input: Reads the whole content of the given { @code File } as a { @code String } using the specified charset . [CODESPLIT] public static String read ( File f , Charset charset ) throws IOException { BufferedReader in = newReader ( f , charset ) ; try { return CharStreams . read ( in ) ; } finally { IO . close ( in ) ; } }


Input: Reads all the lines from the given { @code File } using the system s default charset . Note that the returned { @code List } is immutable . [CODESPLIT] public static List < String > readLines ( File f ) throws IOException { return readLines ( f , Charsets . DEFAULT ) ; }


Input: 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 } . [CODESPLIT] public static URN create ( String urn ) { try { return new URN ( urn ) ; } catch ( URNSyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; } }


Input: 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 . [CODESPLIT] public static Resource find ( String name ) { 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 ) ; }


Input: Finds and returns the resource having the given name ( relative to the specified class ) . [CODESPLIT] public static Resource find ( String name , Class < ? > contextClass ) { Parameters . checkNotNull ( name ) ; URL url = contextClass . getResource ( name ) ; if ( url != null ) { return new Resource ( url ) ; } throw new NotFoundException ( name ) ; }


Input: Copies the content of this resource to the specified stream . [CODESPLIT] public void copyTo ( OutputStream out ) throws IOException { InputStream in = url . openStream ( ) ; try { ByteStreams . copy ( in , out ) ; } finally { IO . close ( in ) ; } }


Input: Copies the content of this resource to the specified stream . [CODESPLIT] public void copyTo ( Writer out , Charset charset ) throws IOException { InputStream in = url . openStream ( ) ; try { CharStreams . copy ( in , out , charset ) ; } finally { IO . close ( in ) ; } }


Input: Reads and returns this resource s content as a { @code byte [] } . [CODESPLIT] public byte [ ] read ( ) throws IOException { InputStream in = url . openStream ( ) ; try { return ByteStreams . read ( in ) ; } finally { IO . close ( in ) ; } }


Input: Reads and returns this resource s content as a { @code String } . [CODESPLIT] public String read ( Charset charset ) throws IOException { InputStream in = url . openStream ( ) ; try { return CharStreams . read ( in , charset ) ; } finally { IO . close ( in ) ; } }


Input: Reads and returns all this resource s lines . Note that the returned { @code List } is immutable . [CODESPLIT] public List < String > readLines ( Charset charset ) throws IOException { InputStream in = url . openStream ( ) ; try { return CharStreams . readLines ( in , charset ) ; } finally { IO . close ( in ) ; } }


Input: Returns whether the given { @code Calendar } s represent the same instant . [CODESPLIT] public static boolean isSameInstant ( Calendar cal1 , Calendar cal2 ) { return isSameInstant ( cal1 . getTime ( ) , cal2 . getTime ( ) ) ; }


Input: Returns whether the given { @code Date } s represent the same local time . [CODESPLIT] public static boolean isSameLocalTime ( Date date1 , Date date2 ) { return isSameLocalTime ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ; }


Input: Returns whether the given { @code Calendar } s represent the same local time . [CODESPLIT] public static boolean isSameLocalTime ( Calendar cal1 , Calendar cal2 ) { 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 ) ; }


Input: Returns whether the given { @code Date } s represent the same day . [CODESPLIT] public static boolean isSameDay ( Date date1 , Date date2 ) { return isSameDay ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ; }


Input: Returns whether the given { @code Calendar } s represent the same day . [CODESPLIT] public static boolean isSameDay ( Calendar cal1 , Calendar cal2 ) { return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( DAY_OF_YEAR ) == cal2 . get ( DAY_OF_YEAR ) ; }


Input: Returns whether the given { @code Date } s represent the same week . [CODESPLIT] public static boolean isSameWeek ( Date date1 , Date date2 ) { return isSameWeek ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ; }


Input: Returns whether the given { @code Calendar } s represent the same week . [CODESPLIT] public static boolean isSameWeek ( Calendar cal1 , Calendar cal2 ) { return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( WEEK_OF_YEAR ) == cal2 . get ( WEEK_OF_YEAR ) ; }


Input: Returns whether the given { @code Date } s represent the same month . [CODESPLIT] public static boolean isSameMonth ( Date date1 , Date date2 ) { return isSameMonth ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ; }


Input: Returns whether the given { @code Calendar } s represent the same month . [CODESPLIT] public static boolean isSameMonth ( Calendar cal1 , Calendar cal2 ) { return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) && cal1 . get ( MONTH ) == cal2 . get ( MONTH ) ; }


Input: Returns whether the given { @code Date } s represent the same year . [CODESPLIT] public static boolean isSameYear ( Date date1 , Date date2 ) { return isSameYear ( toCalendar ( date1 ) , toCalendar ( date2 ) ) ; }


Input: Returns whether the given { @code Calendar } s represent the same year . [CODESPLIT] public static boolean isSameYear ( Calendar cal1 , Calendar cal2 ) { return cal1 . get ( ERA ) == cal2 . get ( ERA ) && cal1 . get ( YEAR ) == cal2 . get ( YEAR ) ; }


Input: 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 } . [CODESPLIT] public static Date parse ( String date , String ... formats ) { return parse ( date , Locale . getDefault ( ) , formats ) ; }


Input: 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 } . [CODESPLIT] public static Date parse ( String date , Locale locale , String ... formats ) { 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 ) ; }


Input: Returns the { @code String } representation of the given { @code Date } according to the specified format pattern . [CODESPLIT] public static String format ( Date date , String format ) { Parameters . checkNotNull ( date ) ; return new SimpleDateFormat ( format ) . format ( date ) ; }


Input: Converts a { @code Date } into a { @code Calendar } . [CODESPLIT] public static Calendar toCalendar ( Date date ) { Calendar calendar = getInstance ( ) ; calendar . setTime ( date ) ; return calendar ; }


Input: 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 . [CODESPLIT] public static < E > Iterator < E > concat ( Iterator < ? extends E > ... iterators ) { return concat ( Arrays . asList ( iterators ) . iterator ( ) ) ; }


Input: 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 . [CODESPLIT] public static < E > Iterator < E > concat ( Iterator < ? extends Iterator < ? extends E > > iterators ) { return new ConcatIterator < E > ( iterators ) ; }


Input: 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 () } . [CODESPLIT] public static < E > Iterator < E > cycle ( Iterator < ? extends E > iterator ) { return new LazyCyclicIterator < E > ( iterator ) ; }


Input: Returns an { @code Iterator } that cycles indefinitely over the given elements . The returned { @code Iterator } supports { @link Iterator#remove () } . [CODESPLIT] public static < E > Iterator < E > cycle ( E ... elements ) { return new CyclicIterator < E > ( Arrays . asList ( elements ) ) ; }


Input: 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 . [CODESPLIT] public static boolean equal ( Iterator < ? > i1 , Iterator < ? > i2 ) { 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 ( ) ) ; }


Input: 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 . [CODESPLIT] public static < E > Iterator < E > limit ( Iterator < ? extends E > iterator , int limit ) { return new LimitIterator < E > ( iterator , limit ) ; }


Input: Skips { @code n } elements from the given { @code Iterator } . [CODESPLIT] public static int skip ( Iterator < ? > iterator , int n ) { Parameters . checkCondition ( n >= 0 ) ; int skipped = 0 ; while ( skipped < n && iterator . hasNext ( ) ) { iterator . next ( ) ; skipped ++ ; } return skipped ; }


Input: 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 } . [CODESPLIT] public static < E > Set < E > toSet ( Iterator < ? extends E > iterator ) { Set < E > set = new LinkedHashSet < E > ( ) ; while ( iterator . hasNext ( ) ) { set . add ( iterator . next ( ) ) ; } return set ; }


Input: 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 } . [CODESPLIT] public static < E > Bag < E > toBag ( Iterator < ? extends E > iterator ) { return new ArrayBag < E > ( iterator ) ; }


Input: Returns whether the given { @code String } only contains space \ n \ r or \ t characters . [CODESPLIT] public static boolean isBlank ( String str ) { for ( char c : str . toCharArray ( ) ) { if ( c != ' ' && c != ' ' && c != ' ' && c != ' ' ) { return false ; } } return true ; }


Input: Abbreviates the given { @code String } using the specified ellipsis so that the returned { @code String } s length is equal to { @code length } . [CODESPLIT] public static String abbreviate ( String str , int length , String ellipsis ) { Parameters . checkCondition ( length > ellipsis . length ( ) ) ; if ( str . length ( ) <= length ) { return str ; } return str . substring ( 0 , length - ellipsis . length ( ) ) + ellipsis ; }


Input: Concatenates the given { @code String } s . [CODESPLIT] public static String concat ( String ... strings ) { StringBuilder sb = new StringBuilder ( strings . length * 10 ) ; for ( String string : strings ) { sb . append ( string ) ; } return sb . toString ( ) ; }


Input: 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 . [CODESPLIT] public static int distance ( String str1 , String str2 ) { char [ ] s1 = str1 . toCharArray ( ) ; char [ ] s2 = str2 . toCharArray ( ) ; int [ ] [ ] d = new int [ s1 . length + 1 ] [ s2 . length + 1 ] ; for ( int i = 0 ; i <= s1 . length ; i ++ ) { d [ i ] [ 0 ] = i ; } for ( int i = 0 ; i <= s2 . length ; i ++ ) { d [ 0 ] [ i ] = i ; } for ( int i = 1 ; i <= s1 . length ; i ++ ) { for ( int j = 1 ; j <= s2 . length ; j ++ ) { int c = s1 [ i - 1 ] == s2 [ j - 1 ] ? 0 : 1 ; d [ i ] [ j ] = min ( d [ i - 1 ] [ j ] + 1 , d [ i ] [ j - 1 ] + 1 , d [ i - 1 ] [ j - 1 ] + c ) ; if ( i > 1 && j > 1 && s1 [ i - 1 ] == s2 [ j - 2 ] && s1 [ i - 2 ] == s2 [ j - 1 ] ) { d [ i ] [ j ] = min ( d [ i ] [ j ] , d [ i - 2 ] [ j - 2 ] + c ) ; } } } return d [ s1 . length ] [ s2 . length ] ; }


Input: 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 . [CODESPLIT] public static String random ( int length , Random rnd , char ... chars ) { 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 ( ) ; }


Input: Returns the { @code String } obtained by repeating { @code count } times the given { @code String } . [CODESPLIT] public static String repeat ( String str , int count ) { Parameters . checkCondition ( count >= 0 ) ; StringBuilder sb = new StringBuilder ( str . length ( ) * count ) ; for ( int i = 0 ; i < count ; i ++ ) { sb . append ( str ) ; } return sb . toString ( ) ; }


Input: 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 . [CODESPLIT] public static String shuffle ( String str , Random rnd ) { return new String ( XArrays . shuffle ( str . toCharArray ( ) , rnd ) ) ; }


Input: Returns the new { @code String } obtained by stripping the first and last { @code n } characters from the given one . [CODESPLIT] public static String strip ( String str , int n ) { return stripRight ( stripLeft ( str , n ) , n ) ; }


Input: Returns the new { @code String } obtained by stripping the first { @code n } characters from the given one . [CODESPLIT] public static String stripLeft ( String str , int n ) { Parameters . checkCondition ( n >= 0 ) ; int start = Math . min ( str . length ( ) , n ) ; return str . substring ( start ) ; }


Input: Returns the new { @code String } obtained by stripping the last { @code n } characters from the given one . [CODESPLIT] public static String stripRight ( String str , int n ) { Parameters . checkCondition ( n >= 0 ) ; int end = Math . max ( 0 , str . length ( ) - n ) ; return str . substring ( 0 , end ) ; }


Input: Returns a copy of the given { @code String } with leading whitespaces omitted . [CODESPLIT] public static String trimLeft ( String str ) { int start = 0 ; for ( char c : str . toCharArray ( ) ) { if ( c != ' ' ) { break ; } start ++ ; } return str . substring ( start ) ; }


Input: Returns a copy of the given { @code String } with trailing whitespaces omitted . [CODESPLIT] public static String trimRight ( String str ) { int end = str . length ( ) ; for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) != ' ' ) { break ; } end -- ; } return str . substring ( 0 , end ) ; }


Input: 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 . [CODESPLIT] public static String padLeft ( String str , int len , char padChar ) { Parameters . checkCondition ( len >= 0 ) ; StringBuilder sb = new StringBuilder ( len ) ; while ( sb . length ( ) < len - str . length ( ) ) { sb . append ( padChar ) ; } sb . append ( str ) ; return sb . toString ( ) ; }


Input: 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 . [CODESPLIT] public static String padRight ( String str , int len , char padChar ) { 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 ( ) ; }


Input: Quotes the given { @code String } with double quotes . If the given { @code String } has multiple quotes only one of them is kept . [CODESPLIT] public static String quote ( String str ) { return new StringBuilder ( str . length ( ) + 2 ) . append ( "\"" ) . append ( unquote ( str ) ) . append ( "\"" ) . toString ( ) ; }


Input: 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 . [CODESPLIT] public static String unquote ( String str ) { String unquoted = str ; while ( unquoted . startsWith ( "\"" ) ) { unquoted = unquoted . substring ( 1 ) ; } while ( unquoted . endsWith ( "\"" ) ) { unquoted = unquoted . substring ( 0 , unquoted . length ( ) - 1 ) ; } return unquoted ; }


Input: Counts the occurrences of the substring { @code sub } in { @code str } . [CODESPLIT] public static int countOccurrences ( String str , String sub ) { 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 ; }


Input: 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 } . [CODESPLIT] public static URL create ( String url ) { Parameters . checkNotNull ( url ) ; try { return new URL ( url ) ; } catch ( MalformedURLException ex ) { throw new IllegalArgumentException ( ex ) ; } }


Input: Relativizes the specified full { @code URL } against the given base . Behaves as { @link java . net . URI#relativize ( java . net . URI ) } . [CODESPLIT] public static String relativize ( URL base , URL full ) { try { return base . toURI ( ) . relativize ( full . toURI ( ) ) . normalize ( ) . toString ( ) ; } catch ( URISyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; } }


Input: Resolves the specified path against the given base { @code URL } . Behaves as { @link java . net . URI#resolve ( java . lang . String ) } . [CODESPLIT] public static URL resolve ( URL base , String path ) { try { return base . toURI ( ) . resolve ( path ) . normalize ( ) . toURL ( ) ; } catch ( URISyntaxException ex ) { throw new IllegalArgumentException ( ex ) ; } catch ( MalformedURLException ex ) { throw new IllegalArgumentException ( ex ) ; } }


Input: 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 . [CODESPLIT] public static String getQualifiedName ( Class < ? > c ) { 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 ( ) ; }


Input: Returns only the name of the given class that is without its package name and without its eventual outer class name . [CODESPLIT] public static String getShortName ( Class < ? > c ) { String qname = getQualifiedName ( c ) ; int start = qname . lastIndexOf ( ' ' ) ; if ( start == - 1 ) { start = qname . lastIndexOf ( ' ' ) ; } return qname . substring ( start + 1 ) ; }


Input: Returns the name of the package of the given class or the empty { @code String } if the class is defined in the default package . [CODESPLIT] public static String getPackageName ( Class < ? > c ) { String name = c . getName ( ) ; int i = name . lastIndexOf ( ' ' ) ; return i != - 1 ? name . substring ( 0 , i ) : "" ; }


Input: 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 . [CODESPLIT] public static Set < Class < ? > > getSuperTypes ( Class < ? > c ) { 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 ) ; }


Input: 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 . [CODESPLIT] public static Set < Class < ? > > getCommonSuperTypes ( Iterable < Class < ? > > classes ) { 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 ) ; }


Input: Verifies that the given password matches the hashed one . [CODESPLIT] public static boolean verify ( String password , byte [ ] hash ) { 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 ; }


Input: Reads the next line from the standard input using the given charset . [CODESPLIT] public static String readString ( Charset charset ) throws IOException { Reader in = new InputStreamReader ( System . in , charset ) ; BufferedReader reader = new BufferedReader ( in ) ; try { return reader . readLine ( ) ; } finally { reader . close ( ) ; } }


Input: Writes the given byte to this buffer . [CODESPLIT] public ByteBuffer append ( byte b ) { int newCount = count + 1 ; ensureCapacity ( newCount ) ; buf [ count ] = b ; count = newCount ; return this ; }


Input: Writes the given data to this buffer . [CODESPLIT] public ByteBuffer append ( byte [ ] bytes , int off , int len ) { int newCount = count + len ; ensureCapacity ( newCount ) ; System . arraycopy ( bytes , off , buf , count , len ) ; count = newCount ; return this ; }


Input: Returns { @code len } bytes from this buffer starting at { @code off } . [CODESPLIT] public byte [ ] toByteArray ( int off , int len ) { 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 ; }


Input: Concatenates the given arrays into a single one . [CODESPLIT] public static long [ ] concat ( long [ ] ... arrays ) { 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 ; }


Input: Concatenates the given arrays into a single one . [CODESPLIT] public static < T > T [ ] concat ( T [ ] ... arrays ) { 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 ; }


Input: 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 } . [CODESPLIT] public static long [ ] copyOf ( long [ ] a , int off , int len ) { 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 ; }


Input: 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 } . [CODESPLIT] public static < T > T [ ] copyOf ( T [ ] a , int off , int len ) { 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 ; }


Input: Returns a copy of the given array . The original array and the returned copy will have identical length and content . [CODESPLIT] public static < T > T [ ] copyOf ( T [ ] original ) { return Arrays . copyOf ( original , original . length ) ; }


Input: Returns a new array containing the same elements as the given one but in reverse order . [CODESPLIT] public static long [ ] reverse ( long ... a ) { int len = a . length ; long [ ] copy = new long [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { copy [ i ] = a [ len - i - 1 ] ; } return copy ; }


Input: Returns a new array containing the same elements as the given one but in reverse order . [CODESPLIT] public static < T > T [ ] reverse ( T [ ] a ) { 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 ; }


Input: 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 . [CODESPLIT] public static long [ ] rotate ( long [ ] a , int distance ) { 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 ; }


Input: 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 . [CODESPLIT] public static < T > T [ ] rotate ( T [ ] a , int distance ) { 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 ; }


Input: 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 . [CODESPLIT] public static int [ ] shuffle ( int [ ] a , Random rnd ) { int [ ] copy = copyOf ( a ) ; for ( int i = copy . length ; i > 1 ; i -- ) { swap ( copy , i - 1 , rnd . nextInt ( i ) ) ; } return copy ; }


Input: 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 ) . [CODESPLIT] public static < T > T [ ] sort ( T [ ] a ) { T [ ] copy = copyOf ( a ) ; Arrays . sort ( copy ) ; return copy ; }


Input: Returns a sorted copy of the given array of objects into ascending order according to the order induced by the given { @code Comparator } . [CODESPLIT] public static < T > T [ ] sort ( T [ ] a , Comparator < ? super T > c ) { T [ ] copy = Arrays . copyOf ( a , a . length ) ; Arrays . sort ( copy , c ) ; return copy ; }


Input: 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 . [CODESPLIT] public static long [ ] toPrimitive ( Long ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static int [ ] toPrimitive ( Integer ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static short [ ] toPrimitive ( Short ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static char [ ] toPrimitive ( Character ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static byte [ ] toPrimitive ( Byte ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static boolean [ ] toPrimitive ( Boolean ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static float [ ] toPrimitive ( Float ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static double [ ] toPrimitive ( Double ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Long [ ] toObject ( long ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Integer [ ] toObject ( int ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Short [ ] toObject ( short ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Character [ ] toObject ( char ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Byte [ ] toObject ( byte ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Boolean [ ] toObject ( boolean ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Float [ ] toObject ( float ... a ) { 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 ; }


Input: 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 . [CODESPLIT] public static Double [ ] toObject ( double ... a ) { 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 ; }


Input: Decodes { @code len } ASCII encoded bytes from the given input buffer starting at { @code off } . [CODESPLIT] public static String decode ( byte [ ] input , int off , int len ) { 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 ) ; } }


Input: Returns whether the given { @code String } is an alphabetic sequence that is a sequence which only contains letters . [CODESPLIT] public static boolean isAlphabetic ( String str ) { for ( char c : str . toCharArray ( ) ) { if ( ! isLetter ( c ) ) { return false ; } } return true ; }


Input: Returns whether the given { @code String } is an alphanumeric sequence that is a sequence which only contains letters and digits . [CODESPLIT] public static boolean isAlphaNumeric ( String str ) { for ( char c : str . toCharArray ( ) ) { if ( ! isDigit ( c ) && ! isLetter ( c ) ) { return false ; } } return true ; }


Input: Returns a { @code String } in which all uppercase ASCII characters have been replaced by their lowercase equivalent ( all other characters are unchanged ) . [CODESPLIT] public static String toLowerCase ( String str ) { StringBuilder sb = new StringBuilder ( str . length ( ) ) ; for ( char c : str . toCharArray ( ) ) { sb . append ( toLowerCase ( c ) ) ; } return sb . toString ( ) ; }


Input: 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 . [CODESPLIT] public BaseEncoding withSeparator ( String separator , int n ) { 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 ) ; }


Input: Encodes the given data bytes according to this { @code BaseEncoding } s configuration . [CODESPLIT] public String encode ( byte [ ] in , int off , int len ) { 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 ( ) ; }


Input: 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 ) . [CODESPLIT] public byte [ ] decode ( String in ) { 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 ( ) ; }


Input: 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 ) . [CODESPLIT] public byte [ ] decode ( String in , int off , int len ) { return decode ( in . substring ( off , off + len ) ) ; }


Input: Returns the { @code Fraction } representation of the given value . [CODESPLIT] public static Fraction valueOf ( Integer val ) { return new Fraction ( BigInteger . valueOf ( val ) , BigInteger . ONE ) ; }


Input: Creates a { @code Fraction } from its { @code String } representation . [CODESPLIT] public static Fraction parse ( String str ) { 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 ) ; }


Input: Adds the given value to this one and returns the result in reduced form . [CODESPLIT] public Fraction plus ( Fraction f ) { return new Fraction ( n . multiply ( f . d ) . add ( f . n . multiply ( d ) ) , d . multiply ( f . d ) ) . reduced ( ) ; }


Input: Subtracts the given value from this one and returns the result in reduced form . [CODESPLIT] public Fraction minus ( Fraction f ) { return new Fraction ( n . multiply ( f . d ) . subtract ( f . n . multiply ( d ) ) , d . multiply ( f . d ) ) . reduced ( ) ; }


Input: Multiplies this value by the given one and returns the result in reduced form . [CODESPLIT] public Fraction multipliedBy ( Fraction f ) { return new Fraction ( n . multiply ( f . n ) , d . multiply ( f . d ) ) . reduced ( ) ; }


Input: Divides this value by the given one and returns the result in reduced form . [CODESPLIT] public Fraction dividedBy ( Fraction f ) { if ( ZERO . equals ( f ) ) { throw new ArithmeticException ( "Division by zero" ) ; } return new Fraction ( n . multiply ( f . d ) , d . multiply ( f . n ) ) . reduced ( ) ; }


Input: Returns the { @code Fraction } obtained by raising this to the given power in reduced form . [CODESPLIT] public Fraction power ( int exponent ) { return new Fraction ( n . pow ( exponent ) , d . pow ( exponent ) ) . reduced ( ) ; }


Input: Returns the opposite of this { @code Fraction } . The result is not reduced before being returned . [CODESPLIT] public Fraction negated ( ) { if ( d . signum ( ) < 0 ) { return new Fraction ( n , d . negate ( ) ) ; } return new Fraction ( n . negate ( ) , d ) ; }


Input: Returns the reduced form of this { @code Fraction } . Also note that the sign information will be held by the numerator . [CODESPLIT] public Fraction reduced ( ) { 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 ) ) ; }


Input: Creates a new { @code ImmutableSet } from the given { @code Collection } . [CODESPLIT] public static < E > Set < E > copyOf ( Collection < ? extends E > c ) { return new ImmutableSet < E > ( new LinkedHashSet < E > ( c ) ) ; }


Input: Creates a new { @code ImmutableSet } from the given { @code Iterable } . [CODESPLIT] public static < E > Set < E > copyOf ( Iterable < ? extends E > i ) { return new ImmutableSet < E > ( Iterables . toSet ( i ) ) ; }


Input: Creates a new { @code ImmutableSet } from the given { @code Iterator } . [CODESPLIT] public static < E > Set < E > copyOf ( Iterator < ? extends E > i ) { return new ImmutableSet < E > ( Iterators . toSet ( i ) ) ; }


Input: Creates a new { @code ImmutableSet } containing the given elements . [CODESPLIT] public static < E > Set < E > copyOf ( E [ ] values ) { return new ImmutableSet < E > ( new LinkedHashSet < E > ( Arrays . asList ( values ) ) ) ; }


Input: Creates a new { @code ImmutableSet } containing the given elements . [CODESPLIT] public static < E > Set < E > of ( E ... values ) { return new ImmutableSet < E > ( new LinkedHashSet < E > ( Arrays . asList ( values ) ) ) ; }


Input: 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 . [CODESPLIT] public static Duration parse ( String duration ) { 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 ) ; }


Input: Creates a new { @code Duration } representing the given amount in the given unit . [CODESPLIT] public static Duration of ( long amount , TimeUnit unit ) { long duration = MILLISECONDS . convert ( amount , unit ) ; if ( unit . convert ( duration , MILLISECONDS ) != amount ) { throw new ArithmeticException ( "Too large duration: " + amount + " " + unit ) ; } return new Duration ( duration ) ; }


Input: Creates a new { @code Duration } instance by summing all the given { @code Duration } s values . [CODESPLIT] public static Duration of ( Duration ... durations ) { 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 ) ; }


Input: Creates a new { @code Duration } instance representing the amount of time elapsed between the given dates . [CODESPLIT] public static Duration between ( Date start , Date end ) { return new Duration ( end . getTime ( ) - start . getTime ( ) ) ; }


Input: Returns the maximum of the given values . [CODESPLIT] public static long max ( long ... values ) { Parameters . checkCondition ( values . length > 0 ) ; long max = values [ 0 ] ; for ( int i = 1 ; i < values . length ; i ++ ) { max = Math . max ( max , values [ i ] ) ; } return max ; }


Input: Returns the minimum of the given values . [CODESPLIT] public static long min ( long ... values ) { Parameters . checkCondition ( values . length > 0 ) ; long min = values [ 0 ] ; for ( int i = 1 ; i < values . length ; i ++ ) { min = Math . min ( min , values [ i ] ) ; } return min ; }


Input: Returns the arithmetic mean of the given values . This method is not subject to overflow . [CODESPLIT] public static double mean ( int ... values ) { Parameters . checkCondition ( values . length > 0 ) ; long sum = 0L ; for ( int value : values ) { sum += value ; } return ( double ) sum / values . length ; }


Input: Returns the arithmetic mean of the given values . This method is not subject to overflow . [CODESPLIT] public static double mean ( long ... values ) { Parameters . checkCondition ( values . length > 0 ) ; BigDecimal sum = BigDecimal . ZERO ; for ( long value : values ) { sum = sum . add ( BigDecimal . valueOf ( value ) ) ; } return sum . divide ( BigDecimal . valueOf ( values . length ) ) . doubleValue ( ) ; }


Input: Returns the absolute value of the given value provided the result fits into a { @code long } . [CODESPLIT] public static long safeAbs ( long a ) { if ( a == Long . MIN_VALUE ) { throw new ArithmeticException ( "Long overflow: abs(" + a + ")" ) ; } return Math . abs ( a ) ; }


Input: Returns the absolute value of the given value provided the result fits into an { @code int } . [CODESPLIT] public static int safeAbs ( int a ) { if ( a == Integer . MIN_VALUE ) { throw new ArithmeticException ( "Int overflow: abs(" + a + ")" ) ; } return Math . abs ( a ) ; }


Input: Returns the difference of { @code a } and { @code b } provided the result fits into a { @code long } . [CODESPLIT] public static long safeSubtract ( long a , long b ) { long diff = a - b ; if ( a < 0L != diff < 0L && a < 0L != b < 0L ) { throw new ArithmeticException ( "Long overflow: " + a + " - " + b ) ; } return diff ; }


Input: Returns the product of { @code a } and { @code b } provided the result fits into a { @code long } . [CODESPLIT] public static long safeMultiply ( long a , long b ) { if ( a == 0L || b == 0L ) { return 0L ; } long max = a < 0L == b < 0L ? Long . MAX_VALUE : Long . MIN_VALUE ; if ( ( b > 0L && b > max / a ) || ( b < 0L && b < max / a ) ) { throw new ArithmeticException ( "Long overflow: " + a + " * " + b ) ; } return a * b ; }


Input: Returns the product of { @code a } and { @code b } provided the result fits into an { @code int } . [CODESPLIT] public static int safeMultiply ( int a , int b ) { if ( a == 0 || b == 0 ) { return 0 ; } long max = a < 0 == b < 0 ? Integer . MAX_VALUE : Integer . MIN_VALUE ; if ( ( b > 0 && b > max / a ) || ( b < 0 && b < max / a ) ) { throw new ArithmeticException ( "Int overflow: " + a + " * " + b ) ; } return a * b ; }


Input: Returns the result of the integer division of the first number by the second provided the result fits into a { @code long } . [CODESPLIT] public static long safeDivide ( long a , long b ) { if ( a == Long . MIN_VALUE && b == - 1L ) { throw new ArithmeticException ( "Long overflow: " + a + " / " + b ) ; } return a / b ; }


Input: Returns the result of the integer division of the first number by the second provided the result fits into an { @code int } . [CODESPLIT] public static int safeDivide ( int a , int b ) { if ( a == Integer . MIN_VALUE && b == - 1L ) { throw new ArithmeticException ( "Int overflow: " + a + " / " + b ) ; } return a / b ; }


Input: Returns the value of the first argument raised to the power of the second provided the result fits into a { @code long } . This method implements the exponentiation by squaring method . Please refer to <a href = http : // en . wikipedia . org / wiki / Exponentiation_by_squaring > Wikipedia< / a > for further information . [CODESPLIT] public static long safePow ( long a , int b ) { Parameters . checkCondition ( b >= 0 ) ; if ( b == 0 ) { return 1L ; } long base = a ; int exponent = b ; long result = 1L ; try { while ( exponent > 1 ) { if ( ( exponent & 1 ) != 0 ) { result = safeMultiply ( result , base ) ; exponent -= 1 ; } base = safeMultiply ( base , base ) ; exponent >>= 1 ; } return safeMultiply ( result , base ) ; } catch ( ArithmeticException e ) { throw new ArithmeticException ( "Long overflow: " + a + " ^ " + b ) ; } }


Input: Returns the greatest common divisor of the absolute value of the given two numbers . This method first computes the absolute values of the given numbers thus it doesn t accept { @code Long . MIN_VALUE } . Also note that if one of the given values is { @code 0 } this method will return the absolute value of the second argument . This method implements the binary GCD algorithm ( also known as Stein s algorithm ) . For further information on this algorithm please refer to <a href = http : // en . wikipedia . org / wiki / Binary_GCD_algorithm > Wikipedia< / a > . [CODESPLIT] public static long gcd ( long a , long b ) { if ( a < 0L || b < 0L ) { try { return gcd ( safeAbs ( a ) , safeAbs ( b ) ) ; } catch ( ArithmeticException e ) { throw new ArithmeticException ( "Long overflow: gcd(" + a + ", " + b + ")" ) ; } } if ( a == 0L ) { return b ; } if ( b == 0L ) { return a ; } int shift = 0 ; while ( ( ( a | b ) & 1L ) == 0 ) { a >>= 1 ; b >>= 1 ; shift ++ ; } while ( ( a & 1L ) == 0L ) { a >>= 1 ; } do { while ( ( b & 1L ) == 0L ) { b >>= 1 ; } if ( a > b ) { long tmp = b ; b = a ; a = tmp ; } b -= a ; } while ( b != 0L ) ; return a << shift ; }


Input: Returns the greatest common divisor of the absolute value of the given two numbers . This method first computes the absolute values of the given numbers thus it doesn t accept { @code Integer . MIN_VALUE } . Also note that if one of the given values is { @code 0 } this method will return the absolute value of the second argument . This method implements the binary GCD algorithm ( also known as Stein s algorithm ) . For further information on this algorithm please refer to <a href = http : // en . wikipedia . org / wiki / Binary_GCD_algorithm > Wikipedia< / a > . [CODESPLIT] public static int gcd ( int a , int b ) { try { if ( a < 0 || b < 0 ) { return gcd ( safeAbs ( a ) , safeAbs ( b ) ) ; } return ( int ) gcd ( ( long ) a , ( long ) b ) ; } catch ( ArithmeticException e ) { throw new ArithmeticException ( "Int overflow: gcd(" + a + ", " + b + ")" ) ; } }


Input: Returns the least common multiple of the absolute value of the given two numbers . This method first computes the absolute values of the given numbers thus it doesn t accept { @code Long . MIN_VALUE } . Also note that if one of the given values is { @code 0 } this method will return the absolute value of the second argument . This method uses the formula { @code lcm ( a b ) = ( a / gcd ( a b )) * b } . Please refer to <a href = http : // en . wikipedia . org / wiki / Least_common_multiple > Wikipedia< / a > for further information . [CODESPLIT] public static long lcm ( long a , long b ) { try { if ( a < 0L || b < 0L ) { return lcm ( safeAbs ( a ) , safeAbs ( b ) ) ; } if ( a == 0L ) { return b ; } if ( b == 0L ) { return a ; } return safeMultiply ( a / gcd ( a , b ) , b ) ; } catch ( ArithmeticException e ) { throw new ArithmeticException ( "Long overflow: lcm(" + a + ", " + b + ")" ) ; } }


Input: Casts the given { @code long } value to { @code int } if possible . [CODESPLIT] public static int safeToInt ( long a ) { if ( a >= Integer . MIN_VALUE && a <= Integer . MAX_VALUE ) { return ( int ) a ; } throw new ArithmeticException ( a + " can't be cast to int" ) ; }


Input: Checks that the given reference is not { @code null } and returns it in case of success . [CODESPLIT] public static < T > T checkNotNull ( T ref , String msg , Object ... args ) { if ( ref == null ) { throw new NullPointerException ( format ( msg , args ) ) ; } return ref ; }


Input: Checks the truth of the given condition checking parameters validity . [CODESPLIT] public static void checkCondition ( boolean condition , String msg , Object ... args ) { if ( ! condition ) { throw new IllegalArgumentException ( format ( msg , args ) ) ; } }


Input: Checks the type of the given reference and in case of success casts and returns it . [CODESPLIT] public static < T > T checkType ( Object ref , Class < T > type ) { if ( type . isInstance ( ref ) ) { return type . cast ( ref ) ; } throw new ClassCastException ( ) ; }


Input: Checks the type of the given reference and in case of success casts and returns it . [CODESPLIT] public static < T > T checkType ( Object ref , Class < T > type , String msg , Object ... args ) { if ( type . isInstance ( ref ) ) { return type . cast ( ref ) ; } throw new ClassCastException ( format ( msg , args ) ) ; }


Input: Performs a logical and on the given values that is this method returns { @code true } if and only if all the given { @code Boolean } values are { @code true } and { @code false } in all other cases . [CODESPLIT] public static Boolean and ( Boolean ... bools ) { Parameters . checkCondition ( bools . length > 0 ) ; for ( Boolean bool : bools ) { if ( ! bool ) { return FALSE ; } } return TRUE ; }


Input: Performs an exclusive or on the given values that is this method returns { @code true } if and only if only one of the given { @code Boolean } values is { @code true } and { @code false } in all other cases . [CODESPLIT] public static Boolean xor ( Boolean ... bools ) { Parameters . checkCondition ( bools . length > 0 ) ; boolean xor = false ; for ( Boolean bool : bools ) { if ( bool ) { if ( xor ) { return FALSE ; } else { xor = true ; } } } return xor ? TRUE : FALSE ; }


Input: Parses the given { @code String } into a { @code Boolean } . This method returns { @code true } if the given { @code String } contains true yes 1 or on . [CODESPLIT] public static Boolean valueOf ( String bool ) { String s = bool . replaceAll ( "\\s" , "" ) ; boolean b = "true" . equalsIgnoreCase ( s ) || "yes" . equalsIgnoreCase ( s ) || "on" . equalsIgnoreCase ( s ) || "1" . equalsIgnoreCase ( s ) ; return b ? TRUE : FALSE ; }


Input: Returns a new { @code Splitter } that will use the specified separator to split { @code String } s . [CODESPLIT] public static Splitter on ( String separator ) { return on ( Pattern . compile ( Pattern . quote ( separator ) ) ) ; }


Input: Returns a new { @code Splitter } that will use the specified pattern to split { @code String } s . [CODESPLIT] public static Splitter on ( Pattern pattern ) { return new Splitter ( - 1 , false , pattern , null , null , "" , false ) ; }


Input: Returns a new { @code Splitter } that will behave as this one except that it will limit the number of times the splitting pattern is applied . If { @code limit } is strictly positive then the pattern will be applied at most { @code limit - 1 } times . If { @code limit } is non - positive then the splitting pattern will be applied as many times as possible . [CODESPLIT] public Splitter limit ( int limit ) { return new Splitter ( limit == 0 ? - 1 : limit , trim , pattern , prefix , suffix , forEmpty , ignoreEmptyStrings ) ; }


Input: Returns a new { @code Splitter } that will behave as this one except that it will ignore the given prefix . [CODESPLIT] public Splitter ignorePrefix ( String prefix ) { Parameters . checkNotNull ( prefix ) ; return new Splitter ( limit , trim , pattern , prefix , suffix , forEmpty , ignoreEmptyStrings ) ; }


Input: Returns a new { @code Splitter } that will behave as this one except that it will ignore the given suffix . [CODESPLIT] public Splitter ignoreSuffix ( String suffix ) { Parameters . checkNotNull ( suffix ) ; return new Splitter ( limit , trim , pattern , prefix , suffix , forEmpty , ignoreEmptyStrings ) ; }


Input: Returns a new { @code Splitter } that will behave as this one except that it will ignore empty results . [CODESPLIT] public Splitter ignoreEmptyStrings ( ) { return new Splitter ( limit , trim , pattern , prefix , suffix , forEmpty , true ) ; }


Input: Returns a new { @code Splitter } that will behave as this one except that it will replace empty results by the specified { @code String } . [CODESPLIT] public Splitter replaceEmptyStringWith ( String forEmpty ) { return new Splitter ( limit , trim , pattern , prefix , suffix , forEmpty , false ) ; }


Input: Splits the given { @code String } into parts according to its configuration . [CODESPLIT] public List < String > split ( String s ) { String [ ] parts = pattern . split ( removePrefixAndSuffix ( s ) , limit ) ; List < String > results = new ArrayList < String > ( parts . length ) ; for ( String part : parts ) { String str = trim ? part . trim ( ) : part ; if ( ! str . isEmpty ( ) ) { results . add ( str ) ; } else if ( ! ignoreEmptyStrings ) { results . add ( forEmpty ) ; } } return Collections . unmodifiableList ( results ) ; }


Input: Returns a { @code Comparator } that will call each { @code Comparator } in the given array until one of them returns a non - zero result ( will return { @code 0 } if they all return { @code 0 } ) . [CODESPLIT] public static < T > Comparator < T > compose ( Comparator < ? super T > ... comparators ) { return compose ( Arrays . asList ( comparators ) ) ; }


Input: Returns a { @code Comparator } that will call each { @code Comparator } in the given { @code Iterable } until one of them returns a non - zero result ( will return { @code 0 } if they all return { @code 0 } ) . [CODESPLIT] public static < T > Comparator < T > compose ( Iterable < ? extends Comparator < ? super T > > comparators ) { return new CompositeComparator < T > ( comparators ) ; }


Input: Returns a { @code Comparator } that represents the reverse ordering of the given one . Namely the returned { @code Comparator } will return a negative value if the original returns a positive value and conversely will return a positive value if it returns a negative value . [CODESPLIT] public static < T > Comparator < T > reverse ( final Comparator < T > comparator ) { Parameters . checkNotNull ( comparator ) ; return new Comparator < T > ( ) { @ Override public int compare ( T o1 , T o2 ) { return - comparator . compare ( o1 , o2 ) ; } } ; }


Input: Returns a { @code Comparator } that compares { @code Comparable } objects in natural order . The returned comparator doesn t accept { @code null } values . [CODESPLIT] public static < T extends Comparable < ? super T > > Comparator < T > naturalOrder ( ) { return new Comparator < T > ( ) { @ Override public int compare ( T o1 , T o2 ) { return o1 . compareTo ( Parameters . checkNotNull ( o2 ) ) ; } } ; }


Input: Returns a new { @code Comparator } that considers { @code null } values as less than all other values and compares non - { @code null } values with the given { @code Comparator } . [CODESPLIT] public static < T > Comparator < T > withNullsFirst ( final Comparator < T > comparator ) { Parameters . checkNotNull ( comparator ) ; return new Comparator < T > ( ) { @ Override public int compare ( T o1 , T o2 ) { return o1 == o2 ? 0 : o1 == null ? - 1 : o2 == null ? 1 : comparator . compare ( o1 , o2 ) ; } } ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will trim inputs before joining them . [CODESPLIT] public Joiner trimInputs ( ) { return new Joiner ( separator , prefix , suffix , true , ignoreNull , ignoreEmpty , forNull , forEmpty ) ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will ignore { @code null } input values . [CODESPLIT] public Joiner ignoreNulls ( ) { return new Joiner ( separator , prefix , suffix , trim , true , ignoreEmpty , forNull , forEmpty ) ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will ignore empty input { @code String } s . [CODESPLIT] public Joiner ignoreEmptyStrings ( ) { return new Joiner ( separator , prefix , suffix , trim , ignoreNull , true , forNull , forEmpty ) ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will replace { @code null } input values with the specified { @code String } . [CODESPLIT] public Joiner replaceNullWith ( String forNull ) { return new Joiner ( separator , prefix , suffix , trim , false , ignoreEmpty , forNull , forEmpty ) ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will replace empty input { @code String } s with the specified value . [CODESPLIT] public Joiner replaceEmptyStringWith ( String forEmpty ) { return new Joiner ( separator , prefix , suffix , trim , ignoreNull , false , forNull , forEmpty ) ; }


Input: Returns a new { @code Joiner } that will behave as this one except that it will use the specified prefix when joining { @code String } s . [CODESPLIT] public Joiner withPrefix ( String prefix ) { return new Joiner ( separator , prefix , suffix , trim , ignoreNull , ignoreEmpty , forNull , forEmpty ) ; }


Input: Joins the given { @code String } s according to its configuration . [CODESPLIT] public String join ( Iterable < ? > parts ) { boolean first = true ; StringBuilder sb = new StringBuilder ( prefix ) ; for ( Object part : parts ) { String s = format ( part ) ; if ( s != null ) { if ( first ) { first = false ; } else { sb . append ( separator ) ; } sb . append ( s ) ; } } return sb . append ( suffix ) . toString ( ) ; }


Input: Creates and returns a { @link Digest } instance corresponding to the given algorithm . [CODESPLIT] static Digest newDigest ( Algorithm < Digest > algorithm ) { Parameters . checkNotNull ( algorithm ) ; Digest digest ; if ( algorithm == Algorithm . MD2 ) { digest = Digests . md2 ( ) ; } else if ( algorithm == Algorithm . MD4 ) { digest = Digests . md4 ( ) ; } else if ( algorithm == Algorithm . MD5 ) { digest = Digests . md5 ( ) ; } else if ( algorithm == Algorithm . SHA1 ) { digest = Digests . sha1 ( ) ; } else if ( algorithm == Algorithm . SHA256 ) { digest = Digests . sha256 ( ) ; } else if ( algorithm == Algorithm . SHA512 ) { digest = Digests . sha512 ( ) ; } else if ( algorithm == Algorithm . KECCAK224 ) { digest = Digests . keccak224 ( ) ; } else if ( algorithm == Algorithm . KECCAK256 ) { digest = Digests . keccak256 ( ) ; } else if ( algorithm == Algorithm . KECCAK384 ) { digest = Digests . keccak384 ( ) ; } else if ( algorithm == Algorithm . KECCAK512 ) { digest = Digests . keccak512 ( ) ; } else { throw new IllegalArgumentException ( "Unknown algorithm" ) ; } return digest ; }


Input: Creates and returns a { @link MAC } instance corresponding to the given algorithm initialized with the provided secret key . [CODESPLIT] static MAC newMAC ( Algorithm < MAC > algorithm , byte [ ] key ) { Parameters . checkNotNull ( algorithm ) ; MAC mac ; if ( algorithm == Algorithm . HMAC_MD2 ) { mac = HMAC . md2 ( key ) ; } else if ( algorithm == Algorithm . HMAC_MD4 ) { mac = HMAC . md4 ( key ) ; } else if ( algorithm == Algorithm . HMAC_MD5 ) { mac = HMAC . md5 ( key ) ; } else if ( algorithm == Algorithm . HMAC_SHA1 ) { mac = HMAC . sha1 ( key ) ; } else if ( algorithm == Algorithm . HMAC_SHA256 ) { mac = HMAC . sha256 ( key ) ; } else if ( algorithm == Algorithm . HMAC_SHA512 ) { mac = HMAC . sha512 ( key ) ; } else if ( algorithm == Algorithm . HMAC_KECCAK224 ) { mac = HMAC . keccak224 ( key ) ; } else if ( algorithm == Algorithm . HMAC_KECCAK256 ) { mac = HMAC . keccak256 ( key ) ; } else if ( algorithm == Algorithm . HMAC_KECCAK384 ) { mac = HMAC . keccak384 ( key ) ; } else if ( algorithm == Algorithm . HMAC_KECCAK512 ) { mac = HMAC . keccak512 ( key ) ; } else { throw new IllegalArgumentException ( "Unknown algorithm" ) ; } return mac ; }


Input: Creates a new { @code ImmutableBag } from the given { @code Collection } . [CODESPLIT] public static < E > Bag < E > copyOf ( Collection < ? extends E > c ) { return new ImmutableBag < E > ( new ArrayBag < E > ( c ) ) ; }


Input: Creates a new { @code ImmutableBag } from the given { @code Iterable } . [CODESPLIT] public static < E > Bag < E > copyOf ( Iterable < ? extends E > i ) { return new ImmutableBag < E > ( new ArrayBag < E > ( i ) ) ; }


Input: Creates a new { @code ImmutableBag } from the given { @code Iterator } . [CODESPLIT] public static < E > Bag < E > copyOf ( Iterator < ? extends E > i ) { return new ImmutableBag < E > ( new ArrayBag < E > ( i ) ) ; }


Input: Creates a new { @code ImmutableBag } containing the given elements . [CODESPLIT] public static < E > Bag < E > copyOf ( E [ ] values ) { return new ImmutableBag < E > ( new ArrayBag < E > ( values ) ) ; }


Input: Creates a new { @code ImmutableBag } containing the given elements . [CODESPLIT] public static < E > Bag < E > of ( E ... values ) { return new ImmutableBag < E > ( new ArrayBag < E > ( values ) ) ; }


Input: ------------------------------------------------------------- [CODESPLIT] private String getRelationHref ( Link link , Object [ ] args , Annotation [ ] [ ] parameterAnnotations ) { HalLink halLink = halResource . getLink ( link . relation ( ) ) ; if ( halLink == null ) { throw new UnsupportedOperationException ( link . relation ( ) ) ; } if ( halLink . getDeprecation ( ) != null ) { log . warn ( "Link '" + link + "' has been deprecated: " + halLink . getDeprecation ( ) ) ; } String href ; if ( halLink . isTemplated ( ) ) { try { UriTemplate uriTemplate = UriTemplate . fromTemplate ( halLink . getHref ( ) ) ; for ( int i = 0 ; i < args . length ; i ++ ) { for ( Annotation annotation : parameterAnnotations [ i ] ) { if ( annotation . annotationType ( ) == UriVariable . class ) { UriVariable uriVariable = ( UriVariable ) annotation ; assignTemplateValue ( uriTemplate , uriVariable . name ( ) , args [ i ] ) ; } } } for ( int i = 0 ; i < link . uriValues ( ) . length ; i ++ ) { UriValue uriValue = link . uriValues ( ) [ i ] ; assignTemplateValue ( uriTemplate , uriValue . name ( ) , uriValue . value ( ) ) ; } href = uriTemplate . expand ( ) ; } catch ( MalformedUriTemplateException | VariableExpansionException e ) { throw new RuntimeException ( e ) ; } } else { href = halLink . getHref ( ) ; } return href ; }


Input: ------------------------------------------------------------- [CODESPLIT] public AmazonServiceException handle ( HttpResponse response ) throws Exception { JSONObject jsonBody = getBodyAsJson ( response ) ; Class < ? extends AmazonServiceException > exceptionClass = exceptionClasses . get ( response . getStatusCode ( ) ) ; AmazonServiceException result ; // Support other attribute names for the message? // TODO: Inspect exception type (caching details) and apply other values from the body String message = jsonBody . has ( "message" ) ? jsonBody . getString ( "message" ) : jsonBody . getString ( "Message" ) ; if ( exceptionClass != null ) { result = exceptionClass . getConstructor ( String . class ) . newInstance ( message ) ; } else { result = AmazonServiceException . class . getConstructor ( String . class ) . newInstance ( message ) ; } result . setServiceName ( response . getRequest ( ) . getServiceName ( ) ) ; result . setStatusCode ( response . getStatusCode ( ) ) ; if ( response . getStatusCode ( ) < 500 ) { result . setErrorType ( ErrorType . Client ) ; } else { result . setErrorType ( ErrorType . Service ) ; } for ( Entry < String , String > headerEntry : response . getHeaders ( ) . entrySet ( ) ) { if ( headerEntry . getKey ( ) . equalsIgnoreCase ( "X-Amzn-RequestId" ) ) { result . setRequestId ( headerEntry . getValue ( ) ) ; } } return result ; }


Input: ------------------------------------------------------------- [CODESPLIT] private JSONObject getBodyAsJson ( HttpResponse response ) { try ( InputStream stream = response . getContent ( ) ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String line = reader . readLine ( ) ; if ( line == null ) { break ; } sb . append ( line ) ; } return new JSONObject ( sb . length ( ) == 0 ? "{}" : sb . toString ( ) ) ; } catch ( IOException e ) { throw new AmazonClientException ( "Unable to read error response: " + e . getMessage ( ) , e ) ; } catch ( JSONException e ) { throw new AmazonClientException ( "Unable to parse error response: " + e . getMessage ( ) , e ) ; } }


Input: ------------------------------------------------------------- [CODESPLIT] @ Override public Map < String , HalResource > unmarshall ( JsonUnmarshallerContext context ) throws Exception { Map < String , HalResource > embedded = new LinkedHashMap <> ( ) ; JsonToken token = context . getCurrentToken ( ) ; while ( token != null && token != JsonToken . END_OBJECT ) { if ( token == JsonToken . FIELD_NAME ) { // Ignore the field name and move to the next token.  The item's key will be the embedded resource's selfHref. token = context . nextToken ( ) ; if ( token == JsonToken . START_ARRAY ) { List < HalResource > halResources = new HalJsonArrayUnmarshaller <> ( HalJsonResourceUnmarshaller . getInstance ( ) ) . unmarshall ( context ) ; for ( HalResource halResource : halResources ) { embedded . put ( halResource . _getSelfHref ( ) , halResource ) ; } } else { HalResource halResource = HalJsonResourceUnmarshaller . getInstance ( ) . unmarshall ( context ) ; embedded . put ( halResource . _getSelfHref ( ) , halResource ) ; } } token = context . nextToken ( ) ; } return embedded ; }


Input: ------------------------------------------------------------- [CODESPLIT] private HalClient getHalClient ( ) { if ( halClient == null ) { this . halClient = new HalClient ( clientConfiguration == null ? new ClientConfiguration ( ) : clientConfiguration , endpoint , serviceName , awsCredentialsProvider == null ? new DefaultAWSCredentialsProviderChain ( ) : awsCredentialsProvider , resourceCache == null ? ImmediatelyExpiringCache . getInstance ( ) : resourceCache , errorResponseHandler ) ; if ( regionId != null ) { halClient . setSignerRegionOverride ( regionId ) ; } } return halClient ; }


Input: ------------------------------------------------------------- [CODESPLIT] @ Override public List < Object > unmarshall ( JsonUnmarshallerContext context ) throws Exception { List < Object > list = new ArrayList <> ( ) ; JsonToken token = context . getCurrentToken ( ) ; while ( token != null && token != JsonToken . END_ARRAY ) { if ( token . isScalarValue ( ) ) { list . add ( JsonUnmarshallerUtil . getObjectForToken ( token , context ) ) ; } else if ( token == JsonToken . START_OBJECT ) { context . nextToken ( ) ; list . add ( HalJsonMapUnmarshaller . getInstance ( ) . unmarshall ( context ) ) ; } else if ( token == JsonToken . START_ARRAY ) { context . nextToken ( ) ; list . add ( HalJsonListUnmarshaller . getInstance ( ) . unmarshall ( context ) ) ; } token = context . nextToken ( ) ; } return list ; }


Input: ------------------------------------------------------------- [CODESPLIT] @ Override public Map < String , Object > unmarshall ( JsonUnmarshallerContext context ) throws Exception { Map < String , Object > map = new HashMap <> ( ) ; JsonToken token = context . getCurrentToken ( ) ; while ( token != null && token != JsonToken . END_OBJECT ) { if ( token == JsonToken . FIELD_NAME ) { String property = context . readText ( ) ; token = context . nextToken ( ) ; if ( token == JsonToken . START_OBJECT ) { context . nextToken ( ) ; map . put ( property , HalJsonMapUnmarshaller . getInstance ( ) . unmarshall ( context ) ) ; } else if ( token == JsonToken . START_ARRAY ) { context . nextToken ( ) ; map . put ( property , HalJsonListUnmarshaller . getInstance ( ) . unmarshall ( context ) ) ; } else { map . put ( property , JsonUnmarshallerUtil . getObjectForToken ( token , context ) ) ; } } token = context . nextToken ( ) ; } return map ; }


Input: ------------------------------------------------------------- [CODESPLIT] public < T > T getResource ( Class < T > resourceClass , String resourcePath ) { return getResource ( null , resourceClass , resourcePath , false ) ; }


Input: ------------------------------------------------------------- [CODESPLIT] < T > T getResource ( HalResource sourceResource , Class < T > resourceClass , String resourcePath , boolean lazy ) { if ( resourceCache . containsKey ( resourcePath ) ) { return resourceClass . cast ( resourceCache . get ( resourcePath ) ) ; } HalResource halResource ; if ( sourceResource != null && sourceResource . getEmbedded ( ) . containsKey ( resourcePath ) ) { halResource = sourceResource . getEmbedded ( ) . get ( resourcePath ) ; } else if ( lazy ) { halResource = null ; } else { halResource = getHalResource ( resourcePath ) ; } return createAndCacheResource ( resourceClass , resourcePath , halResource ) ; }