signature:
public class Joiner { /** * Appends the string representation of each of { @ code parts } , using the previously configured
 * separator between each , to { @ code builder } . Identical to { @ link # appendTo ( Appendable ,
 * Iterable ) } , except that it does not throw { @ link IOException } . */
@ CanIgnoreReturnValue public final StringBuilder appendTo ( StringBuilder builder , Iterable < ? > parts ) { } }

implementation: return appendTo ( builder , parts . iterator ( ) ) ;


signature:
public class Joiner { /** * Appends the string representation of each of { @ code parts } , using the previously configured
 * separator between each , to { @ code builder } . Identical to { @ link # appendTo ( Appendable ,
 * Iterable ) } , except that it does not throw { @ link IOException } . */
@ CanIgnoreReturnValue public final StringBuilder appendTo ( StringBuilder builder , Object [ ] parts ) { } }

implementation: return appendTo ( builder , Arrays . asList ( parts ) ) ;


signature:
public class Joiner { /** * Appends to { @ code builder } the string representation of each of the remaining arguments .
 * Identical to { @ link # appendTo ( Appendable , Object , Object , Object . . . ) } , except that it does not
 * throw { @ link IOException } . */
@ CanIgnoreReturnValue public final StringBuilder appendTo ( StringBuilder builder , @ Nullable Object first , @ Nullable Object second , Object ... rest ) { } }

implementation: return appendTo ( builder , iterable ( first , second , rest ) ) ;


signature:
public class Joiner { /** * Returns a string containing the string representation of each argument , using the previously
 * configured separator between each . */
public final String join ( @ Nullable Object first , @ Nullable Object second , Object ... rest ) { } }

implementation: return join ( iterable ( first , second , rest ) ) ;


signature:
public class Joiner { /** * Returns a joiner with the same behavior as this joiner , except automatically skipping over any
 * provided null elements . */
public Joiner skipNulls ( ) { } }

implementation: return new Joiner ( this ) { @ Override public < A extends Appendable > A appendTo ( A appendable , Iterator < ? > parts ) throws IOException { checkNotNull ( appendable , "appendable" ) ; checkNotNull ( parts , "parts" ) ; while ( parts . hasNext ( ) ) { Object part = parts . next ( ) ; if ( part != null ) { appendable . append ( Joiner . this . toString ( part ) ) ; break ; } } while ( parts . hasNext ( ) ) { Object part = parts . next ( ) ; if ( part != null ) { appendable . append ( separator ) ; appendable . append ( Joiner . this . toString ( part ) ) ; } } return appendable ; } @ Override public Joiner useForNull ( String nullText ) { throw new UnsupportedOperationException ( "already specified skipNulls" ) ; } @ Override public MapJoiner withKeyValueSeparator ( String kvs ) { throw new UnsupportedOperationException ( "can't use .skipNulls() with maps" ) ; } } ;


signature:
public class ImmutableIntArray { /** * Returns an immutable array containing the given values , in order . */
public static ImmutableIntArray of ( int e0 , int e1 , int e2 , int e3 ) { } }

implementation: return new ImmutableIntArray ( new int [ ] { e0 , e1 , e2 , e3 } ) ;


signature:
public class ImmutableIntArray { /** * okay since we have to copy the just - created array anyway . */
public static ImmutableIntArray of ( int first , int ... rest ) { } }

implementation: checkArgument ( rest . length <= Integer . MAX_VALUE - 1 , "the total number of elements must fit in an int" ) ; int [ ] array = new int [ rest . length + 1 ] ; array [ 0 ] = first ; System . arraycopy ( rest , 0 , array , 1 , rest . length ) ; return new ImmutableIntArray ( array ) ;


signature:
public class ImmutableIntArray { /** * Returns an immutable array containing the given values , in order . */
public static ImmutableIntArray copyOf ( int [ ] values ) { } }

implementation: return values . length == 0 ? EMPTY : new ImmutableIntArray ( Arrays . copyOf ( values , values . length ) ) ;


signature:
public class ImmutableIntArray { /** * Returns an immutable array containing the given values , in order . */
public static ImmutableIntArray copyOf ( Collection < Integer > values ) { } }

implementation: return values . isEmpty ( ) ? EMPTY : new ImmutableIntArray ( Ints . toArray ( values ) ) ;


signature:
public class ImmutableIntArray { /** * Returns an immutable array containing the given values , in order .
 * < p > < b > Performance note : < / b > this method delegates to { @ link # copyOf ( Collection ) } if { @ code
 * values } is a { @ link Collection } . Otherwise it creates a { @ link # builder } and uses { @ link
 * Builder # addAll ( Iterable ) } , with all the performance implications associated with that . */
public static ImmutableIntArray copyOf ( Iterable < Integer > values ) { } }

implementation: if ( values instanceof Collection ) { return copyOf ( ( Collection < Integer > ) values ) ; } return builder ( ) . addAll ( values ) . build ( ) ;


signature:
public class ImmutableIntArray { /** * Returns an immutable array containing all the values from { @ code stream } , in order . */
public static ImmutableIntArray copyOf ( IntStream stream ) { } }

implementation:
// Note this uses very different growth behavior from copyOf ( Iterable ) and the builder .
int [ ] array = stream . toArray ( ) ; return ( array . length == 0 ) ? EMPTY : new ImmutableIntArray ( array ) ;


signature:
public class ImmutableIntArray { /** * Returns the smallest index for which { @ link # get } returns { @ code target } , or { @ code - 1 } if no
 * such index exists . Equivalent to { @ code asList ( ) . indexOf ( target ) } . */
public int indexOf ( int target ) { } }

implementation: for ( int i = start ; i < end ; i ++ ) { if ( array [ i ] == target ) { return i - start ; } } return - 1 ;


signature:
public class ImmutableIntArray { /** * Returns a new immutable array containing the values in the specified range .
 * < p > < b > Performance note : < / b > The returned array has the same full memory footprint as this one
 * does ( no actual copying is performed ) . To reduce memory usage , use { @ code subArray ( start ,
 * end ) . trimmed ( ) } . */
public ImmutableIntArray subArray ( int startIndex , int endIndex ) { } }

implementation: Preconditions . checkPositionIndexes ( startIndex , endIndex , length ( ) ) ; return startIndex == endIndex ? EMPTY : new ImmutableIntArray ( array , start + startIndex , start + endIndex ) ;


signature:
public class DoubleMath { /** * Returns the { @ code int } value that is equal to { @ code x } rounded with the specified rounding
 * mode , if possible .
 * @ throws ArithmeticException if
 * < ul >
 * < li > { @ code x } is infinite or NaN
 * < li > { @ code x } , after being rounded to a mathematical integer using the specified rounding
 * mode , is either less than { @ code Integer . MIN _ VALUE } or greater than { @ code
 * Integer . MAX _ VALUE }
 * < li > { @ code x } is not a mathematical integer and { @ code mode } is { @ link
 * RoundingMode # UNNECESSARY }
 * < / ul > */
@ GwtIncompatible // # roundIntermediate
public static int roundToInt ( double x , RoundingMode mode ) { } }

implementation: double z = roundIntermediate ( x , mode ) ; checkInRangeForRoundingInputs ( z > MIN_INT_AS_DOUBLE - 1.0 & z < MAX_INT_AS_DOUBLE + 1.0 , x , mode ) ; return ( int ) z ;


signature:
public class DoubleMath { /** * Returns the { @ code long } value that is equal to { @ code x } rounded with the specified rounding
 * mode , if possible .
 * @ throws ArithmeticException if
 * < ul >
 * < li > { @ code x } is infinite or NaN
 * < li > { @ code x } , after being rounded to a mathematical integer using the specified rounding
 * mode , is either less than { @ code Long . MIN _ VALUE } or greater than { @ code
 * Long . MAX _ VALUE }
 * < li > { @ code x } is not a mathematical integer and { @ code mode } is { @ link
 * RoundingMode # UNNECESSARY }
 * < / ul > */
@ GwtIncompatible // # roundIntermediate
public static long roundToLong ( double x , RoundingMode mode ) { } }

implementation: double z = roundIntermediate ( x , mode ) ; checkInRangeForRoundingInputs ( MIN_LONG_AS_DOUBLE - z < 1.0 & z < MAX_LONG_AS_DOUBLE_PLUS_ONE , x , mode ) ; return ( long ) z ;


signature:
public class DoubleMath { /** * # roundIntermediate , java . lang . Math . getExponent , com . google . common . math . DoubleUtils */
@ GwtIncompatible public static BigInteger roundToBigInteger ( double x , RoundingMode mode ) { } }

implementation: x = roundIntermediate ( x , mode ) ; if ( MIN_LONG_AS_DOUBLE - x < 1.0 & x < MAX_LONG_AS_DOUBLE_PLUS_ONE ) { return BigInteger . valueOf ( ( long ) x ) ; } int exponent = getExponent ( x ) ; long significand = getSignificand ( x ) ; BigInteger result = BigInteger . valueOf ( significand ) . shiftLeft ( exponent - SIGNIFICAND_BITS ) ; return ( x < 0 ) ? result . negate ( ) : result ;


signature:
public class DoubleMath { /** * Returns { @ code true } if { @ code x } is exactly equal to { @ code 2 ^ k } for some finite integer
 * { @ code k } . */
@ GwtIncompatible // com . google . common . math . DoubleUtils
public static boolean isPowerOfTwo ( double x ) { } }

implementation: if ( x > 0.0 && isFinite ( x ) ) { long significand = getSignificand ( x ) ; return ( significand & ( significand - 1 ) ) == 0 ; } return false ;


signature:
public class DoubleMath { /** * Returns { @ code true } if { @ code a } and { @ code b } are within { @ code tolerance } of each other .
 * < p > Technically speaking , this is equivalent to { @ code Math . abs ( a - b ) < = tolerance | |
 * Double . valueOf ( a ) . equals ( Double . valueOf ( b ) ) } .
 * < p > Notable special cases include :
 * < ul >
 * < li > All NaNs are fuzzily equal .
 * < li > If { @ code a = = b } , then { @ code a } and { @ code b } are always fuzzily equal .
 * < li > Positive and negative zero are always fuzzily equal .
 * < li > If { @ code tolerance } is zero , and neither { @ code a } nor { @ code b } is NaN , then { @ code a }
 * and { @ code b } are fuzzily equal if and only if { @ code a = = b } .
 * < li > With { @ link Double # POSITIVE _ INFINITY } tolerance , all non - NaN values are fuzzily equal .
 * < li > With finite tolerance , { @ code Double . POSITIVE _ INFINITY } and { @ code
 * Double . NEGATIVE _ INFINITY } are fuzzily equal only to themselves .
 * < / ul >
 * < p > This is reflexive and symmetric , but < em > not < / em > transitive , so it is < em > not < / em > an
 * equivalence relation and < em > not < / em > suitable for use in { @ link Object # equals }
 * implementations .
 * @ throws IllegalArgumentException if { @ code tolerance } is { @ code < 0 } or NaN
 * @ since 13.0 */
public static boolean fuzzyEquals ( double a , double b , double tolerance ) { } }

implementation:
MathPreconditions . checkNonNegative ( "tolerance" , tolerance ) ; return Math . copySign ( a - b , 1.0 ) <= tolerance // copySign ( x , 1.0 ) is a branch - free version of abs ( x ) , but with different NaN semantics
|| ( a == b ) // needed to ensure that infinities equal themselves
|| ( Double . isNaN ( a ) && Double . isNaN ( b ) ) ;


signature:
public class DoubleMath { /** * Compares { @ code a } and { @ code b } " fuzzily , " with a tolerance for nearly - equal values .
 * < p > This method is equivalent to { @ code fuzzyEquals ( a , b , tolerance ) ? 0 : Double . compare ( a ,
 * b ) } . In particular , like { @ link Double # compare ( double , double ) } , it treats all NaN values as
 * equal and greater than all other values ( including { @ link Double # POSITIVE _ INFINITY } ) .
 * < p > This is < em > not < / em > a total ordering and is < em > not < / em > suitable for use in { @ link
 * Comparable # compareTo } implementations . In particular , it is not transitive .
 * @ throws IllegalArgumentException if { @ code tolerance } is { @ code < 0 } or NaN
 * @ since 13.0 */
public static int fuzzyCompare ( double a , double b , double tolerance ) { } }

implementation: if ( fuzzyEquals ( a , b , tolerance ) ) { return 0 ; } else if ( a < b ) { return - 1 ; } else if ( a > b ) { return 1 ; } else { return Booleans . compare ( Double . isNaN ( a ) , Double . isNaN ( b ) ) ; }


signature:
public class DoubleMath { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Arithmetic _ mean " > arithmetic mean < / a > of
 * { @ code values } .
 * < p > If these values are a sample drawn from a population , this is also an unbiased estimator of
 * the arithmetic mean of the population .
 * @ param values a nonempty series of values
 * @ throws IllegalArgumentException if { @ code values } is empty or contains any non - finite value
 * @ deprecated Use { @ link Stats # meanOf } instead , noting the less strict handling of non - finite
 * values . */
@ Deprecated // com . google . common . math . DoubleUtils
@ GwtIncompatible public static double mean ( double ... values ) { } }

implementation:
checkArgument ( values . length > 0 , "Cannot take mean of 0 values" ) ; long count = 1 ; double mean = checkFinite ( values [ 0 ] ) ; for ( int index = 1 ; index < values . length ; ++ index ) { checkFinite ( values [ index ] ) ; count ++ ; // Art of Computer Programming vol . 2 , Knuth , 4.2.2 , ( 15)
mean += ( values [ index ] - mean ) / count ; } return mean ;


signature:
public class DoubleMath { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Arithmetic _ mean " > arithmetic mean < / a > of
 * { @ code values } .
 * < p > If these values are a sample drawn from a population , this is also an unbiased estimator of
 * the arithmetic mean of the population .
 * @ param values a nonempty series of values
 * @ throws IllegalArgumentException if { @ code values } is empty
 * @ deprecated Use { @ link Stats # meanOf } instead , noting the less strict handling of non - finite
 * values . */
@ Deprecated public static double mean ( int ... values ) { } }

implementation:
checkArgument ( values . length > 0 , "Cannot take mean of 0 values" ) ; // The upper bound on the the length of an array and the bounds on the int values mean that , in
// this case only , we can compute the sum as a long without risking overflow or loss of
// precision . So we do that , as it ' s slightly quicker than the Knuth algorithm .
long sum = 0 ; for ( int index = 0 ; index < values . length ; ++ index ) { sum += values [ index ] ; } return ( double ) sum / values . length ;


signature:
public class DoubleMath { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Arithmetic _ mean " > arithmetic mean < / a > of
 * { @ code values } .
 * < p > If these values are a sample drawn from a population , this is also an unbiased estimator of
 * the arithmetic mean of the population .
 * @ param values a nonempty series of values , which will be converted to { @ code double } values
 * ( this may cause loss of precision for longs of magnitude over 2 ^ 53 ( slightly over 9e15 ) )
 * @ throws IllegalArgumentException if { @ code values } is empty
 * @ deprecated Use { @ link Stats # meanOf } instead , noting the less strict handling of non - finite
 * values . */
@ Deprecated public static double mean ( long ... values ) { } }

implementation:
checkArgument ( values . length > 0 , "Cannot take mean of 0 values" ) ; long count = 1 ; double mean = values [ 0 ] ; for ( int index = 1 ; index < values . length ; ++ index ) { count ++ ; // Art of Computer Programming vol . 2 , Knuth , 4.2.2 , ( 15)
mean += ( values [ index ] - mean ) / count ; } return mean ;


signature:
public class LinkedListMultimap { /** * Removes the specified node from the linked list . This method is only intended to be used from
 * the { @ code Iterator } classes . See also { @ link LinkedListMultimap # removeAllNodes ( Object ) } . */
private void removeNode ( Node < K , V > node ) { } }

implementation:
if ( node . previous != null ) { node . previous . next = node . next ; } else { // node was head
head = node . next ; } if ( node . next != null ) { node . next . previous = node . previous ; } else { // node was tail
tail = node . previous ; } if ( node . previousSibling == null && node . nextSibling == null ) { KeyList < K , V > keyList = keyToKeyList . remove ( node . key ) ; keyList . count = 0 ; modCount ++ ; } else { KeyList < K , V > keyList = keyToKeyList . get ( node . key ) ; keyList . count -- ; if ( node . previousSibling == null ) { keyList . head = node . nextSibling ; } else { node . previousSibling . nextSibling = node . nextSibling ; } if ( node . nextSibling == null ) { keyList . tail = node . previousSibling ; } else { node . nextSibling . previousSibling = node . previousSibling ; } } size -- ;


signature:
public class LinkedListMultimap { /** * { @ inheritDoc }
 * < p > If any entries for the specified { @ code key } already exist in the multimap , their values are
 * changed in - place without affecting the iteration order .
 * < p > The returned list is immutable and implements { @ link java . util . RandomAccess } . */
@ CanIgnoreReturnValue @ Override public List < V > replaceValues ( @ Nullable K key , Iterable < ? extends V > values ) { } }

implementation:
List < V > oldValues = getCopy ( key ) ; ListIterator < V > keyValues = new ValueForKeyIterator ( key ) ; Iterator < ? extends V > newValues = values . iterator ( ) ; // Replace existing values , if any .
while ( keyValues . hasNext ( ) && newValues . hasNext ( ) ) { keyValues . next ( ) ; keyValues . set ( newValues . next ( ) ) ; } // Remove remaining old values , if any .
while ( keyValues . hasNext ( ) ) { keyValues . next ( ) ; keyValues . remove ( ) ; } // Add remaining new values , if any .
while ( newValues . hasNext ( ) ) { keyValues . add ( newValues . next ( ) ) ; } return oldValues ;


signature:
public class LinkedListMultimap { /** * { @ inheritDoc }
 * < p > If the multimap is modified while an iteration over the list is in progress ( except through
 * the iterator ' s own { @ code add } , { @ code set } or { @ code remove } operations ) the results of the
 * iteration are undefined .
 * < p > The returned list is not serializable and does not have random access . */
@ Override public List < V > get ( final @ Nullable K key ) { } }

implementation: return new AbstractSequentialList < V > ( ) { @ Override public int size ( ) { KeyList < K , V > keyList = keyToKeyList . get ( key ) ; return ( keyList == null ) ? 0 : keyList . count ; } @ Override public ListIterator < V > listIterator ( int index ) { return new ValueForKeyIterator ( key , index ) ; } } ;


signature:
public class LinkedListMultimap { /** * { @ inheritDoc }
 * < p > The iterator generated by the returned collection traverses the entries in the order they
 * were added to the multimap . Because the entries may have duplicates and follow the insertion
 * ordering , this method returns a { @ link List } , instead of the { @ link Collection } specified in
 * the { @ link ListMultimap } interface .
 * < p > An entry ' s { @ link Entry # getKey } method always returns the same key , regardless of what
 * happens subsequently . As long as the corresponding key - value mapping is not removed from the
 * multimap , { @ link Entry # getValue } returns the value from the multimap , which may change over
 * time , and { @ link Entry # setValue } modifies that value . Removing the mapping from the multimap
 * does not alter the value returned by { @ code getValue ( ) } , though a subsequent { @ code setValue ( ) }
 * call won ' t update the multimap but will lead to a revised value being returned by { @ code
 * getValue ( ) } . */
@ Override public List < Entry < K , V > > entries ( ) { } }

implementation: return ( List < Entry < K , V > > ) super . entries ( ) ;


signature:
public class HashingInputStream { /** * Reads the next byte of data from the underlying input stream and updates the hasher with the
 * byte read . */
@ Override @ CanIgnoreReturnValue public int read ( ) throws IOException { } }

implementation: int b = in . read ( ) ; if ( b != - 1 ) { hasher . putByte ( ( byte ) b ) ; } return b ;


signature:
public class HashingInputStream { /** * Reads the specified bytes of data from the underlying input stream and updates the hasher with
 * the bytes read . */
@ Override @ CanIgnoreReturnValue public int read ( byte [ ] bytes , int off , int len ) throws IOException { } }

implementation: int numOfBytesRead = in . read ( bytes , off , len ) ; if ( numOfBytesRead != - 1 ) { hasher . putBytes ( bytes , off , numOfBytesRead ) ; } return numOfBytesRead ;


signature:
public class Serialization { /** * Stores the contents of a map in an output stream , as part of serialization . It does not support
 * concurrent maps whose content may change while the method is running .
 * < p > The serialized output consists of the number of entries , first key , first value , second key ,
 * second value , and so on . */
static < K , V > void writeMap ( Map < K , V > map , ObjectOutputStream stream ) throws IOException { } }

implementation: stream . writeInt ( map . size ( ) ) ; for ( Map . Entry < K , V > entry : map . entrySet ( ) ) { stream . writeObject ( entry . getKey ( ) ) ; stream . writeObject ( entry . getValue ( ) ) ; }


signature:
public class Serialization { /** * Populates a map by reading an input stream , as part of deserialization . See { @ link # writeMap }
 * for the data format . */
static < K , V > void populateMap ( Map < K , V > map , ObjectInputStream stream ) throws IOException , ClassNotFoundException { } }

implementation: int size = stream . readInt ( ) ; populateMap ( map , stream , size ) ;


signature:
public class Serialization { /** * Populates a map by reading an input stream , as part of deserialization . See { @ link # writeMap }
 * for the data format . The size is determined by a prior call to { @ link # readCount } . */
static < K , V > void populateMap ( Map < K , V > map , ObjectInputStream stream , int size ) throws IOException , ClassNotFoundException { } }

implementation:
for ( int i = 0 ; i < size ; i ++ ) { @ SuppressWarnings ( "unchecked" ) // reading data stored by writeMap
K key = ( K ) stream . readObject ( ) ; @ SuppressWarnings ( "unchecked" ) // reading data stored by writeMap
V value = ( V ) stream . readObject ( ) ; map . put ( key , value ) ; }


signature:
public class Serialization { /** * Stores the contents of a multiset in an output stream , as part of serialization . It does not
 * support concurrent multisets whose content may change while the method is running .
 * < p > The serialized output consists of the number of distinct elements , the first element , its
 * count , the second element , its count , and so on . */
static < E > void writeMultiset ( Multiset < E > multiset , ObjectOutputStream stream ) throws IOException { } }

implementation: int entryCount = multiset . entrySet ( ) . size ( ) ; stream . writeInt ( entryCount ) ; for ( Multiset . Entry < E > entry : multiset . entrySet ( ) ) { stream . writeObject ( entry . getElement ( ) ) ; stream . writeInt ( entry . getCount ( ) ) ; }


signature:
public class Serialization { /** * Populates a multiset by reading an input stream , as part of deserialization . See { @ link
 * # writeMultiset } for the data format . */
static < E > void populateMultiset ( Multiset < E > multiset , ObjectInputStream stream ) throws IOException , ClassNotFoundException { } }

implementation: int distinctElements = stream . readInt ( ) ; populateMultiset ( multiset , stream , distinctElements ) ;


signature:
public class Serialization { /** * Populates a multiset by reading an input stream , as part of deserialization . See { @ link
 * # writeMultiset } for the data format . The number of distinct elements is determined by a prior
 * call to { @ link # readCount } . */
static < E > void populateMultiset ( Multiset < E > multiset , ObjectInputStream stream , int distinctElements ) throws IOException , ClassNotFoundException { } }

implementation:
for ( int i = 0 ; i < distinctElements ; i ++ ) { @ SuppressWarnings ( "unchecked" ) // reading data stored by writeMultiset
E element = ( E ) stream . readObject ( ) ; int count = stream . readInt ( ) ; multiset . add ( element , count ) ; }


signature:
public class Serialization { /** * Stores the contents of a multimap in an output stream , as part of serialization . It does not
 * support concurrent multimaps whose content may change while the method is running . The { @ link
 * Multimap # asMap } view determines the ordering in which data is written to the stream .
 * < p > The serialized output consists of the number of distinct keys , and then for each distinct
 * key : the key , the number of values for that key , and the key ' s values . */
static < K , V > void writeMultimap ( Multimap < K , V > multimap , ObjectOutputStream stream ) throws IOException { } }

implementation: stream . writeInt ( multimap . asMap ( ) . size ( ) ) ; for ( Map . Entry < K , Collection < V > > entry : multimap . asMap ( ) . entrySet ( ) ) { stream . writeObject ( entry . getKey ( ) ) ; stream . writeInt ( entry . getValue ( ) . size ( ) ) ; for ( V value : entry . getValue ( ) ) { stream . writeObject ( value ) ; } }


signature:
public class Serialization { /** * Populates a multimap by reading an input stream , as part of deserialization . See { @ link
 * # writeMultimap } for the data format . */
static < K , V > void populateMultimap ( Multimap < K , V > multimap , ObjectInputStream stream ) throws IOException , ClassNotFoundException { } }

implementation: int distinctKeys = stream . readInt ( ) ; populateMultimap ( multimap , stream , distinctKeys ) ;


signature:
public class Serialization { /** * Populates a multimap by reading an input stream , as part of deserialization . See { @ link
 * # writeMultimap } for the data format . The number of distinct keys is determined by a prior call
 * to { @ link # readCount } . */
static < K , V > void populateMultimap ( Multimap < K , V > multimap , ObjectInputStream stream , int distinctKeys ) throws IOException , ClassNotFoundException { } }

implementation:
for ( int i = 0 ; i < distinctKeys ; i ++ ) { @ SuppressWarnings ( "unchecked" ) // reading data stored by writeMultimap
K key = ( K ) stream . readObject ( ) ; Collection < V > values = multimap . get ( key ) ; int valueCount = stream . readInt ( ) ; for ( int j = 0 ; j < valueCount ; j ++ ) { @ SuppressWarnings ( "unchecked" ) // reading data stored by writeMultimap
V value = ( V ) stream . readObject ( ) ; values . add ( value ) ; } }


signature:
public class Serialization { /** * Secret sauce for setting final fields ; don ' t make it public . */
static < T > FieldSetter < T > getFieldSetter ( final Class < T > clazz , String fieldName ) { } }

implementation:
try { Field field = clazz . getDeclaredField ( fieldName ) ; return new FieldSetter < T > ( field ) ; } catch ( NoSuchFieldException e ) { throw new AssertionError ( e ) ; // programmer error
}


signature:
public class MapRetrievalCache { /** * Internal methods ( ' protected ' is still package - visible , but treat as only subclass - visible ) */
@ Override protected V getIfCached ( @ Nullable Object key ) { } }

implementation:
V value = super . getIfCached ( key ) ; if ( value != null ) { return value ; } // Store a local reference to the cache entry . If the backing map is immutable , this ,
// in combination with immutable cache entries , will ensure a thread - safe cache .
CacheEntry < K , V > entry ; // Check cache . We use = = on purpose because it ' s cheaper and a cache miss is ok .
entry = cacheEntry1 ; if ( entry != null && entry . key == key ) { return entry . value ; } entry = cacheEntry2 ; if ( entry != null && entry . key == key ) { // Promote second cache entry to first so the access pattern
// [ K1 , K2 , K1 , K3 , K1 , K4 . . . ] still hits the cache half the time .
addToCache ( entry ) ; return entry . value ; } return null ;


signature:
public class AbstractStreamingHasher { /** * This is invoked for the last bytes of the input , which are not enough to fill a whole chunk .
 * The passed { @ code ByteBuffer } is guaranteed to be non - empty .
 * < p > This implementation simply pads with zeros and delegates to { @ link # process ( ByteBuffer ) } . */
protected void processRemaining ( ByteBuffer bb ) { } }

implementation:
bb . position ( bb . limit ( ) ) ; // move at the end
bb . limit ( chunkSize + 7 ) ; // get ready to pad with longs
while ( bb . position ( ) < chunkSize ) { bb . putLong ( 0 ) ; } bb . limit ( chunkSize ) ; bb . flip ( ) ; process ( bb ) ;


signature:
public class UnsignedLong { /** * Returns the result of dividing this by { @ code val } .
 * @ since 14.0 */
public UnsignedLong dividedBy ( UnsignedLong val ) { } }

implementation: return fromLongBits ( UnsignedLongs . divide ( value , checkNotNull ( val ) . value ) ) ;


signature:
public class UnsignedLong { /** * Returns this modulo { @ code val } .
 * @ since 14.0 */
public UnsignedLong mod ( UnsignedLong val ) { } }

implementation: return fromLongBits ( UnsignedLongs . remainder ( value , checkNotNull ( val ) . value ) ) ;


signature:
public class UnsignedLong { /** * Returns the value of this { @ code UnsignedLong } as a { @ code float } , analogous to a widening
 * primitive conversion from { @ code long } to { @ code float } , and correctly rounded . */
@ Override public float floatValue ( ) { } }

implementation: @ SuppressWarnings ( "cast" ) float fValue = ( float ) ( value & UNSIGNED_MASK ) ; if ( value < 0 ) { fValue += 0x1.0p63f ; } return fValue ;


signature:
public class UnsignedLong { /** * Returns the value of this { @ code UnsignedLong } as a { @ code double } , analogous to a widening
 * primitive conversion from { @ code long } to { @ code double } , and correctly rounded . */
@ Override public double doubleValue ( ) { } }

implementation: @ SuppressWarnings ( "cast" ) double dValue = ( double ) ( value & UNSIGNED_MASK ) ; if ( value < 0 ) { dValue += 0x1.0p63 ; } return dValue ;


signature:
public class UnsignedLong { /** * Returns the value of this { @ code UnsignedLong } as a { @ link BigInteger } . */
public BigInteger bigIntegerValue ( ) { } }

implementation: BigInteger bigInt = BigInteger . valueOf ( value & UNSIGNED_MASK ) ; if ( value < 0 ) { bigInt = bigInt . setBit ( Long . SIZE - 1 ) ; } return bigInt ;


signature:
public class Throwables { /** * Throws { @ code throwable } if it is an instance of { @ code declaredType } . Example usage :
 * < pre >
 * for ( Foo foo : foos ) {
 * try {
 * foo . bar ( ) ;
 * } catch ( BarException | RuntimeException | Error t ) {
 * failure = t ;
 * if ( failure ! = null ) {
 * throwIfInstanceOf ( failure , BarException . class ) ;
 * throwIfUnchecked ( failure ) ;
 * throw new AssertionError ( failure ) ;
 * < / pre >
 * @ since 20.0 */
@ GwtIncompatible // Class . cast , Class . isInstance
public static < X extends Throwable > void throwIfInstanceOf ( Throwable throwable , Class < X > declaredType ) throws X { } }

implementation: checkNotNull ( throwable ) ; if ( declaredType . isInstance ( throwable ) ) { throw declaredType . cast ( throwable ) ; }


signature:
public class Throwables { /** * Propagates { @ code throwable } exactly as - is , if and only if it is an instance of { @ code
 * declaredType } . Example usage :
 * < pre >
 * try {
 * someMethodThatCouldThrowAnything ( ) ;
 * } catch ( IKnowWhatToDoWithThisException e ) {
 * handle ( e ) ;
 * } catch ( Throwable t ) {
 * Throwables . propagateIfInstanceOf ( t , IOException . class ) ;
 * Throwables . propagateIfInstanceOf ( t , SQLException . class ) ;
 * throw Throwables . propagate ( t ) ;
 * < / pre >
 * @ deprecated Use { @ link # throwIfInstanceOf } , which has the same behavior but rejects { @ code
 * null } . */
@ Deprecated @ GwtIncompatible // throwIfInstanceOf
public static < X extends Throwable > void propagateIfInstanceOf ( @ Nullable Throwable throwable , Class < X > declaredType ) throws X { } }

implementation: if ( throwable != null ) { throwIfInstanceOf ( throwable , declaredType ) ; }


signature:
public class Throwables { /** * Throws { @ code throwable } if it is a { @ link RuntimeException } or { @ link Error } . Example usage :
 * < pre >
 * for ( Foo foo : foos ) {
 * try {
 * foo . bar ( ) ;
 * } catch ( RuntimeException | Error t ) {
 * failure = t ;
 * if ( failure ! = null ) {
 * throwIfUnchecked ( failure ) ;
 * throw new AssertionError ( failure ) ;
 * < / pre >
 * @ since 20.0 */
public static void throwIfUnchecked ( Throwable throwable ) { } }

implementation: checkNotNull ( throwable ) ; if ( throwable instanceof RuntimeException ) { throw ( RuntimeException ) throwable ; } if ( throwable instanceof Error ) { throw ( Error ) throwable ; }


signature:
public class Throwables { /** * Propagates { @ code throwable } exactly as - is , if and only if it is an instance of { @ link
 * RuntimeException } or { @ link Error } . Example usage :
 * < pre >
 * try {
 * someMethodThatCouldThrowAnything ( ) ;
 * } catch ( IKnowWhatToDoWithThisException e ) {
 * handle ( e ) ;
 * } catch ( Throwable t ) {
 * Throwables . propagateIfPossible ( t ) ;
 * throw new RuntimeException ( " unexpected " , t ) ;
 * < / pre >
 * @ deprecated Use { @ link # throwIfUnchecked } , which has the same behavior but rejects { @ code
 * null } . */
@ Deprecated @ GwtIncompatible public static void propagateIfPossible ( @ Nullable Throwable throwable ) { } }

implementation: if ( throwable != null ) { throwIfUnchecked ( throwable ) ; }


signature:
public class Throwables { /** * Propagates { @ code throwable } exactly as - is , if and only if it is an instance of { @ link
 * RuntimeException } , { @ link Error } , { @ code declaredType1 } , or { @ code declaredType2 } . In the
 * unlikely case that you have three or more declared checked exception types , you can handle them
 * all by invoking these methods repeatedly . See usage example in { @ link
 * # propagateIfPossible ( Throwable , Class ) } .
 * @ param throwable the Throwable to possibly propagate
 * @ param declaredType1 any checked exception type declared by the calling method
 * @ param declaredType2 any other checked exception type declared by the calling method */
@ GwtIncompatible // propagateIfInstanceOf
public static < X1 extends Throwable , X2 extends Throwable > void propagateIfPossible ( @ Nullable Throwable throwable , Class < X1 > declaredType1 , Class < X2 > declaredType2 ) throws X1 , X2 { } }

implementation: checkNotNull ( declaredType2 ) ; propagateIfInstanceOf ( throwable , declaredType1 ) ; propagateIfPossible ( throwable , declaredType2 ) ;


signature:
public class Throwables { /** * Propagates { @ code throwable } as - is if it is an instance of { @ link RuntimeException } or { @ link
 * Error } , or else as a last resort , wraps it in a { @ code RuntimeException } and then propagates .
 * < p > This method always throws an exception . The { @ code RuntimeException } return type allows
 * client code to signal to the compiler that statements after the call are unreachable . Example
 * usage :
 * < pre >
 * T doSomething ( ) {
 * try {
 * return someMethodThatCouldThrowAnything ( ) ;
 * } catch ( IKnowWhatToDoWithThisException e ) {
 * return handle ( e ) ;
 * } catch ( Throwable t ) {
 * throw Throwables . propagate ( t ) ;
 * < / pre >
 * @ param throwable the Throwable to propagate
 * @ return nothing will ever be returned ; this return type is only for your convenience , as
 * illustrated in the example above
 * @ deprecated Use { @ code throw e } or { @ code throw new RuntimeException ( e ) } directly , or use a
 * combination of { @ link # throwIfUnchecked } and { @ code throw new RuntimeException ( e ) } . For
 * background on the deprecation , read < a href = " https : / / goo . gl / Ivn2kc " > Why we deprecated
 * { @ code Throwables . propagate } < / a > . */
@ CanIgnoreReturnValue @ GwtIncompatible @ Deprecated public static RuntimeException propagate ( Throwable throwable ) { } }

implementation: throwIfUnchecked ( throwable ) ; throw new RuntimeException ( throwable ) ;


signature:
public class Throwables { /** * Returns the innermost cause of { @ code throwable } . The first throwable in a chain provides
 * context from when the error or exception was initially detected . Example usage :
 * < pre >
 * assertEquals ( " Unable to assign a customer id " , Throwables . getRootCause ( e ) . getMessage ( ) ) ;
 * < / pre >
 * @ throws IllegalArgumentException if there is a loop in the causal chain */
public static Throwable getRootCause ( Throwable throwable ) { } }

implementation:
// Keep a second pointer that slowly walks the causal chain . If the fast pointer ever catches
// the slower pointer , then there ' s a loop .
Throwable slowPointer = throwable ; boolean advanceSlowPointer = false ; Throwable cause ; while ( ( cause = throwable . getCause ( ) ) != null ) { throwable = cause ; if ( throwable == slowPointer ) { throw new IllegalArgumentException ( "Loop in causal chain detected." , throwable ) ; } if ( advanceSlowPointer ) { slowPointer = slowPointer . getCause ( ) ; } advanceSlowPointer = ! advanceSlowPointer ; // only advance every other iteration
} return throwable ;


signature:
public class Throwables { /** * Gets a { @ code Throwable } cause chain as a list . The first entry in the list will be { @ code
 * throwable } followed by its cause hierarchy . Note that this is a snapshot of the cause chain and
 * will not reflect any subsequent changes to the cause chain .
 * < p > Here ' s an example of how it can be used to find specific types of exceptions in the cause
 * chain :
 * < pre >
 * Iterables . filter ( Throwables . getCausalChain ( e ) , IOException . class ) ) ;
 * < / pre >
 * @ param throwable the non - null { @ code Throwable } to extract causes from
 * @ return an unmodifiable list containing the cause chain starting with { @ code throwable }
 * @ throws IllegalArgumentException if there is a loop in the causal chain */
@ Beta // TODO ( kevinb ) : decide best return type
public static List < Throwable > getCausalChain ( Throwable throwable ) { } }

implementation:
checkNotNull ( throwable ) ; List < Throwable > causes = new ArrayList < > ( 4 ) ; causes . add ( throwable ) ; // Keep a second pointer that slowly walks the causal chain . If the fast pointer ever catches
// the slower pointer , then there ' s a loop .
Throwable slowPointer = throwable ; boolean advanceSlowPointer = false ; Throwable cause ; while ( ( cause = throwable . getCause ( ) ) != null ) { throwable = cause ; causes . add ( throwable ) ; if ( throwable == slowPointer ) { throw new IllegalArgumentException ( "Loop in causal chain detected." , throwable ) ; } if ( advanceSlowPointer ) { slowPointer = slowPointer . getCause ( ) ; } advanceSlowPointer = ! advanceSlowPointer ; // only advance every other iteration
} return Collections . unmodifiableList ( causes ) ;


signature:
public class Throwables { /** * Returns { @ code throwable } ' s cause , cast to { @ code expectedCauseType } .
 * < p > Prefer this method instead of manually casting an exception ' s cause . For example , { @ code
 * ( IOException ) e . getCause ( ) } throws a { @ link ClassCastException } that discards the original
 * exception { @ code e } if the cause is not an { @ link IOException } , but { @ code
 * Throwables . getCauseAs ( e , IOException . class ) } keeps { @ code e } as the { @ link
 * ClassCastException } ' s cause .
 * @ throws ClassCastException if the cause cannot be cast to the expected type . The { @ code
 * ClassCastException } ' s cause is { @ code throwable } .
 * @ since 22.0 */
@ Beta @ GwtIncompatible // Class . cast ( Object )
public static < X extends Throwable > X getCauseAs ( Throwable throwable , Class < X > expectedCauseType ) { } }

implementation: try { return expectedCauseType . cast ( throwable . getCause ( ) ) ; } catch ( ClassCastException e ) { e . initCause ( throwable ) ; throw e ; }


signature:
public class Throwables { /** * TODO ( cpovirk ) : Say something about the possibility that List access could fail at runtime ? */
@ Beta @ GwtIncompatible // lazyStackTraceIsLazy , jlaStackTrace
// TODO ( cpovirk ) : Consider making this available under GWT ( slow implementation only ) .
public static List < StackTraceElement > lazyStackTrace ( Throwable throwable ) { } }

implementation: return lazyStackTraceIsLazy ( ) ? jlaStackTrace ( throwable ) : unmodifiableList ( asList ( throwable . getStackTrace ( ) ) ) ;


signature:
public class Stats { /** * Returns statistics over a dataset containing the given values .
 * @ param values a series of values , which will be converted to { @ code double } values ( this may
 * cause loss of precision ) */
public static Stats of ( Iterable < ? extends Number > values ) { } }

implementation: StatsAccumulator accumulator = new StatsAccumulator ( ) ; accumulator . addAll ( values ) ; return accumulator . snapshot ( ) ;


signature:
public class Stats { /** * Returns statistics over a dataset containing the given values .
 * @ param values a series of values */
public static Stats of ( int ... values ) { } }

implementation: StatsAccumulator acummulator = new StatsAccumulator ( ) ; acummulator . addAll ( values ) ; return acummulator . snapshot ( ) ;


signature:
public class Stats { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Variance # Population _ variance " > population
 * variance < / a > of the values . The count must be non - zero .
 * < p > This is guaranteed to return zero if the dataset contains only exactly one finite value . It
 * is not guaranteed to return zero when the dataset consists of the same value multiple times ,
 * due to numerical errors . However , it is guaranteed never to return a negative result .
 * < h3 > Non - finite values < / h3 >
 * < p > If the dataset contains any non - finite values ( { @ link Double # POSITIVE _ INFINITY } , { @ link
 * Double # NEGATIVE _ INFINITY } , or { @ link Double # NaN } ) then the result is { @ link Double # NaN } .
 * @ throws IllegalStateException if the dataset is empty */
public double populationVariance ( ) { } }

implementation: checkState ( count > 0 ) ; if ( isNaN ( sumOfSquaresOfDeltas ) ) { return NaN ; } if ( count == 1 ) { return 0.0 ; } return ensureNonNegative ( sumOfSquaresOfDeltas ) / count ( ) ;


signature:
public class Stats { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Arithmetic _ mean " > arithmetic mean < / a > of the
 * values . The count must be non - zero .
 * < p > The definition of the mean is the same as { @ link Stats # mean } .
 * @ param values a series of values , which will be converted to { @ code double } values ( this may
 * cause loss of precision )
 * @ throws IllegalArgumentException if the dataset is empty */
public static double meanOf ( Iterator < ? extends Number > values ) { } }

implementation:
checkArgument ( values . hasNext ( ) ) ; long count = 1 ; double mean = values . next ( ) . doubleValue ( ) ; while ( values . hasNext ( ) ) { double value = values . next ( ) . doubleValue ( ) ; count ++ ; if ( isFinite ( value ) && isFinite ( mean ) ) { // Art of Computer Programming vol . 2 , Knuth , 4.2.2 , ( 15)
mean += ( value - mean ) / count ; } else { mean = calculateNewMeanNonFinite ( mean , value ) ; } } return mean ;


signature:
public class Stats { /** * Returns the < a href = " http : / / en . wikipedia . org / wiki / Arithmetic _ mean " > arithmetic mean < / a > of the
 * values . The count must be non - zero .
 * < p > The definition of the mean is the same as { @ link Stats # mean } .
 * @ param values a series of values , which will be converted to { @ code double } values ( this may
 * cause loss of precision for longs of magnitude over 2 ^ 53 ( slightly over 9e15 ) )
 * @ throws IllegalArgumentException if the dataset is empty */
public static double meanOf ( long ... values ) { } }

implementation:
checkArgument ( values . length > 0 ) ; double mean = values [ 0 ] ; for ( int index = 1 ; index < values . length ; index ++ ) { double value = values [ index ] ; if ( isFinite ( value ) && isFinite ( mean ) ) { // Art of Computer Programming vol . 2 , Knuth , 4.2.2 , ( 15)
mean += ( value - mean ) / ( index + 1 ) ; } else { mean = calculateNewMeanNonFinite ( mean , value ) ; } } return mean ;


signature:
public class Stats { /** * Gets a byte array representation of this instance .
 * < p > < b > Note : < / b > No guarantees are made regarding stability of the representation between
 * versions . */
public byte [ ] toByteArray ( ) { } }

implementation: ByteBuffer buff = ByteBuffer . allocate ( BYTES ) . order ( ByteOrder . LITTLE_ENDIAN ) ; writeTo ( buff ) ; return buff . array ( ) ;


signature:
public class Stats { /** * Writes to the given { @ link ByteBuffer } a byte representation of this instance .
 * < p > < b > Note : < / b > No guarantees are made regarding stability of the representation between
 * versions .
 * @ param buffer A { @ link ByteBuffer } with at least BYTES { @ link ByteBuffer # remaining } , ordered as
 * { @ link ByteOrder # LITTLE _ ENDIAN } , to which a BYTES - long byte representation of this instance
 * is written . In the process increases the position of { @ link ByteBuffer } by BYTES . */
void writeTo ( ByteBuffer buffer ) { } }

implementation: checkNotNull ( buffer ) ; checkArgument ( buffer . remaining ( ) >= BYTES , "Expected at least Stats.BYTES = %s remaining , got %s" , BYTES , buffer . remaining ( ) ) ; buffer . putLong ( count ) . putDouble ( mean ) . putDouble ( sumOfSquaresOfDeltas ) . putDouble ( min ) . putDouble ( max ) ;


signature:
public class Stats { /** * Creates a Stats instance from the given byte representation which was obtained by { @ link
 * # toByteArray } .
 * < p > < b > Note : < / b > No guarantees are made regarding stability of the representation between
 * versions . */
public static Stats fromByteArray ( byte [ ] byteArray ) { } }

implementation: checkNotNull ( byteArray ) ; checkArgument ( byteArray . length == BYTES , "Expected Stats.BYTES = %s remaining , got %s" , BYTES , byteArray . length ) ; return readFrom ( ByteBuffer . wrap ( byteArray ) . order ( ByteOrder . LITTLE_ENDIAN ) ) ;


signature:
public class Stats { /** * Creates a Stats instance from the byte representation read from the given { @ link ByteBuffer } .
 * < p > < b > Note : < / b > No guarantees are made regarding stability of the representation between
 * versions .
 * @ param buffer A { @ link ByteBuffer } with at least BYTES { @ link ByteBuffer # remaining } , ordered as
 * { @ link ByteOrder # LITTLE _ ENDIAN } , from which a BYTES - long byte representation of this
 * instance is read . In the process increases the position of { @ link ByteBuffer } by BYTES . */
static Stats readFrom ( ByteBuffer buffer ) { } }

implementation: checkNotNull ( buffer ) ; checkArgument ( buffer . remaining ( ) >= BYTES , "Expected at least Stats.BYTES = %s remaining , got %s" , BYTES , buffer . remaining ( ) ) ; return new Stats ( buffer . getLong ( ) , buffer . getDouble ( ) , buffer . getDouble ( ) , buffer . getDouble ( ) , buffer . getDouble ( ) ) ;


signature:
public class AtomicDoubleArray { /** * Sets the element at position { @ code i } to the given value .
 * @ param i the index
 * @ param newValue the new value */
public final void set ( int i , double newValue ) { } }

implementation: long next = doubleToRawLongBits ( newValue ) ; longs . set ( i , next ) ;


signature:
public class AtomicDoubleArray { /** * Eventually sets the element at position { @ code i } to the given value .
 * @ param i the index
 * @ param newValue the new value */
public final void lazySet ( int i , double newValue ) { } }

implementation: long next = doubleToRawLongBits ( newValue ) ; longs . lazySet ( i , next ) ;


signature:
public class AtomicDoubleArray { /** * Atomically sets the element at position { @ code i } to the given value and returns the old value .
 * @ param i the index
 * @ param newValue the new value
 * @ return the previous value */
public final double getAndSet ( int i , double newValue ) { } }

implementation: long next = doubleToRawLongBits ( newValue ) ; return longBitsToDouble ( longs . getAndSet ( i , next ) ) ;


signature:
public class AtomicDoubleArray { /** * Atomically sets the element at position { @ code i } to the given updated value if the current
 * value is < a href = " # bitEquals " > bitwise equal < / a > to the expected value .
 * @ param i the index
 * @ param expect the expected value
 * @ param update the new value
 * @ return true if successful . False return indicates that the actual value was not equal to the
 * expected value . */
public final boolean compareAndSet ( int i , double expect , double update ) { } }

implementation: return longs . compareAndSet ( i , doubleToRawLongBits ( expect ) , doubleToRawLongBits ( update ) ) ;


signature:
public class AtomicDoubleArray { /** * Atomically sets the element at position { @ code i } to the given updated value if the current
 * value is < a href = " # bitEquals " > bitwise equal < / a > to the expected value .
 * < p > May < a
 * href = " http : / / download . oracle . com / javase / 7 / docs / api / java / util / concurrent / atomic / package - summary . html # Spurious " >
 * fail spuriously < / a > and does not provide ordering guarantees , so is only rarely an appropriate
 * alternative to { @ code compareAndSet } .
 * @ param i the index
 * @ param expect the expected value
 * @ param update the new value
 * @ return true if successful */
public final boolean weakCompareAndSet ( int i , double expect , double update ) { } }

implementation: return longs . weakCompareAndSet ( i , doubleToRawLongBits ( expect ) , doubleToRawLongBits ( update ) ) ;


signature:
public class AtomicDoubleArray { /** * Atomically adds the given value to the element at index { @ code i } .
 * @ param i the index
 * @ param delta the value to add
 * @ return the previous value */
@ CanIgnoreReturnValue public final double getAndAdd ( int i , double delta ) { } }

implementation: while ( true ) { long current = longs . get ( i ) ; double currentVal = longBitsToDouble ( current ) ; double nextVal = currentVal + delta ; long next = doubleToRawLongBits ( nextVal ) ; if ( longs . compareAndSet ( i , current , next ) ) { return currentVal ; } }


signature:
public class AtomicDoubleArray { /** * Saves the state to a stream ( that is , serializes it ) .
 * @ serialData The length of the array is emitted ( int ) , followed by all of its elements ( each a
 * { @ code double } ) in the proper order . */
private void writeObject ( java . io . ObjectOutputStream s ) throws java . io . IOException { } }

implementation:
s . defaultWriteObject ( ) ; // Write out array length
int length = length ( ) ; s . writeInt ( length ) ; // Write out all elements in the proper order .
for ( int i = 0 ; i < length ; i ++ ) { s . writeDouble ( get ( i ) ) ; }


signature:
public class AtomicDoubleArray { /** * Reconstitutes the instance from a stream ( that is , deserializes it ) . */
private void readObject ( java . io . ObjectInputStream s ) throws java . io . IOException , ClassNotFoundException { } }

implementation: s . defaultReadObject ( ) ; int length = s . readInt ( ) ; ImmutableLongArray . Builder builder = ImmutableLongArray . builder ( ) ; for ( int i = 0 ; i < length ; i ++ ) { builder . add ( doubleToRawLongBits ( s . readDouble ( ) ) ) ; } this . longs = new AtomicLongArray ( builder . build ( ) . toArray ( ) ) ;


signature:
public class EndpointPair { /** * Returns an { @ link EndpointPair } representing the endpoints of a directed edge . */
public static < N > EndpointPair < N > ordered ( N source , N target ) { } }

implementation: return new Ordered < N > ( source , target ) ;


signature:
public class EndpointPair { /** * Returns an { @ link EndpointPair } representing the endpoints of an undirected edge . */
public static < N > EndpointPair < N > unordered ( N nodeU , N nodeV ) { } }

implementation:
// Swap nodes on purpose to prevent callers from relying on the " ordering " of an unordered pair .
return new Unordered < N > ( nodeV , nodeU ) ;


signature:
public class EndpointPair { /** * Returns an { @ link EndpointPair } representing the endpoints of an edge in { @ code graph } . */
static < N > EndpointPair < N > of ( Graph < ? > graph , N nodeU , N nodeV ) { } }

implementation: return graph . isDirected ( ) ? ordered ( nodeU , nodeV ) : unordered ( nodeU , nodeV ) ;


signature:
public class EndpointPair { /** * Returns an { @ link EndpointPair } representing the endpoints of an edge in { @ code network } . */
static < N > EndpointPair < N > of ( Network < ? , ? > network , N nodeU , N nodeV ) { } }

implementation: return network . isDirected ( ) ? ordered ( nodeU , nodeV ) : unordered ( nodeU , nodeV ) ;


signature:
public class EndpointPair { /** * Returns the node that is adjacent to { @ code node } along the origin edge .
 * @ throws IllegalArgumentException if this { @ link EndpointPair } does not contain { @ code node } */
public final N adjacentNode ( Object node ) { } }

implementation: if ( node . equals ( nodeU ) ) { return nodeV ; } else if ( node . equals ( nodeV ) ) { return nodeU ; } else { throw new IllegalArgumentException ( "EndpointPair " + this + " does not contain node " + node ) ; }


signature:
public class Stopwatch { /** * Starts the stopwatch .
 * @ return this { @ code Stopwatch } instance
 * @ throws IllegalStateException if the stopwatch is already running . */
@ CanIgnoreReturnValue public Stopwatch start ( ) { } }

implementation: checkState ( ! isRunning , "This stopwatch is already running." ) ; isRunning = true ; startTick = ticker . read ( ) ; return this ;


signature:
public class ConcurrentHashMultiset { /** * Creates a new { @ code ConcurrentHashMultiset } containing the specified elements , using the
 * default initial capacity , load factor , and concurrency settings .
 * < p > This implementation is highly efficient when { @ code elements } is itself a { @ link Multiset } .
 * @ param elements the elements that the multiset should contain */
public static < E > ConcurrentHashMultiset < E > create ( Iterable < ? extends E > elements ) { } }

implementation: ConcurrentHashMultiset < E > multiset = ConcurrentHashMultiset . create ( ) ; Iterables . addAll ( multiset , elements ) ; return multiset ;


signature:
public class ConcurrentHashMultiset { /** * Creates a new , empty { @ code ConcurrentHashMultiset } using { @ code countMap } as the internal
 * backing map .
 * < p > This instance will assume ownership of { @ code countMap } , and other code should not maintain
 * references to the map or modify it in any way .
 * < p > The returned multiset is serializable if the input map is .
 * @ param countMap backing map for storing the elements in the multiset and their counts . It must
 * be empty .
 * @ throws IllegalArgumentException if { @ code countMap } is not empty
 * @ since 20.0 */
@ Beta public static < E > ConcurrentHashMultiset < E > create ( ConcurrentMap < E , AtomicInteger > countMap ) { } }

implementation: return new ConcurrentHashMultiset < E > ( countMap ) ;


signature:
public class ConcurrentHashMultiset { /** * Returns the number of occurrences of { @ code element } in this multiset .
 * @ param element the element to look for
 * @ return the nonnegative number of occurrences of the element */
@ Override public int count ( @ NullableDecl Object element ) { } }

implementation: AtomicInteger existingCounter = Maps . safeGet ( countMap , element ) ; return ( existingCounter == null ) ? 0 : existingCounter . get ( ) ;


signature:
public class ConcurrentHashMultiset { /** * { @ inheritDoc }
 * < p > If the data in the multiset is modified by any other threads during this method , it is
 * undefined which ( if any ) of these modifications will be reflected in the result . */
@ Override public int size ( ) { } }

implementation: long sum = 0L ; for ( AtomicInteger value : countMap . values ( ) ) { sum += value . get ( ) ; } return Ints . saturatedCast ( sum ) ;


signature:
public class ConcurrentHashMultiset { /** * We ' d love to use ' new ArrayList ( this ) ' or ' list . addAll ( this ) ' , but
 * either of these would recurse back to us again ! */
private List < E > snapshot ( ) { } }

implementation: List < E > list = Lists . newArrayListWithExpectedSize ( size ( ) ) ; for ( Multiset . Entry < E > entry : entrySet ( ) ) { E element = entry . getElement ( ) ; for ( int i = entry . getCount ( ) ; i > 0 ; i -- ) { list . add ( element ) ; } } return list ;


signature:
public class ConcurrentHashMultiset { /** * Adds a number of occurrences of the specified element to this multiset .
 * @ param element the element to add
 * @ param occurrences the number of occurrences to add
 * @ return the previous count of the element before the operation ; possibly zero
 * @ throws IllegalArgumentException if { @ code occurrences } is negative , or if the resulting amount
 * would exceed { @ link Integer # MAX _ VALUE } */
@ CanIgnoreReturnValue @ Override public int add ( E element , int occurrences ) { } }

implementation:
checkNotNull ( element ) ; if ( occurrences == 0 ) { return count ( element ) ; } CollectPreconditions . checkPositive ( occurrences , "occurences" ) ; while ( true ) { AtomicInteger existingCounter = Maps . safeGet ( countMap , element ) ; if ( existingCounter == null ) { existingCounter = countMap . putIfAbsent ( element , new AtomicInteger ( occurrences ) ) ; if ( existingCounter == null ) { return 0 ; } // existingCounter ! = null : fall through to operate against the existing AtomicInteger
} while ( true ) { int oldValue = existingCounter . get ( ) ; if ( oldValue != 0 ) { try { int newValue = IntMath . checkedAdd ( oldValue , occurrences ) ; if ( existingCounter . compareAndSet ( oldValue , newValue ) ) { // newValue can ' t = = 0 , so no need to check & remove
return oldValue ; } } catch ( ArithmeticException overflow ) { throw new IllegalArgumentException ( "Overflow adding " + occurrences + " occurrences to a count of " + oldValue ) ; } } else { // In the case of a concurrent remove , we might observe a zero value , which means another
// thread is about to remove ( element , existingCounter ) from the map . Rather than wait ,
// we can just do that work here .
AtomicInteger newCounter = new AtomicInteger ( occurrences ) ; if ( ( countMap . putIfAbsent ( element , newCounter ) == null ) || countMap . replace ( element , existingCounter , newCounter ) ) { return 0 ; } break ; } } // If we ' re still here , there was a race , so just try again .
}


signature:
public class ConcurrentHashMultiset { /** * Views */
@ Override Set < E > createElementSet ( ) { } }

implementation: final Set < E > delegate = countMap . keySet ( ) ; return new ForwardingSet < E > ( ) { @ Override protected Set < E > delegate ( ) { return delegate ; } @ Override public boolean contains ( @ NullableDecl Object object ) { return object != null && Collections2 . safeContains ( delegate , object ) ; } @ Override public boolean containsAll ( Collection < ? > collection ) { return standardContainsAll ( collection ) ; } @ Override public boolean remove ( Object object ) { return object != null && Collections2 . safeRemove ( delegate , object ) ; } @ Override public boolean removeAll ( Collection < ? > c ) { return standardRemoveAll ( c ) ; } } ;


signature:
public class CompactHashSet { /** * Creates a fresh entry with the specified object at the specified position in the entry arrays . */
void insertEntry ( int entryIndex , E object , int hash ) { } }

implementation: this . entries [ entryIndex ] = ( ( long ) hash << 32 ) | ( NEXT_MASK & UNSET ) ; this . elements [ entryIndex ] = object ;


signature:
public class CompactHashSet { /** * Resizes the entries storage if necessary . */
private void resizeMeMaybe ( int newSize ) { } }

implementation: int entriesSize = entries . length ; if ( newSize > entriesSize ) { int newCapacity = entriesSize + Math . max ( 1 , entriesSize >>> 1 ) ; if ( newCapacity < 0 ) { newCapacity = Integer . MAX_VALUE ; } if ( newCapacity != entriesSize ) { resizeEntries ( newCapacity ) ; } }


signature:
public class CompactHashSet { /** * Resizes the internal entries array to the specified capacity , which may be greater or less than
 * the current capacity . */
void resizeEntries ( int newCapacity ) { } }

implementation: this . elements = Arrays . copyOf ( elements , newCapacity ) ; long [ ] entries = this . entries ; int oldCapacity = entries . length ; entries = Arrays . copyOf ( entries , newCapacity ) ; if ( newCapacity > oldCapacity ) { Arrays . fill ( entries , oldCapacity , newCapacity , UNSET ) ; } this . entries = entries ;


signature:
public class CompactHashSet { /** * Moves the last entry in the entry array into { @ code dstIndex } , and nulls out its old position . */
void moveLastEntry ( int dstIndex ) { } }

implementation:
int srcIndex = size ( ) - 1 ; if ( dstIndex < srcIndex ) { // move last entry to deleted spot
elements [ dstIndex ] = elements [ srcIndex ] ; elements [ srcIndex ] = null ; // move the last entry to the removed spot , just like we moved the element
long lastEntry = entries [ srcIndex ] ; entries [ dstIndex ] = lastEntry ; entries [ srcIndex ] = UNSET ; // also need to update whoever ' s " next " pointer was pointing to the last entry place
// reusing " tableIndex " and " next " ; these variables were no longer needed
int tableIndex = getHash ( lastEntry ) & hashTableMask ( ) ; int lastNext = table [ tableIndex ] ; if ( lastNext == srcIndex ) { // we need to update the root pointer
table [ tableIndex ] = dstIndex ; } else { // we need to update a pointer in an entry
int previous ; long entry ; do { previous = lastNext ; lastNext = getNext ( entry = entries [ lastNext ] ) ; } while ( lastNext != srcIndex ) ; // here , entries [ previous ] points to the old entry location ; update it
entries [ previous ] = swapNext ( entry , dstIndex ) ; } } else { elements [ dstIndex ] = null ; entries [ dstIndex ] = UNSET ; }


signature:
public class CompactHashSet { /** * Ensures that this { @ code CompactHashSet } has the smallest representation in memory , given its
 * current size . */
public void trimToSize ( ) { } }

implementation: if ( needsAllocArrays ( ) ) { return ; } int size = this . size ; if ( size < entries . length ) { resizeEntries ( size ) ; } int minimumTableSize = Hashing . closedTableSize ( size , LOAD_FACTOR ) ; if ( minimumTableSize < table . length ) { resizeTable ( minimumTableSize ) ; }


signature:
public class CompactHashSet { /** * The serial form currently mimics Android ' s java . util . HashSet version , e . g . see
 * http : / / omapzoom . org / ? p = platform / libcore . git ; a = blob ; f = luni / src / main / java / java / util / HashSet . java */
private void writeObject ( ObjectOutputStream stream ) throws IOException { } }

implementation: stream . defaultWriteObject ( ) ; stream . writeInt ( size ) ; for ( int i = firstEntryIndex ( ) ; i >= 0 ; i = getSuccessor ( i ) ) { stream . writeObject ( elements [ i ] ) ; }


signature:
public class InetAddresses { /** * Returns an { @ link Inet4Address } , given a byte array representation of the IPv4 address .
 * @ param bytes byte array representing an IPv4 address ( should be of length 4)
 * @ return { @ link Inet4Address } corresponding to the supplied byte array
 * @ throws IllegalArgumentException if a valid { @ link Inet4Address } can not be created */
private static Inet4Address getInet4Address ( byte [ ] bytes ) { } }

implementation:
checkArgument ( bytes . length == 4 , "Byte array has invalid length for an IPv4 address: %s != 4." , bytes . length ) ; // Given a 4 - byte array , this cast should always succeed .
return ( Inet4Address ) bytesToInetAddress ( bytes ) ;


signature:
public class InetAddresses { /** * Returns the { @ link InetAddress } having the given string representation .
 * < p > This deliberately avoids all nameservice lookups ( e . g . no DNS ) .
 * @ param ipString { @ code String } containing an IPv4 or IPv6 string literal , e . g . { @ code
 * " 192.168.0.1 " } or { @ code " 2001 : db8 : : 1 " }
 * @ return { @ link InetAddress } representing the argument
 * @ throws IllegalArgumentException if the argument is not a valid IP string literal */
public static InetAddress forString ( String ipString ) { } }

implementation:
byte [ ] addr = ipStringToBytes ( ipString ) ; // The argument was malformed , i . e . not an IP string literal .
if ( addr == null ) { throw formatIllegalArgumentException ( "'%s' is not an IP string literal." , ipString ) ; } return bytesToInetAddress ( addr ) ;


signature:
public class InetAddresses { /** * Convert a byte array into an InetAddress .
 * < p > { @ link InetAddress # getByAddress } is documented as throwing a checked exception " if IP
 * address is of illegal length . " We replace it with an unchecked exception , for use by callers
 * who already know that addr is an array of length 4 or 16.
 * @ param addr the raw 4 - byte or 16 - byte IP address in big - endian order
 * @ return an InetAddress object created from the raw IP address */
private static InetAddress bytesToInetAddress ( byte [ ] addr ) { } }

implementation: try { return InetAddress . getByAddress ( addr ) ; } catch ( UnknownHostException e ) { throw new AssertionError ( e ) ; }


signature:
public class InetAddresses { /** * Returns the string representation of an { @ link InetAddress } .
 * < p > For IPv4 addresses , this is identical to { @ link InetAddress # getHostAddress ( ) } , but for IPv6
 * addresses , the output follows < a href = " http : / / tools . ietf . org / html / rfc5952 " > RFC 5952 < / a > section
 * 4 . The main difference is that this method uses " : : " for zero compression , while Java ' s version
 * uses the uncompressed form .
 * < p > This method uses hexadecimal for all IPv6 addresses , including IPv4 - mapped IPv6 addresses
 * such as " : : c000:201 " . The output does not include a Scope ID .
 * @ param ip { @ link InetAddress } to be converted to an address string
 * @ return { @ code String } containing the text - formatted IP address
 * @ since 10.0 */
public static String toAddrString ( InetAddress ip ) { } }

implementation:
checkNotNull ( ip ) ; if ( ip instanceof Inet4Address ) { // For IPv4 , Java ' s formatting is good enough .
return ip . getHostAddress ( ) ; } checkArgument ( ip instanceof Inet6Address ) ; byte [ ] bytes = ip . getAddress ( ) ; int [ ] hextets = new int [ IPV6_PART_COUNT ] ; for ( int i = 0 ; i < hextets . length ; i ++ ) { hextets [ i ] = Ints . fromBytes ( ( byte ) 0 , ( byte ) 0 , bytes [ 2 * i ] , bytes [ 2 * i + 1 ] ) ; } compressLongestRunOfZeroes ( hextets ) ; return hextetsToIPv6String ( hextets ) ;


signature:
public class InetAddresses { /** * Identify and mark the longest run of zeroes in an IPv6 address .
 * < p > Only runs of two or more hextets are considered . In case of a tie , the leftmost run wins . If
 * a qualifying run is found , its hextets are replaced by the sentinel value - 1.
 * @ param hextets { @ code int [ ] } mutable array of eight 16 - bit hextets */
private static void compressLongestRunOfZeroes ( int [ ] hextets ) { } }

implementation: int bestRunStart = - 1 ; int bestRunLength = - 1 ; int runStart = - 1 ; for ( int i = 0 ; i < hextets . length + 1 ; i ++ ) { if ( i < hextets . length && hextets [ i ] == 0 ) { if ( runStart < 0 ) { runStart = i ; } } else if ( runStart >= 0 ) { int runLength = i - runStart ; if ( runLength > bestRunLength ) { bestRunStart = runStart ; bestRunLength = runLength ; } runStart = - 1 ; } } if ( bestRunLength >= 2 ) { Arrays . fill ( hextets , bestRunStart , bestRunStart + bestRunLength , - 1 ) ; }


signature:
public class InetAddresses { /** * Convert a list of hextets into a human - readable IPv6 address .
 * < p > In order for " : : " compression to work , the input should contain negative sentinel values in
 * place of the elided zeroes .
 * @ param hextets { @ code int [ ] } array of eight 16 - bit hextets , or - 1s */
private static String hextetsToIPv6String ( int [ ] hextets ) { } }

implementation:
// While scanning the array , handle these state transitions :
// start - > num = > " num " start - > gap = > " : : "
// num - > num = > " : num " num - > gap = > " : : "
// gap - > num = > " num " gap - > gap = > " "
StringBuilder buf = new StringBuilder ( 39 ) ; boolean lastWasNumber = false ; for ( int i = 0 ; i < hextets . length ; i ++ ) { boolean thisIsNumber = hextets [ i ] >= 0 ; if ( thisIsNumber ) { if ( lastWasNumber ) { buf . append ( ':' ) ; } buf . append ( Integer . toHexString ( hextets [ i ] ) ) ; } else { if ( i == 0 || lastWasNumber ) { buf . append ( "::" ) ; } } lastWasNumber = thisIsNumber ; } return buf . toString ( ) ;


signature:
public class InetAddresses { /** * Returns the string representation of an { @ link InetAddress } suitable for inclusion in a URI .
 * < p > For IPv4 addresses , this is identical to { @ link InetAddress # getHostAddress ( ) } , but for IPv6
 * addresses it compresses zeroes and surrounds the text with square brackets ; for example { @ code
 * " [ 2001 : db8 : : 1 ] " } .
 * < p > Per section 3.2.2 of < a target = " _ parent "
 * href = " http : / / tools . ietf . org / html / rfc3986 # section - 3.2.2 " > RFC 3986 < / a > , a URI containing an IPv6
 * string literal is of the form { @ code " http : / / [ 2001 : db8 : : 1 ] : 8888 / index . html " } .
 * < p > Use of either { @ link InetAddresses # toAddrString } , { @ link InetAddress # getHostAddress ( ) } , or
 * this method is recommended over { @ link InetAddress # toString ( ) } when an IP address string
 * literal is desired . This is because { @ link InetAddress # toString ( ) } prints the hostname and the
 * IP address string joined by a " / " .
 * @ param ip { @ link InetAddress } to be converted to URI string literal
 * @ return { @ code String } containing URI - safe string literal */
public static String toUriString ( InetAddress ip ) { } }

implementation: if ( ip instanceof Inet6Address ) { return "[" + toAddrString ( ip ) + "]" ; } return toAddrString ( ip ) ;


signature:
public class InetAddresses { /** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL , encoded in
 * the format specified by RFC 3986 section 3.2.2.
 * < p > This function is similar to { @ link InetAddresses # forString ( String ) } , however , it requires
 * that IPv6 addresses are surrounded by square brackets .
 * < p > This function is the inverse of { @ link InetAddresses # toUriString ( java . net . InetAddress ) } .
 * @ param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address
 * @ return an InetAddress representing the address in { @ code hostAddr }
 * @ throws IllegalArgumentException if { @ code hostAddr } is not a valid IPv4 address , or IPv6
 * address surrounded by square brackets */
public static InetAddress forUriString ( String hostAddr ) { } }

implementation: InetAddress addr = forUriStringNoThrow ( hostAddr ) ; if ( addr == null ) { throw formatIllegalArgumentException ( "Not a valid URI IP literal: '%s'" , hostAddr ) ; } return addr ;


signature:
public class InetAddresses { /** * Evaluates whether the argument is an IPv6 " compat " address .
 * < p > An " IPv4 compatible " , or " compat " , address is one with 96 leading bits of zero , with the
 * remaining 32 bits interpreted as an IPv4 address . These are conventionally represented in
 * string literals as { @ code " : : 192.168.0.1 " } , though { @ code " : : c0a8:1 " } is also considered an
 * IPv4 compatible address ( and equivalent to { @ code " : : 192.168.0.1 " } ) .
 * < p > For more on IPv4 compatible addresses see section 2.5.5.1 of < a target = " _ parent "
 * href = " http : / / tools . ietf . org / html / rfc4291 # section - 2.5.5.1 " > RFC 4291 < / a > .
 * < p > NOTE : This method is different from { @ link Inet6Address # isIPv4CompatibleAddress } in that it
 * more correctly classifies { @ code " : : " } and { @ code " : : 1 " } as proper IPv6 addresses ( which they
 * are ) , NOT IPv4 compatible addresses ( which they are generally NOT considered to be ) .
 * @ param ip { @ link Inet6Address } to be examined for embedded IPv4 compatible address format
 * @ return { @ code true } if the argument is a valid " compat " address */
public static boolean isCompatIPv4Address ( Inet6Address ip ) { } }

implementation: if ( ! ip . isIPv4CompatibleAddress ( ) ) { return false ; } byte [ ] bytes = ip . getAddress ( ) ; if ( ( bytes [ 12 ] == 0 ) && ( bytes [ 13 ] == 0 ) && ( bytes [ 14 ] == 0 ) && ( ( bytes [ 15 ] == 0 ) || ( bytes [ 15 ] == 1 ) ) ) { return false ; } return true ;


signature:
public class InetAddresses { /** * Returns the IPv4 address embedded in an IPv4 compatible address .
 * @ param ip { @ link Inet6Address } to be examined for an embedded IPv4 address
 * @ return { @ link Inet4Address } of the embedded IPv4 address
 * @ throws IllegalArgumentException if the argument is not a valid IPv4 compatible address */
public static Inet4Address getCompatIPv4Address ( Inet6Address ip ) { } }

implementation: checkArgument ( isCompatIPv4Address ( ip ) , "Address '%s' is not IPv4-compatible." , toAddrString ( ip ) ) ; return getInet4Address ( Arrays . copyOfRange ( ip . getAddress ( ) , 12 , 16 ) ) ;


signature:
public class InetAddresses { /** * Evaluates whether the argument is a Teredo address .
 * < p > Teredo addresses begin with the { @ code " 2001 : : / 32 " } prefix .
 * @ param ip { @ link Inet6Address } to be examined for Teredo address format
 * @ return { @ code true } if the argument is a Teredo address */
public static boolean isTeredoAddress ( Inet6Address ip ) { } }

implementation: byte [ ] bytes = ip . getAddress ( ) ; return ( bytes [ 0 ] == ( byte ) 0x20 ) && ( bytes [ 1 ] == ( byte ) 0x01 ) && ( bytes [ 2 ] == 0 ) && ( bytes [ 3 ] == 0 ) ;


signature:
public class InetAddresses { /** * Evaluates whether the argument is an ISATAP address .
 * < p > From RFC 5214 : " ISATAP interface identifiers are constructed in Modified EUI - 64 format [ . . . ]
 * by concatenating the 24 - bit IANA OUI ( 00-00-5E ) , the 8 - bit hexadecimal value 0xFE , and a 32 - bit
 * IPv4 address in network byte order [ . . . ] "
 * < p > For more on ISATAP addresses see section 6.1 of < a target = " _ parent "
 * href = " http : / / tools . ietf . org / html / rfc5214 # section - 6.1 " > RFC 5214 < / a > .
 * @ param ip { @ link Inet6Address } to be examined for ISATAP address format
 * @ return { @ code true } if the argument is an ISATAP address */
public static boolean isIsatapAddress ( Inet6Address ip ) { } }

implementation:
// If it ' s a Teredo address with the right port ( 41217 , or 0xa101)
// which would be encoded as 0x5efe then it can ' t be an ISATAP address .
if ( isTeredoAddress ( ip ) ) { return false ; } byte [ ] bytes = ip . getAddress ( ) ; if ( ( bytes [ 8 ] | ( byte ) 0x03 ) != ( byte ) 0x03 ) { // Verify that high byte of the 64 bit identifier is zero , modulo
// the U / L and G bits , with which we are not concerned .
return false ; } return ( bytes [ 9 ] == ( byte ) 0x00 ) && ( bytes [ 10 ] == ( byte ) 0x5e ) && ( bytes [ 11 ] == ( byte ) 0xfe ) ;


signature:
public class InetAddresses { /** * Returns the IPv4 address embedded in an ISATAP address .
 * @ param ip { @ link Inet6Address } to be examined for embedded IPv4 in ISATAP address
 * @ return { @ link Inet4Address } of embedded IPv4 in an ISATAP address
 * @ throws IllegalArgumentException if the argument is not a valid IPv6 ISATAP address */
public static Inet4Address getIsatapIPv4Address ( Inet6Address ip ) { } }

implementation: checkArgument ( isIsatapAddress ( ip ) , "Address '%s' is not an ISATAP address." , toAddrString ( ip ) ) ; return getInet4Address ( Arrays . copyOfRange ( ip . getAddress ( ) , 12 , 16 ) ) ;


signature:
public class InetAddresses { /** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an
 * IPv6 address of one of the specified address types that contain an embedded IPv4 address .
 * < p > NOTE : ISATAP addresses are explicitly excluded from this method due to their trivial
 * spoofability . With other transition addresses spoofing involves ( at least ) infection of one ' s
 * BGP routing table .
 * @ param ip { @ link Inet6Address } to be examined for embedded IPv4 client address
 * @ return { @ link Inet4Address } of embedded IPv4 client address
 * @ throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */
public static Inet4Address getEmbeddedIPv4ClientAddress ( Inet6Address ip ) { } }

implementation: if ( isCompatIPv4Address ( ip ) ) { return getCompatIPv4Address ( ip ) ; } if ( is6to4Address ( ip ) ) { return get6to4IPv4Address ( ip ) ; } if ( isTeredoAddress ( ip ) ) { return getTeredoInfo ( ip ) . getClient ( ) ; } throw formatIllegalArgumentException ( "'%s' has no embedded IPv4 address." , toAddrString ( ip ) ) ;


signature:
public class InetAddresses { /** * Evaluates whether the argument is an " IPv4 mapped " IPv6 address .
 * < p > An " IPv4 mapped " address is anything in the range : : ffff : 0:0/96 ( sometimes written as
 * : : ffff : 0.0.0.0/96 ) , with the last 32 bits interpreted as an IPv4 address .
 * < p > For more on IPv4 mapped addresses see section 2.5.5.2 of < a target = " _ parent "
 * href = " http : / / tools . ietf . org / html / rfc4291 # section - 2.5.5.2 " > RFC 4291 < / a > .
 * < p > Note : This method takes a { @ code String } argument because { @ link InetAddress } automatically
 * collapses mapped addresses to IPv4 . ( It is actually possible to avoid this using one of the
 * obscure { @ link Inet6Address } methods , but it would be unwise to depend on such a
 * poorly - documented feature . )
 * @ param ipString { @ code String } to be examined for embedded IPv4 - mapped IPv6 address format
 * @ return { @ code true } if the argument is a valid " mapped " address
 * @ since 10.0 */
public static boolean isMappedIPv4Address ( String ipString ) { } }

implementation: byte [ ] bytes = ipStringToBytes ( ipString ) ; if ( bytes != null && bytes . length == 16 ) { for ( int i = 0 ; i < 10 ; i ++ ) { if ( bytes [ i ] != 0 ) { return false ; } } for ( int i = 10 ; i < 12 ; i ++ ) { if ( bytes [ i ] != ( byte ) 0xff ) { return false ; } } return true ; } return false ;


signature:
public class InetAddresses { /** * Returns an address from a < b > little - endian ordered < / b > byte array ( the opposite of what { @ link
 * InetAddress # getByAddress } expects ) .
 * < p > IPv4 address byte array must be 4 bytes long and IPv6 byte array must be 16 bytes long .
 * @ param addr the raw IP address in little - endian byte order
 * @ return an InetAddress object created from the raw IP address
 * @ throws UnknownHostException if IP address is of illegal length */
public static InetAddress fromLittleEndianByteArray ( byte [ ] addr ) throws UnknownHostException { } }

implementation: byte [ ] reversed = new byte [ addr . length ] ; for ( int i = 0 ; i < addr . length ; i ++ ) { reversed [ i ] = addr [ addr . length - i - 1 ] ; } return InetAddress . getByAddress ( reversed ) ;


signature:
public class InetAddresses { /** * Returns a new InetAddress that is one less than the passed in address . This method works for
 * both IPv4 and IPv6 addresses .
 * @ param address the InetAddress to decrement
 * @ return a new InetAddress that is one less than the passed in address
 * @ throws IllegalArgumentException if InetAddress is at the beginning of its range
 * @ since 18.0 */
public static InetAddress decrement ( InetAddress address ) { } }

implementation: byte [ ] addr = address . getAddress ( ) ; int i = addr . length - 1 ; while ( i >= 0 && addr [ i ] == ( byte ) 0x00 ) { addr [ i ] = ( byte ) 0xff ; i -- ; } checkArgument ( i >= 0 , "Decrementing %s would wrap." , address ) ; addr [ i ] -- ; return bytesToInetAddress ( addr ) ;


signature:
public class InetAddresses { /** * Returns true if the InetAddress is either 255.255.255.255 for IPv4 or
 * ffff : ffff : ffff : ffff : ffff : ffff : ffff : ffff for IPv6.
 * @ return true if the InetAddress is either 255.255.255.255 for IPv4 or
 * ffff : ffff : ffff : ffff : ffff : ffff : ffff : ffff for IPv6
 * @ since 10.0 */
public static boolean isMaximum ( InetAddress address ) { } }

implementation: byte [ ] addr = address . getAddress ( ) ; for ( int i = 0 ; i < addr . length ; i ++ ) { if ( addr [ i ] != ( byte ) 0xff ) { return false ; } } return true ;


signature:
public class JdkBackedImmutableMap { /** * Creates an { @ code ImmutableMap } backed by a JDK HashMap . Used when probable hash flooding is
 * detected . This implementation may replace the entries in entryArray with its own entry objects
 * ( though they will have the same key / value contents ) , and will take ownership of entryArray . */
static < K , V > ImmutableMap < K , V > create ( int n , Entry < K , V > [ ] entryArray ) { } }

implementation: Map < K , V > delegateMap = Maps . newHashMapWithExpectedSize ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { entryArray [ i ] = makeImmutable ( entryArray [ i ] ) ; V oldValue = delegateMap . putIfAbsent ( entryArray [ i ] . getKey ( ) , entryArray [ i ] . getValue ( ) ) ; if ( oldValue != null ) { throw conflictException ( "key" , entryArray [ i ] , entryArray [ i ] . getKey ( ) + "=" + oldValue ) ; } } return new JdkBackedImmutableMap < > ( delegateMap , ImmutableList . asImmutableList ( entryArray , n ) ) ;


signature:
public class LongMath { /** * Returns the largest power of two less than or equal to { @ code x } . This is equivalent to { @ code
 * checkedPow ( 2 , log2 ( x , FLOOR ) ) } .
 * @ throws IllegalArgumentException if { @ code x < = 0}
 * @ since 20.0 */
@ Beta public static long floorPowerOfTwo ( long x ) { } }

implementation:
checkPositive ( "x" , x ) ; // Long . highestOneBit was buggy on GWT . We ' ve fixed it , but I ' m not certain when the fix will
// be released .
return 1L << ( ( Long . SIZE - 1 ) - Long . numberOfLeadingZeros ( x ) ) ;


signature:
public class LongMath { /** * Returns the base - 10 logarithm of { @ code x } , rounded according to the specified rounding mode .
 * @ throws IllegalArgumentException if { @ code x < = 0}
 * @ throws ArithmeticException if { @ code mode } is { @ link RoundingMode # UNNECESSARY } and { @ code x }
 * is not a power of ten */
@ GwtIncompatible // TODO
@ SuppressWarnings ( "fallthrough" ) // TODO ( kevinb ) : remove after this warning is disabled globally
public static int log10 ( long x , RoundingMode mode ) { } }

implementation:
checkPositive ( "x" , x ) ; int logFloor = log10Floor ( x ) ; long floorPow = powersOf10 [ logFloor ] ; switch ( mode ) { case UNNECESSARY : checkRoundingUnnecessary ( x == floorPow ) ; // fall through
case FLOOR : case DOWN : return logFloor ; case CEILING : case UP : return logFloor + lessThanBranchFree ( floorPow , x ) ; case HALF_DOWN : case HALF_UP : case HALF_EVEN : // sqrt ( 10 ) is irrational , so log10 ( x ) - logFloor is never exactly 0.5
return logFloor + lessThanBranchFree ( halfPowersOf10 [ logFloor ] , x ) ; default : throw new AssertionError ( ) ; }


signature:
public class LongMath { /** * Returns the square root of { @ code x } , rounded with the specified rounding mode .
 * @ throws IllegalArgumentException if { @ code x < 0}
 * @ throws ArithmeticException if { @ code mode } is { @ link RoundingMode # UNNECESSARY } and { @ code
 * sqrt ( x ) } is not an integer */
@ GwtIncompatible // TODO
@ SuppressWarnings ( "fallthrough" ) public static long sqrt ( long x , RoundingMode mode ) { } }

implementation:
checkNonNegative ( "x" , x ) ; if ( fitsInInt ( x ) ) { return IntMath . sqrt ( ( int ) x , mode ) ; } /* * Let k be the true value of floor ( sqrt ( x ) ) , so that
 * k * k < = x < ( k + 1 ) * ( k + 1)
 * ( double ) ( k * k ) < = ( double ) x < = ( double ) ( ( k + 1 ) * ( k + 1 ) )
 * since casting to double is nondecreasing .
 * Note that the right - hand inequality is no longer strict .
 * Math . sqrt ( k * k ) < = Math . sqrt ( x ) < = Math . sqrt ( ( k + 1 ) * ( k + 1 ) )
 * since Math . sqrt is monotonic .
 * ( long ) Math . sqrt ( k * k ) < = ( long ) Math . sqrt ( x ) < = ( long ) Math . sqrt ( ( k + 1 ) * ( k + 1 ) )
 * since casting to long is monotonic
 * k < = ( long ) Math . sqrt ( x ) < = k + 1
 * since ( long ) Math . sqrt ( k * k ) = = k , as checked exhaustively in
 * { @ link LongMathTest # testSqrtOfPerfectSquareAsDoubleIsPerfect } */
long guess = ( long ) Math . sqrt ( x ) ; // Note : guess is always < = FLOOR _ SQRT _ MAX _ LONG .
long guessSquared = guess * guess ; // Note ( 2013-2-26 ) : benchmarks indicate that , inscrutably enough , using if statements is
// faster here than using lessThanBranchFree .
switch ( mode ) { case UNNECESSARY : checkRoundingUnnecessary ( guessSquared == x ) ; return guess ; case FLOOR : case DOWN : if ( x < guessSquared ) { return guess - 1 ; } return guess ; case CEILING : case UP : if ( x > guessSquared ) { return guess + 1 ; } return guess ; case HALF_DOWN : case HALF_UP : case HALF_EVEN : long sqrtFloor = guess - ( ( x < guessSquared ) ? 1 : 0 ) ; long halfSquare = sqrtFloor * sqrtFloor + sqrtFloor ; /* * We wish to test whether or not x < = ( sqrtFloor + 0.5 ) ^ 2 = halfSquare + 0.25 . Since both x
 * and halfSquare are integers , this is equivalent to testing whether or not x < =
 * halfSquare . ( We have to deal with overflow , though . )
 * If we treat halfSquare as an unsigned long , we know that
 * sqrtFloor ^ 2 < = x < ( sqrtFloor + 1 ) ^ 2
 * halfSquare - sqrtFloor < = x < halfSquare + sqrtFloor + 1
 * so | x - halfSquare | < = sqrtFloor . Therefore , it ' s safe to treat x - halfSquare as a
 * signed long , so lessThanBranchFree is safe for use . */
return sqrtFloor + lessThanBranchFree ( halfSquare , x ) ; default : throw new AssertionError ( ) ; }


signature:
public class LongMath { /** * Returns the result of dividing { @ code p } by { @ code q } , rounding using the specified { @ code
 * RoundingMode } .
 * @ throws ArithmeticException if { @ code q = = 0 } , or if { @ code mode = = UNNECESSARY } and { @ code a }
 * is not an integer multiple of { @ code b } */
@ GwtIncompatible // TODO
@ SuppressWarnings ( "fallthrough" ) public static long divide ( long p , long q , RoundingMode mode ) { } }

implementation:
checkNotNull ( mode ) ; long div = p / q ; // throws if q = = 0
long rem = p - q * div ; // equals p % q
if ( rem == 0 ) { return div ; } /* * Normal Java division rounds towards 0 , consistently with RoundingMode . DOWN . We just have to
 * deal with the cases where rounding towards 0 is wrong , which typically depends on the sign of
 * p / q .
 * signum is 1 if p and q are both nonnegative or both negative , and - 1 otherwise . */
int signum = 1 | ( int ) ( ( p ^ q ) >> ( Long . SIZE - 1 ) ) ; boolean increment ; switch ( mode ) { case UNNECESSARY : checkRoundingUnnecessary ( rem == 0 ) ; // fall through
case DOWN : increment = false ; break ; case UP : increment = true ; break ; case CEILING : increment = signum > 0 ; break ; case FLOOR : increment = signum < 0 ; break ; case HALF_EVEN : case HALF_DOWN : case HALF_UP : long absRem = abs ( rem ) ; long cmpRemToHalfDivisor = absRem - ( abs ( q ) - absRem ) ; // subtracting two nonnegative longs can ' t overflow
// cmpRemToHalfDivisor has the same sign as compare ( abs ( rem ) , abs ( q ) / 2 ) .
if ( cmpRemToHalfDivisor == 0 ) { // exactly on the half mark
increment = ( mode == HALF_UP | ( mode == HALF_EVEN & ( div & 1 ) != 0 ) ) ; } else { increment = cmpRemToHalfDivisor > 0 ; // closer to the UP value
} break ; default : throw new AssertionError ( ) ; } return increment ? div + signum : div ;


signature:
public class LongMath { /** * Returns the difference of { @ code a } and { @ code b } , provided it does not overflow .
 * @ throws ArithmeticException if { @ code a - b } overflows in signed { @ code long } arithmetic */
@ GwtIncompatible // TODO
public static long checkedSubtract ( long a , long b ) { } }

implementation: long result = a - b ; checkNoOverflow ( ( a ^ b ) >= 0 | ( a ^ result ) >= 0 , "checkedSubtract" , a , b ) ; return result ;


signature:
public class LongMath { /** * Returns the { @ code b } to the { @ code k } th power , provided it does not overflow .
 * @ throws ArithmeticException if { @ code b } to the { @ code k } th power overflows in signed { @ code
 * long } arithmetic */
@ GwtIncompatible // TODO
public static long checkedPow ( long b , int k ) { } }

implementation: checkNonNegative ( "exponent" , k ) ; if ( b >= - 2 & b <= 2 ) { switch ( ( int ) b ) { case 0 : return ( k == 0 ) ? 1 : 0 ; case 1 : return 1 ; case ( - 1 ) : return ( ( k & 1 ) == 0 ) ? 1 : - 1 ; case 2 : checkNoOverflow ( k < Long . SIZE - 1 , "checkedPow" , b , k ) ; return 1L << k ; case ( - 2 ) : checkNoOverflow ( k < Long . SIZE , "checkedPow" , b , k ) ; return ( ( k & 1 ) == 0 ) ? ( 1L << k ) : ( - 1L << k ) ; default : throw new AssertionError ( ) ; } } long accum = 1 ; while ( true ) { switch ( k ) { case 0 : return accum ; case 1 : return checkedMultiply ( accum , b ) ; default : if ( ( k & 1 ) != 0 ) { accum = checkedMultiply ( accum , b ) ; } k >>= 1 ; if ( k > 0 ) { checkNoOverflow ( - FLOOR_SQRT_MAX_LONG <= b && b <= FLOOR_SQRT_MAX_LONG , "checkedPow" , b , k ) ; b *= b ; } } }


signature:
public class LongMath { /** * Returns { @ code n ! } , that is , the product of the first { @ code n } positive integers , { @ code 1 } if
 * { @ code n = = 0 } , or { @ link Long # MAX _ VALUE } if the result does not fit in a { @ code long } .
 * @ throws IllegalArgumentException if { @ code n < 0} */
@ GwtIncompatible // TODO
public static long factorial ( int n ) { } }

implementation: checkNonNegative ( "n" , n ) ; return ( n < factorials . length ) ? factorials [ n ] : Long . MAX_VALUE ;


signature:
public class LongMath { /** * Returns { @ code n } choose { @ code k } , also known as the binomial coefficient of { @ code n } and
 * { @ code k } , or { @ link Long # MAX _ VALUE } if the result does not fit in a { @ code long } .
 * @ throws IllegalArgumentException if { @ code n < 0 } , { @ code k < 0 } , or { @ code k > n } */
public static long binomial ( int n , int k ) { } }

implementation:
checkNonNegative ( "n" , n ) ; checkNonNegative ( "k" , k ) ; checkArgument ( k <= n , "k (%s) > n (%s)" , k , n ) ; if ( k > ( n >> 1 ) ) { k = n - k ; } switch ( k ) { case 0 : return 1 ; case 1 : return n ; default : if ( n < factorials . length ) { return factorials [ n ] / ( factorials [ k ] * factorials [ n - k ] ) ; } else if ( k >= biggestBinomials . length || n > biggestBinomials [ k ] ) { return Long . MAX_VALUE ; } else if ( k < biggestSimpleBinomials . length && n <= biggestSimpleBinomials [ k ] ) { // guaranteed not to overflow
long result = n -- ; for ( int i = 2 ; i <= k ; n -- , i ++ ) { result *= n ; result /= i ; } return result ; } else { int nBits = LongMath . log2 ( n , RoundingMode . CEILING ) ; long result = 1 ; long numerator = n -- ; long denominator = 1 ; int numeratorBits = nBits ; // This is an upper bound on log2 ( numerator , ceiling ) .
/* * We want to do this in long math for speed , but want to avoid overflow . We adapt the
 * technique previously used by BigIntegerMath : maintain separate numerator and
 * denominator accumulators , multiplying the fraction into result when near overflow . */
for ( int i = 2 ; i <= k ; i ++ , n -- ) { if ( numeratorBits + nBits < Long . SIZE - 1 ) { // It ' s definitely safe to multiply into numerator and denominator .
numerator *= n ; denominator *= i ; numeratorBits += nBits ; } else { // It might not be safe to multiply into numerator and denominator ,
// so multiply ( numerator / denominator ) into result .
result = multiplyFraction ( result , numerator , denominator ) ; numerator = n ; denominator = i ; numeratorBits = nBits ; } } return multiplyFraction ( result , numerator , denominator ) ; } }


signature:
public class LongMath { /** * Returns ( x * numerator / denominator ) , which is assumed to come out to an integral value . */
static long multiplyFraction ( long x , long numerator , long denominator ) { } }

implementation:
if ( x == 1 ) { return numerator / denominator ; } long commonDivisor = gcd ( x , denominator ) ; x /= commonDivisor ; denominator /= commonDivisor ; // We know gcd ( x , denominator ) = 1 , and x * numerator / denominator is exact ,
// so denominator must be a divisor of numerator .
return x * ( numerator / denominator ) ;


signature:
public class LongMath { /** * Returns { @ code true } if { @ code n } is a < a
 * href = " http : / / mathworld . wolfram . com / PrimeNumber . html " > prime number < / a > : an integer < i > greater
 * than one < / i > that cannot be factored into a product of < i > smaller < / i > positive integers .
 * Returns { @ code false } if { @ code n } is zero , one , or a composite number ( one which < i > can < / i > be
 * factored into smaller positive integers ) .
 * < p > To test larger numbers , use { @ link BigInteger # isProbablePrime } .
 * @ throws IllegalArgumentException if { @ code n } is negative
 * @ since 20.0 */
@ GwtIncompatible // TODO
@ Beta public static boolean isPrime ( long n ) { } }

implementation: if ( n < 2 ) { checkNonNegative ( "n" , n ) ; return false ; } if ( n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 ) { return true ; } if ( ( SIEVE_30 & ( 1 << ( n % 30 ) ) ) != 0 ) { return false ; } if ( n % 7 == 0 || n % 11 == 0 || n % 13 == 0 ) { return false ; } if ( n < 17 * 17 ) { return true ; } for ( long [ ] baseSet : millerRabinBaseSets ) { if ( n <= baseSet [ 0 ] ) { for ( int i = 1 ; i < baseSet . length ; i ++ ) { if ( ! MillerRabinTester . test ( baseSet [ i ] , n ) ) { return false ; } } return true ; } } throw new AssertionError ( ) ;


signature:
public class Chars { /** * Returns the { @ code char } nearest in value to { @ code value } .
 * @ param value any { @ code long } value
 * @ return the same value cast to { @ code char } if it is in the range of the { @ code char } type ,
 * { @ link Character # MAX _ VALUE } if it is too large , or { @ link Character # MIN _ VALUE } if it is too
 * small */
public static char saturatedCast ( long value ) { } }

implementation: if ( value > Character . MAX_VALUE ) { return Character . MAX_VALUE ; } if ( value < Character . MIN_VALUE ) { return Character . MIN_VALUE ; } return ( char ) value ;


signature:
public class Chars { /** * Copies a collection of { @ code Character } instances into a new array of primitive { @ code char }
 * values .
 * < p > Elements are copied from the argument collection as if by { @ code collection . toArray ( ) } .
 * Calling this method is as thread - safe as calling that method .
 * @ param collection a collection of { @ code Character } objects
 * @ return an array containing the same values as { @ code collection } , in the same order , converted
 * to primitives
 * @ throws NullPointerException if { @ code collection } or any of its elements is null */
public static char [ ] toArray ( Collection < Character > collection ) { } }

implementation:
if ( collection instanceof CharArrayAsList ) { return ( ( CharArrayAsList ) collection ) . toCharArray ( ) ; } Object [ ] boxedArray = collection . toArray ( ) ; int len = boxedArray . length ; char [ ] array = new char [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { // checkNotNull for GWT ( do not optimize )
array [ i ] = ( Character ) checkNotNull ( boxedArray [ i ] ) ; } return array ;


signature:
public class Chars { /** * Returns a fixed - size list backed by the specified array , similar to { @ link
 * Arrays # asList ( Object [ ] ) } . The list supports { @ link List # set ( int , Object ) } , but any attempt to
 * set a value to { @ code null } will result in a { @ link NullPointerException } .
 * < p > The returned list maintains the values , but not the identities , of { @ code Character } objects
 * written to or read from it . For example , whether { @ code list . get ( 0 ) = = list . get ( 0 ) } is true for
 * the returned list is unspecified .
 * @ param backingArray the array to back the list
 * @ return a list view of the array */
public static List < Character > asList ( char ... backingArray ) { } }

implementation: if ( backingArray . length == 0 ) { return Collections . emptyList ( ) ; } return new CharArrayAsList ( backingArray ) ;


signature:
public class Splitter { /** * Returns a splitter that considers any single character matched by the given { @ code CharMatcher }
 * to be a separator . For example , { @ code
 * Splitter . on ( CharMatcher . anyOf ( " ; , " ) ) . split ( " foo , ; bar , quux " ) } returns an iterable containing
 * { @ code [ " foo " , " " , " bar " , " quux " ] } .
 * @ param separatorMatcher a { @ link CharMatcher } that determines whether a character is a
 * separator
 * @ return a splitter , with default settings , that uses this matcher */
public static Splitter on ( final CharMatcher separatorMatcher ) { } }

implementation: checkNotNull ( separatorMatcher ) ; return new Splitter ( new Strategy ( ) { @ Override public SplittingIterator iterator ( Splitter splitter , final CharSequence toSplit ) { return new SplittingIterator ( splitter , toSplit ) { @ Override int separatorStart ( int start ) { return separatorMatcher . indexIn ( toSplit , start ) ; } @ Override int separatorEnd ( int separatorPosition ) { return separatorPosition + 1 ; } } ; } } ) ;


signature:
public class Splitter { /** * Returns a splitter that uses the given fixed string as a separator . For example , { @ code
 * Splitter . on ( " , " ) . split ( " foo , bar , baz " ) } returns an iterable containing { @ code [ " foo " ,
 * " bar , baz " ] } .
 * @ param separator the literal , nonempty string to recognize as a separator
 * @ return a splitter , with default settings , that recognizes that separator */
public static Splitter on ( final String separator ) { } }

implementation: checkArgument ( separator . length ( ) != 0 , "The separator may not be the empty string." ) ; if ( separator . length ( ) == 1 ) { return Splitter . on ( separator . charAt ( 0 ) ) ; } return new Splitter ( new Strategy ( ) { @ Override public SplittingIterator iterator ( Splitter splitter , CharSequence toSplit ) { return new SplittingIterator ( splitter , toSplit ) { @ Override public int separatorStart ( int start ) { int separatorLength = separator . length ( ) ; positions : for ( int p = start , last = toSplit . length ( ) - separatorLength ; p <= last ; p ++ ) { for ( int i = 0 ; i < separatorLength ; i ++ ) { if ( toSplit . charAt ( i + p ) != separator . charAt ( i ) ) { continue positions ; } } return p ; } return - 1 ; } @ Override public int separatorEnd ( int separatorPosition ) { return separatorPosition + separator . length ( ) ; } } ; } } ) ;