signature:
public class Multimaps { /** * Creates an index { @ code ImmutableListMultimap } that contains the results of applying a
 * specified function to each item in an { @ code Iterator } of values . Each value will be stored as
 * a value in the resulting multimap , yielding a multimap with the same size as the input
 * iterator . The key used to store that value in the multimap will be the result of calling the
 * function on that value . The resulting multimap is created as an immutable snapshot . In the
 * returned multimap , keys appear in the order they are first encountered , and the values
 * corresponding to each key appear in the same order as they are encountered .
 * < p > For example ,
 * < pre > { @ code
 * List < String > badGuys =
 * Arrays . asList ( " Inky " , " Blinky " , " Pinky " , " Pinky " , " Clyde " ) ;
 * Function < String , Integer > stringLengthFunction = . . . ;
 * Multimap < Integer , String > index =
 * Multimaps . index ( badGuys . iterator ( ) , stringLengthFunction ) ;
 * System . out . println ( index ) ;
 * } < / pre >
 * < p > prints
 * < pre > { @ code
 * { 4 = [ Inky ] , 6 = [ Blinky ] , 5 = [ Pinky , Pinky , Clyde ] }
 * } < / pre >
 * < p > The returned multimap is serializable if its keys and values are all serializable .
 * @ param values the values to use when constructing the { @ code ImmutableListMultimap }
 * @ param keyFunction the function used to produce the key for each value
 * @ return { @ code ImmutableListMultimap } mapping the result of evaluating the function { @ code
 * keyFunction } on each value in the input collection to that value
 * @ throws NullPointerException if any element of { @ code values } is { @ code null } , or if { @ code
 * keyFunction } produces { @ code null } for any key
 * @ since 10.0 */
public static < K , V > ImmutableListMultimap < K , V > index ( Iterator < V > values , Function < ? super V , K > keyFunction ) { } }

implementation: checkNotNull ( keyFunction ) ; ImmutableListMultimap . Builder < K , V > builder = ImmutableListMultimap . builder ( ) ; while ( values . hasNext ( ) ) { V value = values . next ( ) ; checkNotNull ( value , values ) ; builder . put ( keyFunction . apply ( value ) , value ) ; } return builder . build ( ) ;


signature:
public class Multimaps { /** * Returns a multimap containing the mappings in { @ code unfiltered } whose keys satisfy a
 * predicate . The returned multimap is a live view of { @ code unfiltered } ; changes to one affect
 * the other .
 * < p > The resulting multimap ' s views have iterators that don ' t support { @ code remove ( ) } , but all
 * other methods are supported by the multimap and its views . When adding a key that doesn ' t
 * satisfy the predicate , the multimap ' s { @ code put ( ) } , { @ code putAll ( ) } , and { @ code
 * replaceValues ( ) } methods throw an { @ link IllegalArgumentException } .
 * < p > When methods such as { @ code removeAll ( ) } and { @ code clear ( ) } are called on the filtered
 * multimap or its views , only mappings whose keys satisfy the filter will be removed from the
 * underlying multimap .
 * < p > The returned multimap isn ' t threadsafe or serializable , even if { @ code unfiltered } is .
 * < p > Many of the filtered multimap ' s methods , such as { @ code size ( ) } , iterate across every
 * key / value mapping in the underlying multimap and determine which satisfy the filter . When a
 * live view is < i > not < / i > needed , it may be faster to copy the filtered multimap and use the
 * copy .
 * < p > < b > Warning : < / b > { @ code keyPredicate } must be < i > consistent with equals < / i > , as documented at
 * { @ link Predicate # apply } . Do not provide a predicate such as { @ code
 * Predicates . instanceOf ( ArrayList . class ) } , which is inconsistent with equals .
 * @ since 11.0 */
public static < K , V > Multimap < K , V > filterKeys ( Multimap < K , V > unfiltered , final Predicate < ? super K > keyPredicate ) { } }

implementation: if ( unfiltered instanceof SetMultimap ) { return filterKeys ( ( SetMultimap < K , V > ) unfiltered , keyPredicate ) ; } else if ( unfiltered instanceof ListMultimap ) { return filterKeys ( ( ListMultimap < K , V > ) unfiltered , keyPredicate ) ; } else if ( unfiltered instanceof FilteredKeyMultimap ) { FilteredKeyMultimap < K , V > prev = ( FilteredKeyMultimap < K , V > ) unfiltered ; return new FilteredKeyMultimap < > ( prev . unfiltered , Predicates . < K > and ( prev . keyPredicate , keyPredicate ) ) ; } else if ( unfiltered instanceof FilteredMultimap ) { FilteredMultimap < K , V > prev = ( FilteredMultimap < K , V > ) unfiltered ; return filterFiltered ( prev , Maps . < K > keyPredicateOnEntries ( keyPredicate ) ) ; } else { return new FilteredKeyMultimap < > ( unfiltered , keyPredicate ) ; }


signature:
public class Multimaps { /** * Returns a multimap containing the mappings in { @ code unfiltered } whose keys satisfy a
 * predicate . The returned multimap is a live view of { @ code unfiltered } ; changes to one affect
 * the other .
 * < p > The resulting multimap ' s views have iterators that don ' t support { @ code remove ( ) } , but all
 * other methods are supported by the multimap and its views . When adding a key that doesn ' t
 * satisfy the predicate , the multimap ' s { @ code put ( ) } , { @ code putAll ( ) } , and { @ code
 * replaceValues ( ) } methods throw an { @ link IllegalArgumentException } .
 * < p > When methods such as { @ code removeAll ( ) } and { @ code clear ( ) } are called on the filtered
 * multimap or its views , only mappings whose keys satisfy the filter will be removed from the
 * underlying multimap .
 * < p > The returned multimap isn ' t threadsafe or serializable , even if { @ code unfiltered } is .
 * < p > Many of the filtered multimap ' s methods , such as { @ code size ( ) } , iterate across every
 * key / value mapping in the underlying multimap and determine which satisfy the filter . When a
 * live view is < i > not < / i > needed , it may be faster to copy the filtered multimap and use the
 * copy .
 * < p > < b > Warning : < / b > { @ code keyPredicate } must be < i > consistent with equals < / i > , as documented at
 * { @ link Predicate # apply } . Do not provide a predicate such as { @ code
 * Predicates . instanceOf ( ArrayList . class ) } , which is inconsistent with equals .
 * @ since 14.0 */
public static < K , V > SetMultimap < K , V > filterKeys ( SetMultimap < K , V > unfiltered , final Predicate < ? super K > keyPredicate ) { } }

implementation: if ( unfiltered instanceof FilteredKeySetMultimap ) { FilteredKeySetMultimap < K , V > prev = ( FilteredKeySetMultimap < K , V > ) unfiltered ; return new FilteredKeySetMultimap < > ( prev . unfiltered ( ) , Predicates . < K > and ( prev . keyPredicate , keyPredicate ) ) ; } else if ( unfiltered instanceof FilteredSetMultimap ) { FilteredSetMultimap < K , V > prev = ( FilteredSetMultimap < K , V > ) unfiltered ; return filterFiltered ( prev , Maps . < K > keyPredicateOnEntries ( keyPredicate ) ) ; } else { return new FilteredKeySetMultimap < > ( unfiltered , keyPredicate ) ; }


signature:
public class Multimaps { /** * Returns a multimap containing the mappings in { @ code unfiltered } whose keys satisfy a
 * predicate . The returned multimap is a live view of { @ code unfiltered } ; changes to one affect
 * the other .
 * < p > The resulting multimap ' s views have iterators that don ' t support { @ code remove ( ) } , but all
 * other methods are supported by the multimap and its views . When adding a key that doesn ' t
 * satisfy the predicate , the multimap ' s { @ code put ( ) } , { @ code putAll ( ) } , and { @ code
 * replaceValues ( ) } methods throw an { @ link IllegalArgumentException } .
 * < p > When methods such as { @ code removeAll ( ) } and { @ code clear ( ) } are called on the filtered
 * multimap or its views , only mappings whose keys satisfy the filter will be removed from the
 * underlying multimap .
 * < p > The returned multimap isn ' t threadsafe or serializable , even if { @ code unfiltered } is .
 * < p > Many of the filtered multimap ' s methods , such as { @ code size ( ) } , iterate across every
 * key / value mapping in the underlying multimap and determine which satisfy the filter . When a
 * live view is < i > not < / i > needed , it may be faster to copy the filtered multimap and use the
 * copy .
 * < p > < b > Warning : < / b > { @ code keyPredicate } must be < i > consistent with equals < / i > , as documented at
 * { @ link Predicate # apply } . Do not provide a predicate such as { @ code
 * Predicates . instanceOf ( ArrayList . class ) } , which is inconsistent with equals .
 * @ since 14.0 */
public static < K , V > ListMultimap < K , V > filterKeys ( ListMultimap < K , V > unfiltered , final Predicate < ? super K > keyPredicate ) { } }

implementation: if ( unfiltered instanceof FilteredKeyListMultimap ) { FilteredKeyListMultimap < K , V > prev = ( FilteredKeyListMultimap < K , V > ) unfiltered ; return new FilteredKeyListMultimap < > ( prev . unfiltered ( ) , Predicates . < K > and ( prev . keyPredicate , keyPredicate ) ) ; } else { return new FilteredKeyListMultimap < > ( unfiltered , keyPredicate ) ; }


signature:
public class Multimaps { /** * Returns a multimap containing the mappings in { @ code unfiltered } that satisfy a predicate . The
 * returned multimap is a live view of { @ code unfiltered } ; changes to one affect the other .
 * < p > The resulting multimap ' s views have iterators that don ' t support { @ code remove ( ) } , but all
 * other methods are supported by the multimap and its views . When adding a key / value pair that
 * doesn ' t satisfy the predicate , multimap ' s { @ code put ( ) } , { @ code putAll ( ) } , and { @ code
 * replaceValues ( ) } methods throw an { @ link IllegalArgumentException } .
 * < p > When methods such as { @ code removeAll ( ) } and { @ code clear ( ) } are called on the filtered
 * multimap or its views , only mappings whose keys satisfy the filter will be removed from the
 * underlying multimap .
 * < p > The returned multimap isn ' t threadsafe or serializable , even if { @ code unfiltered } is .
 * < p > Many of the filtered multimap ' s methods , such as { @ code size ( ) } , iterate across every
 * key / value mapping in the underlying multimap and determine which satisfy the filter . When a
 * live view is < i > not < / i > needed , it may be faster to copy the filtered multimap and use the
 * copy .
 * < p > < b > Warning : < / b > { @ code entryPredicate } must be < i > consistent with equals < / i > , as documented
 * at { @ link Predicate # apply } .
 * @ since 11.0 */
public static < K , V > Multimap < K , V > filterEntries ( Multimap < K , V > unfiltered , Predicate < ? super Entry < K , V > > entryPredicate ) { } }

implementation: checkNotNull ( entryPredicate ) ; if ( unfiltered instanceof SetMultimap ) { return filterEntries ( ( SetMultimap < K , V > ) unfiltered , entryPredicate ) ; } return ( unfiltered instanceof FilteredMultimap ) ? filterFiltered ( ( FilteredMultimap < K , V > ) unfiltered , entryPredicate ) : new FilteredEntryMultimap < K , V > ( checkNotNull ( unfiltered ) , entryPredicate ) ;


signature:
public class Multimaps { /** * Returns a multimap containing the mappings in { @ code unfiltered } that satisfy a predicate . The
 * returned multimap is a live view of { @ code unfiltered } ; changes to one affect the other .
 * < p > The resulting multimap ' s views have iterators that don ' t support { @ code remove ( ) } , but all
 * other methods are supported by the multimap and its views . When adding a key / value pair that
 * doesn ' t satisfy the predicate , multimap ' s { @ code put ( ) } , { @ code putAll ( ) } , and { @ code
 * replaceValues ( ) } methods throw an { @ link IllegalArgumentException } .
 * < p > When methods such as { @ code removeAll ( ) } and { @ code clear ( ) } are called on the filtered
 * multimap or its views , only mappings whose keys satisfy the filter will be removed from the
 * underlying multimap .
 * < p > The returned multimap isn ' t threadsafe or serializable , even if { @ code unfiltered } is .
 * < p > Many of the filtered multimap ' s methods , such as { @ code size ( ) } , iterate across every
 * key / value mapping in the underlying multimap and determine which satisfy the filter . When a
 * live view is < i > not < / i > needed , it may be faster to copy the filtered multimap and use the
 * copy .
 * < p > < b > Warning : < / b > { @ code entryPredicate } must be < i > consistent with equals < / i > , as documented
 * at { @ link Predicate # apply } .
 * @ since 14.0 */
public static < K , V > SetMultimap < K , V > filterEntries ( SetMultimap < K , V > unfiltered , Predicate < ? super Entry < K , V > > entryPredicate ) { } }

implementation: checkNotNull ( entryPredicate ) ; return ( unfiltered instanceof FilteredSetMultimap ) ? filterFiltered ( ( FilteredSetMultimap < K , V > ) unfiltered , entryPredicate ) : new FilteredEntrySetMultimap < K , V > ( checkNotNull ( unfiltered ) , entryPredicate ) ;


signature:
public class ImmutableSortedMultiset { /** * Returns a { @ code Collector } that accumulates the input elements into a new { @ code
 * ImmutableMultiset } . Elements are sorted by the specified comparator .
 * < p > < b > Warning : < / b > { @ code comparator } should be < i > consistent with { @ code equals } < / i > as
 * explained in the { @ link Comparator } documentation .
 * @ since 21.0 */
public static < E > Collector < E , ? , ImmutableSortedMultiset < E > > toImmutableSortedMultiset ( Comparator < ? super E > comparator ) { } }

implementation: return toImmutableSortedMultiset ( comparator , Function . identity ( ) , e -> 1 ) ;


signature:
public class ImmutableSortedMultiset { /** * Returns a { @ code Collector } that accumulates elements into an { @ code ImmutableSortedMultiset }
 * whose elements are the result of applying { @ code elementFunction } to the inputs , with counts
 * equal to the result of applying { @ code countFunction } to the inputs .
 * < p > If the mapped elements contain duplicates ( according to { @ code comparator } ) , the first
 * occurrence in encounter order appears in the resulting multiset , with count equal to the sum of
 * the outputs of { @ code countFunction . applyAsInt ( t ) } for each { @ code t } mapped to that element .
 * @ since 22.0 */
public static < T , E > Collector < T , ? , ImmutableSortedMultiset < E > > toImmutableSortedMultiset ( Comparator < ? super E > comparator , Function < ? super T , ? extends E > elementFunction , ToIntFunction < ? super T > countFunction ) { } }

implementation: checkNotNull ( comparator ) ; checkNotNull ( elementFunction ) ; checkNotNull ( countFunction ) ; return Collector . of ( ( ) -> TreeMultiset . create ( comparator ) , ( multiset , t ) -> multiset . add ( checkNotNull ( elementFunction . apply ( t ) ) , countFunction . applyAsInt ( t ) ) , ( multiset1 , multiset2 ) -> { multiset1 . addAll ( multiset2 ) ; return multiset1 ; } , ( Multiset < E > multiset ) -> copyOfSortedEntries ( comparator , multiset . entrySet ( ) ) ) ;


signature:
public class ImmutableSortedMultiset { /** * Returns an immutable sorted multiset containing the given elements sorted by the given { @ code
 * Comparator } . This method iterates over { @ code elements } at most once .
 * < p > Despite the method name , this method attempts to avoid actually copying the data when it is
 * safe to do so . The exact circumstances under which a copy will or will not be performed are
 * undocumented and subject to change .
 * @ throws NullPointerException if { @ code comparator } or any of { @ code elements } is null */
public static < E > ImmutableSortedMultiset < E > copyOf ( Comparator < ? super E > comparator , Iterable < ? extends E > elements ) { } }

implementation:
if ( elements instanceof ImmutableSortedMultiset ) { @ SuppressWarnings ( "unchecked" ) // immutable collections are always safe for covariant casts
ImmutableSortedMultiset < E > multiset = ( ImmutableSortedMultiset < E > ) elements ; if ( comparator . equals ( multiset . comparator ( ) ) ) { if ( multiset . isPartialView ( ) ) { return copyOfSortedEntries ( comparator , multiset . entrySet ( ) . asList ( ) ) ; } else { return multiset ; } } } elements = Lists . newArrayList ( elements ) ; // defensive copy
TreeMultiset < E > sortedCopy = TreeMultiset . create ( checkNotNull ( comparator ) ) ; Iterables . addAll ( sortedCopy , elements ) ; return copyOfSortedEntries ( comparator , sortedCopy . entrySet ( ) ) ;


signature:
public class TypeVisitor { /** * Visits the given types . Null types are ignored . This allows subclasses to call { @ code
 * visit ( parameterizedType . getOwnerType ( ) ) } safely without having to check nulls . */
public final void visit ( Type ... types ) { } }

implementation:
for ( Type type : types ) { if ( type == null || ! visited . add ( type ) ) { // null owner type , or already visited ;
continue ; } boolean succeeded = false ; try { if ( type instanceof TypeVariable ) { visitTypeVariable ( ( TypeVariable < ? > ) type ) ; } else if ( type instanceof WildcardType ) { visitWildcardType ( ( WildcardType ) type ) ; } else if ( type instanceof ParameterizedType ) { visitParameterizedType ( ( ParameterizedType ) type ) ; } else if ( type instanceof Class ) { visitClass ( ( Class < ? > ) type ) ; } else if ( type instanceof GenericArrayType ) { visitGenericArrayType ( ( GenericArrayType ) type ) ; } else { throw new AssertionError ( "Unknown type: " + type ) ; } succeeded = true ; } finally { if ( ! succeeded ) { // When the visitation failed , we don ' t want to ignore the second .
visited . remove ( type ) ; } } }


signature:
public class UnsignedBytes { /** * Returns the least value present in { @ code array } .
 * @ param array a < i > nonempty < / i > array of { @ code byte } values
 * @ return the value present in { @ code array } that is less than or equal to every other value in
 * the array
 * @ throws IllegalArgumentException if { @ code array } is empty */
public static byte min ( byte ... array ) { } }

implementation: checkArgument ( array . length > 0 ) ; int min = toInt ( array [ 0 ] ) ; for ( int i = 1 ; i < array . length ; i ++ ) { int next = toInt ( array [ i ] ) ; if ( next < min ) { min = next ; } } return ( byte ) min ;


signature:
public class UnsignedBytes { /** * Returns the greatest value present in { @ code array } .
 * @ param array a < i > nonempty < / i > array of { @ code byte } values
 * @ return the value present in { @ code array } that is greater than or equal to every other value
 * in the array
 * @ throws IllegalArgumentException if { @ code array } is empty */
public static byte max ( byte ... array ) { } }

implementation: checkArgument ( array . length > 0 ) ; int max = toInt ( array [ 0 ] ) ; for ( int i = 1 ; i < array . length ; i ++ ) { int next = toInt ( array [ i ] ) ; if ( next > max ) { max = next ; } } return ( byte ) max ;


signature:
public class UnsignedBytes { /** * Returns the unsigned { @ code byte } value represented by a string with the given radix .
 * @ param string the string containing the unsigned { @ code byte } representation to be parsed .
 * @ param radix the radix to use while parsing { @ code string }
 * @ throws NumberFormatException if the string does not contain a valid unsigned { @ code byte } with
 * the given radix , or if { @ code radix } is not between { @ link Character # MIN _ RADIX } and { @ link
 * Character # MAX _ RADIX } .
 * @ throws NullPointerException if { @ code string } is null ( in contrast to { @ link
 * Byte # parseByte ( String ) } )
 * @ since 13.0 */
@ Beta @ CanIgnoreReturnValue public static byte parseUnsignedByte ( String string , int radix ) { } }

implementation:
int parse = Integer . parseInt ( checkNotNull ( string ) , radix ) ; // We need to throw a NumberFormatException , so we have to duplicate checkedCast . = (
if ( parse >> Byte . SIZE == 0 ) { return ( byte ) parse ; } else { throw new NumberFormatException ( "out of range: " + parse ) ; }


signature:
public class AbstractByteHasher { /** * Updates this hasher with { @ code len } bytes starting at { @ code off } in the given buffer . */
protected void update ( byte [ ] b , int off , int len ) { } }

implementation: for ( int i = off ; i < off + len ; i ++ ) { update ( b [ i ] ) ; }


signature:
public class AbstractByteHasher { /** * Updates this hasher with bytes from the given buffer . */
protected void update ( ByteBuffer b ) { } }

implementation: if ( b . hasArray ( ) ) { update ( b . array ( ) , b . arrayOffset ( ) + b . position ( ) , b . remaining ( ) ) ; b . position ( b . limit ( ) ) ; } else { for ( int remaining = b . remaining ( ) ; remaining > 0 ; remaining -- ) { update ( b . get ( ) ) ; } }


signature:
public class ImmutableSortedSet { /** * Assumes that delegate doesn ' t have null elements and comparator . */
static < E > ImmutableSortedSet < E > unsafeDelegateSortedSet ( SortedSet < E > delegate , boolean isSubset ) { } }

implementation: return delegate . isEmpty ( ) ? emptySet ( delegate . comparator ( ) ) : new RegularImmutableSortedSet < E > ( delegate , isSubset ) ;


signature:
public class ImmutableSetMultimap_CustomFieldSerializer { /** * Serialization type safety is at the caller ' s mercy . */
@ SuppressWarnings ( "unchecked" ) public static ImmutableSetMultimap < Object , Object > instantiate ( SerializationStreamReader reader ) throws SerializationException { } }

implementation: Comparator < Object > valueComparator = ( Comparator < Object > ) reader . readObject ( ) ; ImmutableSetMultimap . Builder < Object , Object > builder = ImmutableSetMultimap . builder ( ) ; if ( valueComparator != null ) { builder . orderValuesBy ( valueComparator ) ; } return ( ImmutableSetMultimap < Object , Object > ) Multimap_CustomFieldSerializerBase . instantiate ( reader , builder ) ;


signature:
public class AtomicLongMap { /** * Returns the value associated with { @ code key } , or zero if there is no value associated with
 * { @ code key } . */
public long get ( K key ) { } }

implementation: AtomicLong atomic = map . get ( key ) ; return atomic == null ? 0L : atomic . get ( ) ;


signature:
public class AtomicLongMap { /** * If { @ code ( key , value ) } is currently in the map , this method removes it and returns true ;
 * otherwise , this method returns false . */
boolean remove ( K key , long value ) { } }

implementation:
AtomicLong atomic = map . get ( key ) ; if ( atomic == null ) { return false ; } long oldValue = atomic . get ( ) ; if ( oldValue != value ) { return false ; } if ( oldValue == 0L || atomic . compareAndSet ( oldValue , 0L ) ) { // only remove after setting to zero , to avoid concurrent updates
map . remove ( key , atomic ) ; // succeed even if the remove fails , since the value was already adjusted
return true ; } // value changed
return false ;


signature:
public class AtomicLongMap { /** * Returns the sum of all values in this map .
 * < p > This method is not atomic : the sum may or may not include other concurrent operations . */
public long sum ( ) { } }

implementation: long sum = 0L ; for ( AtomicLong value : map . values ( ) ) { sum = sum + value . get ( ) ; } return sum ;


signature:
public class AtomicLongMap { /** * If { @ code ( key , expectedOldValue ) } is currently in the map , this method replaces { @ code
 * expectedOldValue } with { @ code newValue } and returns true ; otherwise , this method returns false .
 * < p > If { @ code expectedOldValue } is zero , this method will succeed if { @ code ( key , zero ) } is
 * currently in the map , or if { @ code key } is not in the map at all . */
boolean replace ( K key , long expectedOldValue , long newValue ) { } }

implementation: if ( expectedOldValue == 0L ) { return putIfAbsent ( key , newValue ) == 0L ; } else { AtomicLong atomic = map . get ( key ) ; return ( atomic == null ) ? false : atomic . compareAndSet ( expectedOldValue , newValue ) ; }


signature:
public class FinalizableReferenceQueue { /** * Iterates through the given loaders until it finds one that can load Finalizer .
 * @ return Finalizer . class */
private static Class < ? > loadFinalizer ( FinalizerLoader ... loaders ) { } }

implementation: for ( FinalizerLoader loader : loaders ) { Class < ? > finalizer = loader . loadFinalizer ( ) ; if ( finalizer != null ) { return finalizer ; } } throw new AssertionError ( ) ;


signature:
public class FinalizableReferenceQueue { /** * Looks up Finalizer . startFinalizer ( ) . */
static Method getStartFinalizer ( Class < ? > finalizer ) { } }

implementation: try { return finalizer . getMethod ( "startFinalizer" , Class . class , ReferenceQueue . class , PhantomReference . class ) ; } catch ( NoSuchMethodException e ) { throw new AssertionError ( e ) ; }


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # lower } in terms of the { @ code descendingIterator } method of
 * { @ link # headSet ( Object , boolean ) } . If you override { @ link # headSet ( Object , boolean ) } , you may
 * wish to override { @ link # lower } to forward to this implementation . */
protected E standardLower ( E e ) { } }

implementation: return Iterators . getNext ( headSet ( e , false ) . descendingIterator ( ) , null ) ;


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # floor } in terms of the { @ code descendingIterator } method of
 * { @ link # headSet ( Object , boolean ) } . If you override { @ link # headSet ( Object , boolean ) } , you may
 * wish to override { @ link # floor } to forward to this implementation . */
protected E standardFloor ( E e ) { } }

implementation: return Iterators . getNext ( headSet ( e , true ) . descendingIterator ( ) , null ) ;


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # ceiling } in terms of the { @ code iterator } method of { @ link
 * # tailSet ( Object , boolean ) } . If you override { @ link # tailSet ( Object , boolean ) } , you may wish to
 * override { @ link # ceiling } to forward to this implementation . */
protected E standardCeiling ( E e ) { } }

implementation: return Iterators . getNext ( tailSet ( e , true ) . iterator ( ) , null ) ;


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # higher } in terms of the { @ code iterator } method of { @ link
 * # tailSet ( Object , boolean ) } . If you override { @ link # tailSet ( Object , boolean ) } , you may wish to
 * override { @ link # higher } to forward to this implementation . */
protected E standardHigher ( E e ) { } }

implementation: return Iterators . getNext ( tailSet ( e , false ) . iterator ( ) , null ) ;


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # subSet ( Object , boolean , Object , boolean ) } in terms of the
 * { @ code headSet } and { @ code tailSet } methods . In many cases , you may wish to override { @ link
 * # subSet ( Object , boolean , Object , boolean ) } to forward to this implementation . */
@ Beta protected NavigableSet < E > standardSubSet ( E fromElement , boolean fromInclusive , E toElement , boolean toInclusive ) { } }

implementation: return tailSet ( fromElement , fromInclusive ) . headSet ( toElement , toInclusive ) ;


signature:
public class ForwardingNavigableSet { /** * A sensible definition of { @ link # subSet ( Object , Object ) } in terms of the { @ link # subSet ( Object ,
 * boolean , Object , boolean ) } method . If you override { @ link # subSet ( Object , boolean , Object ,
 * boolean ) } , you may wish to override { @ link # subSet ( Object , Object ) } to forward to this
 * implementation . */
@ Override protected SortedSet < E > standardSubSet ( E fromElement , E toElement ) { } }

implementation: return subSet ( fromElement , true , toElement , false ) ;


signature:
public class BloomFilter { /** * Creates a new { @ code BloomFilter } that ' s a copy of this instance . The new instance is equal to
 * this instance but shares no mutable state .
 * @ since 12.0 */
public BloomFilter < T > copy ( ) { } }

implementation: return new BloomFilter < T > ( bits . copy ( ) , numHashFunctions , funnel , strategy ) ;


signature:
public class BloomFilter { /** * Puts an element into this { @ code BloomFilter } . Ensures that subsequent invocations of { @ link
 * # mightContain ( Object ) } with the same element will always return { @ code true } .
 * @ return true if the Bloom filter ' s bits changed as a result of this operation . If the bits
 * changed , this is < i > definitely < / i > the first time { @ code object } has been added to the
 * filter . If the bits haven ' t changed , this < i > might < / i > be the first time { @ code object } has
 * been added to the filter . Note that { @ code put ( t ) } always returns the < i > opposite < / i >
 * result to what { @ code mightContain ( t ) } would have returned at the time it is called .
 * @ since 12.0 ( present in 11.0 with { @ code void } return type } ) */
@ CanIgnoreReturnValue public boolean put ( T object ) { } }

implementation: return strategy . put ( object , funnel , numHashFunctions , bits ) ;


signature:
public class BloomFilter { /** * Combines this Bloom filter with another Bloom filter by performing a bitwise OR of the
 * underlying data . The mutations happen to < b > this < / b > instance . Callers must ensure the Bloom
 * filters are appropriately sized to avoid saturating them .
 * @ param that The Bloom filter to combine this Bloom filter with . It is not mutated .
 * @ throws IllegalArgumentException if { @ code isCompatible ( that ) = = false }
 * @ since 15.0 */
public void putAll ( BloomFilter < T > that ) { } }

implementation: checkNotNull ( that ) ; checkArgument ( this != that , "Cannot combine a BloomFilter with itself." ) ; checkArgument ( this . numHashFunctions == that . numHashFunctions , "BloomFilters must have the same number of hash functions (%s != %s)" , this . numHashFunctions , that . numHashFunctions ) ; checkArgument ( this . bitSize ( ) == that . bitSize ( ) , "BloomFilters must have the same size underlying bit arrays (%s != %s)" , this . bitSize ( ) , that . bitSize ( ) ) ; checkArgument ( this . strategy . equals ( that . strategy ) , "BloomFilters must have equal strategies (%s != %s)" , this . strategy , that . strategy ) ; checkArgument ( this . funnel . equals ( that . funnel ) , "BloomFilters must have equal funnels (%s != %s)" , this . funnel , that . funnel ) ; this . bits . putAll ( that . bits ) ;


signature:
public class BloomFilter { /** * Creates a { @ link BloomFilter } with the expected number of insertions and expected false
 * positive probability .
 * < p > Note that overflowing a { @ code BloomFilter } with significantly more elements than specified ,
 * will result in its saturation , and a sharp deterioration of its false positive probability .
 * < p > The constructed { @ code BloomFilter } will be serializable if the provided { @ code Funnel < T > }
 * is .
 * < p > It is recommended that the funnel be implemented as a Java enum . This has the benefit of
 * ensuring proper serialization and deserialization , which is important since { @ link # equals }
 * also relies on object identity of funnels .
 * @ param funnel the funnel of T ' s that the constructed { @ code BloomFilter } will use
 * @ param expectedInsertions the number of expected insertions to the constructed { @ code
 * BloomFilter } ; must be positive
 * @ param fpp the desired false positive probability ( must be positive and less than 1.0)
 * @ return a { @ code BloomFilter } */
public static < T > BloomFilter < T > create ( Funnel < ? super T > funnel , int expectedInsertions , double fpp ) { } }

implementation: return create ( funnel , ( long ) expectedInsertions , fpp ) ;


signature:
public class BloomFilter { /** * Creates a { @ link BloomFilter } with the expected number of insertions and expected false
 * positive probability .
 * < p > Note that overflowing a { @ code BloomFilter } with significantly more elements than specified ,
 * will result in its saturation , and a sharp deterioration of its false positive probability .
 * < p > The constructed { @ code BloomFilter } will be serializable if the provided { @ code Funnel < T > }
 * is .
 * < p > It is recommended that the funnel be implemented as a Java enum . This has the benefit of
 * ensuring proper serialization and deserialization , which is important since { @ link # equals }
 * also relies on object identity of funnels .
 * @ param funnel the funnel of T ' s that the constructed { @ code BloomFilter } will use
 * @ param expectedInsertions the number of expected insertions to the constructed { @ code
 * BloomFilter } ; must be positive
 * @ param fpp the desired false positive probability ( must be positive and less than 1.0)
 * @ return a { @ code BloomFilter }
 * @ since 19.0 */
public static < T > BloomFilter < T > create ( Funnel < ? super T > funnel , long expectedInsertions , double fpp ) { } }

implementation: return create ( funnel , expectedInsertions , fpp , BloomFilterStrategies . MURMUR128_MITZ_64 ) ;


signature:
public class BloomFilter { /** * Reads a byte stream , which was written by { @ linkplain # writeTo ( OutputStream ) } , into a { @ code
 * BloomFilter } .
 * < p > The { @ code Funnel } to be used is not encoded in the stream , so it must be provided here .
 * < b > Warning : < / b > the funnel provided < b > must < / b > behave identically to the one used to populate
 * the original Bloom filter !
 * @ throws IOException if the InputStream throws an { @ code IOException } , or if its data does not
 * appear to be a BloomFilter serialized using the { @ linkplain # writeTo ( OutputStream ) } method . */
public static < T > BloomFilter < T > readFrom ( InputStream in , Funnel < ? super T > funnel ) throws IOException { } }

implementation:
checkNotNull ( in , "InputStream" ) ; checkNotNull ( funnel , "Funnel" ) ; int strategyOrdinal = - 1 ; int numHashFunctions = - 1 ; int dataLength = - 1 ; try { DataInputStream din = new DataInputStream ( in ) ; // currently this assumes there is no negative ordinal ; will have to be updated if we
// add non - stateless strategies ( for which we ' ve reserved negative ordinals ; see
// Strategy . ordinal ( ) ) .
strategyOrdinal = din . readByte ( ) ; numHashFunctions = UnsignedBytes . toInt ( din . readByte ( ) ) ; dataLength = din . readInt ( ) ; Strategy strategy = BloomFilterStrategies . values ( ) [ strategyOrdinal ] ; long [ ] data = new long [ dataLength ] ; for ( int i = 0 ; i < data . length ; i ++ ) { data [ i ] = din . readLong ( ) ; } return new BloomFilter < T > ( new LockFreeBitArray ( data ) , numHashFunctions , funnel , strategy ) ; } catch ( RuntimeException e ) { String message = "Unable to deserialize BloomFilter from InputStream." + " strategyOrdinal: " + strategyOrdinal + " numHashFunctions: " + numHashFunctions + " dataLength: " + dataLength ; throw new IOException ( message , e ) ; }


signature:
public class Subscriber { /** * Creates a { @ code Subscriber } for { @ code method } on { @ code listener } . */
static Subscriber create ( EventBus bus , Object listener , Method method ) { } }

implementation: return isDeclaredThreadSafe ( method ) ? new Subscriber ( bus , listener , method ) : new SynchronizedSubscriber ( bus , listener , method ) ;


signature:
public class Subscriber { /** * Dispatches { @ code event } to this subscriber using the proper executor . */
final void dispatchEvent ( final Object event ) { } }

implementation: executor . execute ( new Runnable ( ) { @ Override public void run ( ) { try { invokeSubscriberMethod ( event ) ; } catch ( InvocationTargetException e ) { bus . handleSubscriberException ( e . getCause ( ) , context ( event ) ) ; } } } ) ;


signature:
public class FileBackedOutputStream { /** * Calls { @ link # close } if not already closed , and then resets this object back to its initial
 * state , for reuse . If data was buffered to a file , it will be deleted .
 * @ throws IOException if an I / O error occurred while deleting the file buffer */
public synchronized void reset ( ) throws IOException { } }

implementation: try { close ( ) ; } finally { if ( memory == null ) { memory = new MemoryOutput ( ) ; } else { memory . reset ( ) ; } out = memory ; if ( file != null ) { File deleteMe = file ; file = null ; if ( ! deleteMe . delete ( ) ) { throw new IOException ( "Could not delete: " + deleteMe ) ; } } }


signature:
public class FileBackedOutputStream { /** * Checks if writing { @ code len } bytes would go over threshold , and switches to file buffering if
 * so . */
private void update ( int len ) throws IOException { } }

implementation:
if ( file == null && ( memory . getCount ( ) + len > fileThreshold ) ) { File temp = File . createTempFile ( "FileBackedOutputStream" , null ) ; if ( resetOnFinalize ) { // Finalizers are not guaranteed to be called on system shutdown ;
// this is insurance .
temp . deleteOnExit ( ) ; } FileOutputStream transfer = new FileOutputStream ( temp ) ; transfer . write ( memory . getBuffer ( ) , 0 , memory . getCount ( ) ) ; transfer . flush ( ) ; // We ' ve successfully transferred the data ; switch to writing to file
out = transfer ; file = temp ; memory = null ; }


signature:
public class ListenerCallQueue { /** * Adds a listener that will be called using the given executor when events are later { @ link
 * # enqueue enqueued } and { @ link # dispatch dispatched } . */
public void addListener ( L listener , Executor executor ) { } }

implementation: checkNotNull ( listener , "listener" ) ; checkNotNull ( executor , "executor" ) ; listeners . add ( new PerListenerQueue < > ( listener , executor ) ) ;


signature:
public class ListenerCallQueue { /** * Dispatches all events enqueued prior to this call , serially and in order , for every listener .
 * < p > Note : this method is idempotent and safe to call from any thread */
public void dispatch ( ) { } }

implementation:
// iterate by index to avoid concurrent modification exceptions
for ( int i = 0 ; i < listeners . size ( ) ; i ++ ) { listeners . get ( i ) . dispatch ( ) ; }


signature:
public class ImmutableNetwork { /** * Returns an immutable copy of { @ code network } . */
public static < N , E > ImmutableNetwork < N , E > copyOf ( Network < N , E > network ) { } }

implementation: return ( network instanceof ImmutableNetwork ) ? ( ImmutableNetwork < N , E > ) network : new ImmutableNetwork < N , E > ( network ) ;


signature:
public class ImmutableNetwork { /** * Simply returns its argument .
 * @ deprecated no need to use this */
@ Deprecated public static < N , E > ImmutableNetwork < N , E > copyOf ( ImmutableNetwork < N , E > network ) { } }

implementation: return checkNotNull ( network ) ;


signature:
public class Resources { /** * Returns a { @ link CharSource } that reads from the given URL using the given character set .
 * @ since 14.0 */
public static CharSource asCharSource ( URL url , Charset charset ) { } }

implementation: return asByteSource ( url ) . asCharSource ( charset ) ;


signature:
public class Resources { /** * Copies all bytes from a URL to an output stream .
 * @ param from the URL to read from
 * @ param to the output stream
 * @ throws IOException if an I / O error occurs */
public static void copy ( URL from , OutputStream to ) throws IOException { } }

implementation: asByteSource ( from ) . copyTo ( to ) ;


signature:
public class Resources { /** * Returns a { @ code URL } pointing to { @ code resourceName } if the resource is found using the
 * { @ linkplain Thread # getContextClassLoader ( ) context class loader } . In simple environments , the
 * context class loader will find resources from the class path . In environments where different
 * threads can have different class loaders , for example app servers , the context class loader
 * will typically have been set to an appropriate loader for the current thread .
 * < p > In the unusual case where the context class loader is null , the class loader that loaded
 * this class ( { @ code Resources } ) will be used instead .
 * @ throws IllegalArgumentException if the resource is not found */
@ CanIgnoreReturnValue // being used to check if a resource exists
// TODO ( cgdecker ) : maybe add a better way to check if a resource exists
// e . g . Optional < URL > tryGetResource or boolean resourceExists
public static URL getResource ( String resourceName ) { } }

implementation: ClassLoader loader = MoreObjects . firstNonNull ( Thread . currentThread ( ) . getContextClassLoader ( ) , Resources . class . getClassLoader ( ) ) ; URL url = loader . getResource ( resourceName ) ; checkArgument ( url != null , "resource %s not found." , resourceName ) ; return url ;


signature:
public class Resources { /** * Given a { @ code resourceName } that is relative to { @ code contextClass } , returns a { @ code URL }
 * pointing to the named resource .
 * @ throws IllegalArgumentException if the resource is not found */
public static URL getResource ( Class < ? > contextClass , String resourceName ) { } }

implementation: URL url = contextClass . getResource ( resourceName ) ; checkArgument ( url != null , "resource %s relative to %s not found." , resourceName , contextClass . getName ( ) ) ; return url ;


signature:
public class AbstractFuture { /** * Usually returns { @ code null } but , if this { @ code Future } has failed , may < i > optionally < / i >
 * return the cause of the failure . " Failure " means specifically " completed with an exception " ; it
 * does not include " was cancelled . " To be explicit : If this method returns a non - null value ,
 * then :
 * < ul >
 * < li > { @ code isDone ( ) } must return { @ code true }
 * < li > { @ code isCancelled ( ) } must return { @ code false }
 * < li > { @ code get ( ) } must not block , and it must throw an { @ code ExecutionException } with the
 * return value of this method as its cause
 * < / ul >
 * < p > This method is { @ code protected } so that classes like { @ code
 * com . google . common . util . concurrent . SettableFuture } do not expose it to their users as an
 * instance method . In the unlikely event that you need to call this method , call { @ link
 * InternalFutures # tryInternalFastPathGetFailure ( InternalFutureFailureAccess ) } .
 * @ since 27.0 */
@ Override @ NullableDecl protected final Throwable tryInternalFastPathGetFailure ( ) { } }

implementation: if ( this instanceof Trusted ) { Object obj = value ; if ( obj instanceof Failure ) { return ( ( Failure ) obj ) . exception ; } } return null ;


signature:
public class AbstractFuture { /** * If this future has been cancelled ( and possibly interrupted ) , cancels ( and possibly interrupts )
 * the given future ( if available ) . */
final void maybePropagateCancellationTo ( @ NullableDecl Future < ? > related ) { } }

implementation: if ( related != null & isCancelled ( ) ) { related . cancel ( wasInterrupted ( ) ) ; }


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

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


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

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


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

implementation: return values . isEmpty ( ) ? EMPTY : new ImmutableDoubleArray ( Doubles . toArray ( values ) ) ;


signature:
public class ImmutableDoubleArray { /** * 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 ImmutableDoubleArray copyOf ( Iterable < Double > values ) { } }

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


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

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


signature:
public class ImmutableDoubleArray { /** * Invokes { @ code consumer } for each value contained in this array , in order . */
public void forEach ( DoubleConsumer consumer ) { } }

implementation: checkNotNull ( consumer ) ; for ( int i = start ; i < end ; i ++ ) { consumer . accept ( array [ i ] ) ; }


signature:
public class Invokable { /** * Returns { @ link Invokable } of { @ code constructor } . */
public static < T > Invokable < T , T > from ( Constructor < T > constructor ) { } }

implementation: return new ConstructorInvokable < T > ( constructor ) ;


signature:
public class Invokable { /** * All subclasses are owned by us and we ' ll make sure to get the R type right . */
@ SuppressWarnings ( "unchecked" ) @ CanIgnoreReturnValue public final R invoke ( @ Nullable T receiver , Object ... args ) throws InvocationTargetException , IllegalAccessException { } }

implementation: return ( R ) invokeInternal ( receiver , checkNotNull ( args ) ) ;


signature:
public class Invokable { /** * Returns all declared parameters of this { @ code Invokable } . Note that if this is a constructor
 * of a non - static inner class , unlike { @ link Constructor # getParameterTypes } , the hidden { @ code
 * this } parameter of the enclosing class is excluded from the returned parameters . */
public final ImmutableList < Parameter > getParameters ( ) { } }

implementation: Type [ ] parameterTypes = getGenericParameterTypes ( ) ; Annotation [ ] [ ] annotations = getParameterAnnotations ( ) ; AnnotatedType [ ] annotatedTypes = getAnnotatedParameterTypes ( ) ; ImmutableList . Builder < Parameter > builder = ImmutableList . builder ( ) ; for ( int i = 0 ; i < parameterTypes . length ; i ++ ) { builder . add ( new Parameter ( this , i , TypeToken . of ( parameterTypes [ i ] ) , annotations [ i ] , annotatedTypes [ i ] ) ) ; } return builder . build ( ) ;


signature:
public class Invokable { /** * Returns all declared exception types of this { @ code Invokable } . */
public final ImmutableList < TypeToken < ? extends Throwable > > getExceptionTypes ( ) { } }

implementation:
ImmutableList . Builder < TypeToken < ? extends Throwable > > builder = ImmutableList . builder ( ) ; for ( Type type : getGenericExceptionTypes ( ) ) { // getGenericExceptionTypes ( ) will never return a type that ' s not exception
@ SuppressWarnings ( "unchecked" ) TypeToken < ? extends Throwable > exceptionType = ( TypeToken < ? extends Throwable > ) TypeToken . of ( type ) ; builder . add ( exceptionType ) ; } return builder . build ( ) ;


signature:
public class Invokable { /** * Explicitly specifies the return type of this { @ code Invokable } . For example :
 * < pre > { @ code
 * Method factoryMethod = Person . class . getMethod ( " create " ) ;
 * Invokable < ? , Person > factory = Invokable . of ( getNameMethod ) . returning ( Person . class ) ;
 * } < / pre > */
public final < R1 extends R > Invokable < T , R1 > returning ( Class < R1 > returnType ) { } }

implementation: return returning ( TypeToken . of ( returnType ) ) ;


signature:
public class Invokable { /** * Explicitly specifies the return type of this { @ code Invokable } . */
public final < R1 extends R > Invokable < T , R1 > returning ( TypeToken < R1 > returnType ) { } }

implementation:
if ( ! returnType . isSupertypeOf ( getReturnType ( ) ) ) { throw new IllegalArgumentException ( "Invokable is known to return " + getReturnType ( ) + ", not " + returnType ) ; } @ SuppressWarnings ( "unchecked" ) // guarded by previous check
Invokable < T , R1 > specialized = ( Invokable < T , R1 > ) this ; return specialized ;


signature:
public class Invokable { /** * Overridden in TypeToken # method ( ) and TypeToken # constructor ( ) */
@ SuppressWarnings ( "unchecked" ) // The declaring class is T .
@ Override public TypeToken < T > getOwnerType ( ) { } }

implementation: return ( TypeToken < T > ) TypeToken . of ( getDeclaringClass ( ) ) ;


signature:
public class EventBus { /** * Posts an event to all registered subscribers . This method will return successfully after the
 * event has been posted to all subscribers , and regardless of any exceptions thrown by
 * subscribers .
 * < p > If no subscribers have been subscribed for { @ code event } ' s class , and { @ code event } is not
 * already a { @ link DeadEvent } , it will be wrapped in a DeadEvent and reposted .
 * @ param event event to post . */
public void post ( Object event ) { } }

implementation:
Iterator < Subscriber > eventSubscribers = subscribers . getSubscribers ( event ) ; if ( eventSubscribers . hasNext ( ) ) { dispatcher . dispatch ( event , eventSubscribers ) ; } else if ( ! ( event instanceof DeadEvent ) ) { // the event had no subscribers and was not itself a DeadEvent
post ( new DeadEvent ( this , event ) ) ; }


signature:
public class ImmutableListMultimap { /** * Returns a { @ link Collector } that accumulates elements into an { @ code ImmutableListMultimap }
 * whose keys and values are the result of applying the provided mapping functions to the input
 * elements .
 * < p > For streams with { @ linkplain java . util . stream # Ordering defined encounter order } , that order
 * is preserved , but entries are < a href = " ImmutableMultimap . html # iteration " > grouped by key < / a > .
 * < p > Example :
 * < pre > { @ code
 * static final Multimap < Character , String > FIRST _ LETTER _ MULTIMAP =
 * Stream . of ( " banana " , " apple " , " carrot " , " asparagus " , " cherry " )
 * . collect ( toImmutableListMultimap ( str - > str . charAt ( 0 ) , str - > str . substring ( 1 ) ) ) ;
 * / / is equivalent to
 * static final Multimap < Character , String > FIRST _ LETTER _ MULTIMAP =
 * new ImmutableListMultimap . Builder < Character , String > ( )
 * . put ( ' b ' , " anana " )
 * . putAll ( ' a ' , " pple " , " sparagus " )
 * . putAll ( ' c ' , " arrot " , " herry " )
 * . build ( ) ;
 * } < / pre >
 * @ since 21.0 */
public static < T , K , V > Collector < T , ? , ImmutableListMultimap < K , V > > toImmutableListMultimap ( Function < ? super T , ? extends K > keyFunction , Function < ? super T , ? extends V > valueFunction ) { } }

implementation: checkNotNull ( keyFunction , "keyFunction" ) ; checkNotNull ( valueFunction , "valueFunction" ) ; return Collector . of ( ImmutableListMultimap :: < K , V > builder , ( builder , t ) -> builder . put ( keyFunction . apply ( t ) , valueFunction . apply ( t ) ) , ImmutableListMultimap . Builder :: combine , ImmutableListMultimap . Builder :: build ) ;


signature:
public class ImmutableListMultimap { /** * Returns a { @ code Collector } accumulating entries into an { @ code ImmutableListMultimap } . Each
 * input element is mapped to a key and a stream of values , each of which are put into the
 * resulting { @ code Multimap } , in the encounter order of the stream and the encounter order of the
 * streams of values .
 * < p > Example :
 * < pre > { @ code
 * static final ImmutableListMultimap < Character , Character > FIRST _ LETTER _ MULTIMAP =
 * Stream . of ( " banana " , " apple " , " carrot " , " asparagus " , " cherry " )
 * . collect (
 * flatteningToImmutableListMultimap (
 * str - > str . charAt ( 0 ) ,
 * str - > str . substring ( 1 ) . chars ( ) . mapToObj ( c - > ( char ) c ) ) ;
 * / / is equivalent to
 * static final ImmutableListMultimap < Character , Character > FIRST _ LETTER _ MULTIMAP =
 * ImmutableListMultimap . < Character , Character > builder ( )
 * . putAll ( ' b ' , Arrays . asList ( ' a ' , ' n ' , ' a ' , ' n ' , ' a ' ) )
 * . putAll ( ' a ' , Arrays . asList ( ' p ' , ' p ' , ' l ' , ' e ' ) )
 * . putAll ( ' c ' , Arrays . asList ( ' a ' , ' r ' , ' r ' , ' o ' , ' t ' ) )
 * . putAll ( ' a ' , Arrays . asList ( ' s ' , ' p ' , ' a ' , ' r ' , ' a ' , ' g ' , ' u ' , ' s ' ) )
 * . putAll ( ' c ' , Arrays . asList ( ' h ' , ' e ' , ' r ' , ' r ' , ' y ' ) )
 * . build ( ) ;
 * } < / pre >
 * @ since 21.0 */
public static < T , K , V > Collector < T , ? , ImmutableListMultimap < K , V > > flatteningToImmutableListMultimap ( Function < ? super T , ? extends K > keyFunction , Function < ? super T , ? extends Stream < ? extends V > > valuesFunction ) { } }

implementation: checkNotNull ( keyFunction ) ; checkNotNull ( valuesFunction ) ; return Collectors . collectingAndThen ( Multimaps . flatteningToMultimap ( input -> checkNotNull ( keyFunction . apply ( input ) ) , input -> valuesFunction . apply ( input ) . peek ( Preconditions :: checkNotNull ) , MultimapBuilder . linkedHashKeys ( ) . arrayListValues ( ) :: < K , V > build ) , ImmutableListMultimap :: copyOf ) ;


signature:
public class ImmutableListMultimap { /** * Casting is safe because the multimap will never hold any elements . */
@ SuppressWarnings ( "unchecked" ) public static < K , V > ImmutableListMultimap < K , V > of ( ) { } }

implementation: return ( ImmutableListMultimap < K , V > ) EmptyImmutableListMultimap . INSTANCE ;


signature:
public class ImmutableListMultimap { /** * Returns an immutable multimap containing a single entry . */
public static < K , V > ImmutableListMultimap < K , V > of ( K k1 , V v1 ) { } }

implementation: ImmutableListMultimap . Builder < K , V > builder = ImmutableListMultimap . builder ( ) ; builder . put ( k1 , v1 ) ; return builder . build ( ) ;


signature:
public class ImmutableListMultimap { /** * Returns an immutable multimap containing the same mappings as { @ code multimap } . The generated
 * multimap ' s key and value orderings correspond to the iteration ordering of the { @ code
 * multimap . asMap ( ) } view .
 * < p > Despite the method name , this method attempts to avoid actually copying the data when it is
 * safe to do so . The exact circumstances under which a copy will or will not be performed are
 * undocumented and subject to change .
 * @ throws NullPointerException if any key or value in { @ code multimap } is null */
public static < K , V > ImmutableListMultimap < K , V > copyOf ( Multimap < ? extends K , ? extends V > multimap ) { } }

implementation:
if ( multimap . isEmpty ( ) ) { return of ( ) ; } // TODO ( lowasser ) : copy ImmutableSetMultimap by using asList ( ) on the sets
if ( multimap instanceof ImmutableListMultimap ) { @ SuppressWarnings ( "unchecked" ) // safe since multimap is not writable
ImmutableListMultimap < K , V > kvMultimap = ( ImmutableListMultimap < K , V > ) multimap ; if ( ! kvMultimap . isPartialView ( ) ) { return kvMultimap ; } } return fromMapEntries ( multimap . asMap ( ) . entrySet ( ) , null ) ;


signature:
public class ImmutableListMultimap { /** * Returns an immutable multimap containing the specified entries . The returned multimap iterates
 * over keys in the order they were first encountered in the input , and the values for each key
 * are iterated in the order they were encountered .
 * @ throws NullPointerException if any key , value , or entry is null
 * @ since 19.0 */
@ Beta public static < K , V > ImmutableListMultimap < K , V > copyOf ( Iterable < ? extends Entry < ? extends K , ? extends V > > entries ) { } }

implementation: return new Builder < K , V > ( ) . putAll ( entries ) . build ( ) ;


signature:
public class ImmutableListMultimap { /** * { @ inheritDoc }
 * < p > Because an inverse of a list multimap can contain multiple pairs with the same key and
 * value , this method returns an { @ code ImmutableListMultimap } rather than the { @ code
 * ImmutableMultimap } specified in the { @ code ImmutableMultimap } class .
 * @ since 11.0 */
@ Override public ImmutableListMultimap < V , K > inverse ( ) { } }

implementation: ImmutableListMultimap < V , K > result = inverse ; return ( result == null ) ? ( inverse = invert ( ) ) : result ;


signature:
public class MapMaker { /** * Sets the minimum total size for the internal hash tables . For example , if the initial capacity
 * is { @ code 60 } , and the concurrency level is { @ code 8 } , then eight segments are created , each
 * having a hash table of size eight . Providing a large enough estimate at construction time
 * avoids the need for expensive resizing operations later , but setting this value unnecessarily
 * high wastes memory .
 * @ throws IllegalArgumentException if { @ code initialCapacity } is negative
 * @ throws IllegalStateException if an initial capacity was already set */
@ CanIgnoreReturnValue public MapMaker initialCapacity ( int initialCapacity ) { } }

implementation: checkState ( this . initialCapacity == UNSET_INT , "initial capacity was already set to %s" , this . initialCapacity ) ; checkArgument ( initialCapacity >= 0 ) ; this . initialCapacity = initialCapacity ; return this ;


signature:
public class MapMaker { /** * Guides the allowed concurrency among update operations . Used as a hint for internal sizing . The
 * table is internally partitioned to try to permit the indicated number of concurrent updates
 * without contention . Because assignment of entries to these partitions is not necessarily
 * uniform , the actual concurrency observed may vary . Ideally , you should choose a value to
 * accommodate as many threads as will ever concurrently modify the table . Using a significantly
 * higher value than you need can waste space and time , and a significantly lower value can lead
 * to thread contention . But overestimates and underestimates within an order of magnitude do not
 * usually have much noticeable impact . A value of one permits only one thread to modify the map
 * at a time , but since read operations can proceed concurrently , this still yields higher
 * concurrency than full synchronization . Defaults to 4.
 * < p > < b > Note : < / b > Prior to Guava release 9.0 , the default was 16 . It is possible the default will
 * change again in the future . If you care about this value , you should always choose it
 * explicitly .
 * @ throws IllegalArgumentException if { @ code concurrencyLevel } is nonpositive
 * @ throws IllegalStateException if a concurrency level was already set */
@ CanIgnoreReturnValue public MapMaker concurrencyLevel ( int concurrencyLevel ) { } }

implementation: checkState ( this . concurrencyLevel == UNSET_INT , "concurrency level was already set to %s" , this . concurrencyLevel ) ; checkArgument ( concurrencyLevel > 0 ) ; this . concurrencyLevel = concurrencyLevel ; return this ;


signature:
public class MapMaker { /** * Builds a thread - safe map . This method does not alter the state of this { @ code MapMaker }
 * instance , so it can be invoked again to create multiple independent maps .
 * < p > The bulk operations { @ code putAll } , { @ code equals } , and { @ code clear } are not guaranteed to
 * be performed atomically on the returned map . Additionally , { @ code size } and { @ code
 * containsValue } are implemented as bulk read operations , and thus may fail to observe concurrent
 * writes .
 * @ return a serializable concurrent map having the requested features */
public < K , V > ConcurrentMap < K , V > makeMap ( ) { } }

implementation: if ( ! useCustomMap ) { return new ConcurrentHashMap < > ( getInitialCapacity ( ) , 0.75f , getConcurrencyLevel ( ) ) ; } return MapMakerInternalMap . create ( this ) ;


signature:
public class AbstractBiMap { /** * Specifies the delegate maps going in each direction . Called by the constructor and by
 * subclasses during deserialization . */
void setDelegates ( Map < K , V > forward , Map < V , K > backward ) { } }

implementation: checkState ( delegate == null ) ; checkState ( inverse == null ) ; checkArgument ( forward . isEmpty ( ) ) ; checkArgument ( backward . isEmpty ( ) ) ; checkArgument ( forward != backward ) ; delegate = forward ; inverse = makeInverse ( backward ) ;


signature:
public class Predicates { /** * Returns a predicate that always evaluates to { @ code true } . */
@ GwtCompatible ( serializable = true ) public static < T > Predicate < T > alwaysTrue ( ) { } }

implementation: return ObjectPredicate . ALWAYS_TRUE . withNarrowedType ( ) ;


signature:
public class Predicates { /** * Returns a predicate that always evaluates to { @ code false } . */
@ GwtCompatible ( serializable = true ) public static < T > Predicate < T > alwaysFalse ( ) { } }

implementation: return ObjectPredicate . ALWAYS_FALSE . withNarrowedType ( ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if the object reference being tested is
 * null . */
@ GwtCompatible ( serializable = true ) public static < T > Predicate < T > isNull ( ) { } }

implementation: return ObjectPredicate . IS_NULL . withNarrowedType ( ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if the object reference being tested is not
 * null . */
@ GwtCompatible ( serializable = true ) public static < T > Predicate < T > notNull ( ) { } }

implementation: return ObjectPredicate . NOT_NULL . withNarrowedType ( ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if each of its components evaluates to
 * { @ code true } . The components are evaluated in order , and evaluation will be " short - circuited "
 * as soon as a false predicate is found . It defensively copies the iterable passed in , so future
 * changes to it won ' t alter the behavior of this predicate . If { @ code components } is empty , the
 * returned predicate will always evaluate to { @ code true } . */
public static < T > Predicate < T > and ( Iterable < ? extends Predicate < ? super T > > components ) { } }

implementation: return new AndPredicate < T > ( defensiveCopy ( components ) ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if both of its components evaluate to { @ code
 * true } . The components are evaluated in order , and evaluation will be " short - circuited " as soon
 * as a false predicate is found . */
public static < T > Predicate < T > and ( Predicate < ? super T > first , Predicate < ? super T > second ) { } }

implementation: return new AndPredicate < T > ( Predicates . < T > asList ( checkNotNull ( first ) , checkNotNull ( second ) ) ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if either of its components evaluates to
 * { @ code true } . The components are evaluated in order , and evaluation will be " short - circuited "
 * as soon as a true predicate is found . */
public static < T > Predicate < T > or ( Predicate < ? super T > first , Predicate < ? super T > second ) { } }

implementation: return new OrPredicate < T > ( Predicates . < T > asList ( checkNotNull ( first ) , checkNotNull ( second ) ) ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if the object being tested { @ code equals ( ) }
 * the given target or both are null . */
public static < T > Predicate < T > equalTo ( @ NullableDecl T target ) { } }

implementation: return ( target == null ) ? Predicates . < T > isNull ( ) : new IsEqualToPredicate < T > ( target ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if the object reference being tested is a
 * member of the given collection . It does not defensively copy the collection passed in , so
 * future changes to it will alter the behavior of the predicate .
 * < p > This method can technically accept any { @ code Collection < ? > } , but using a typed collection
 * helps prevent bugs . This approach doesn ' t block any potential users since it is always possible
 * to use { @ code Predicates . < Object > in ( ) } .
 * @ param target the collection that may contain the function input */
public static < T > Predicate < T > in ( Collection < ? extends T > target ) { } }

implementation: return new InPredicate < T > ( target ) ;


signature:
public class Predicates { /** * Returns a predicate that evaluates to { @ code true } if the { @ code CharSequence } being tested
 * contains any match for the given regular expression pattern . The test used is equivalent to
 * { @ code pattern . matcher ( arg ) . find ( ) }
 * @ since 3.0 */
@ GwtIncompatible ( value = "java.util.regex.Pattern" ) public static Predicate < CharSequence > contains ( Pattern pattern ) { } }

implementation: return new ContainsPatternPredicate ( new JdkPattern ( pattern ) ) ;


signature:
public class ArrayTable { /** * Creates an { @ code ArrayTable } with the mappings in the provided table .
 * < p > If { @ code table } includes a mapping with row key { @ code r } and a separate mapping with
 * column key { @ code c } , the returned table contains a mapping with row key { @ code r } and column
 * key { @ code c } . If that row key / column key pair in not in { @ code table } , the pair maps to
 * { @ code null } in the generated table .
 * < p > The returned table allows subsequent { @ code put } calls with the row keys in { @ code
 * table . rowKeySet ( ) } and the column keys in { @ code table . columnKeySet ( ) } . Calling { @ link # put }
 * with other keys leads to an { @ code IllegalArgumentException } .
 * < p > The ordering of { @ code table . rowKeySet ( ) } and { @ code table . columnKeySet ( ) } determines the
 * row and column iteration ordering of the returned table .
 * @ throws NullPointerException if { @ code table } has a null key */
public static < R , C , V > ArrayTable < R , C , V > create ( Table < R , C , V > table ) { } }

implementation: return ( table instanceof ArrayTable < ? , ? , ? > ) ? new ArrayTable < R , C , V > ( ( ArrayTable < R , C , V > ) table ) : new ArrayTable < R , C , V > ( table ) ;


signature:
public class ArrayTable { /** * Returns the value corresponding to the specified row and column indices . The same value is
 * returned by { @ code get ( rowKeyList ( ) . get ( rowIndex ) , columnKeyList ( ) . get ( columnIndex ) ) } , but this
 * method runs more quickly .
 * @ param rowIndex position of the row key in { @ link # rowKeyList ( ) }
 * @ param columnIndex position of the row key in { @ link # columnKeyList ( ) }
 * @ return the value with the specified row and column
 * @ throws IndexOutOfBoundsException if either index is negative , { @ code rowIndex } is greater than
 * or equal to the number of allowed row keys , or { @ code columnIndex } is greater than or equal
 * to the number of allowed column keys */
public V at ( int rowIndex , int columnIndex ) { } }

implementation:
// In GWT array access never throws IndexOutOfBoundsException .
checkElementIndex ( rowIndex , rowList . size ( ) ) ; checkElementIndex ( columnIndex , columnList . size ( ) ) ; return array [ rowIndex ] [ columnIndex ] ;


signature:
public class ArrayTable { /** * Associates { @ code value } with the specified row and column indices . The logic { @ code
 * put ( rowKeyList ( ) . get ( rowIndex ) , columnKeyList ( ) . get ( columnIndex ) , value ) } has the same
 * behavior , but this method runs more quickly .
 * @ param rowIndex position of the row key in { @ link # rowKeyList ( ) }
 * @ param columnIndex position of the row key in { @ link # columnKeyList ( ) }
 * @ param value value to store in the table
 * @ return the previous value with the specified row and column
 * @ throws IndexOutOfBoundsException if either index is negative , { @ code rowIndex } is greater than
 * or equal to the number of allowed row keys , or { @ code columnIndex } is greater than or equal
 * to the number of allowed column keys */
@ CanIgnoreReturnValue public V set ( int rowIndex , int columnIndex , @ Nullable V value ) { } }

implementation:
// In GWT array access never throws IndexOutOfBoundsException .
checkElementIndex ( rowIndex , rowList . size ( ) ) ; checkElementIndex ( columnIndex , columnList . size ( ) ) ; V oldValue = array [ rowIndex ] [ columnIndex ] ; array [ rowIndex ] [ columnIndex ] = value ; return oldValue ;


signature:
public class ArrayTable { /** * Returns a two - dimensional array with the table contents . The row and column indices correspond
 * to the positions of the row and column in the iterables provided during table construction . If
 * the table lacks a mapping for a given row and column , the corresponding array element is null .
 * < p > Subsequent table changes will not modify the array , and vice versa .
 * @ param valueClass class of values stored in the returned array */
@ GwtIncompatible // reflection
public V [ ] [ ] toArray ( Class < V > valueClass ) { } }

implementation:
@ SuppressWarnings ( "unchecked" ) // TODO : safe ?
V [ ] [ ] copy = ( V [ ] [ ] ) Array . newInstance ( valueClass , rowList . size ( ) , columnList . size ( ) ) ; for ( int i = 0 ; i < rowList . size ( ) ; i ++ ) { System . arraycopy ( array [ i ] , 0 , copy [ i ] , 0 , array [ i ] . length ) ; } return copy ;


signature:
public class ArrayTable { /** * Returns { @ code true } if the provided keys are among the keys provided when the table was
 * constructed . */
@ Override public boolean contains ( @ Nullable Object rowKey , @ Nullable Object columnKey ) { } }

implementation: return containsRow ( rowKey ) && containsColumn ( columnKey ) ;


signature:
public class ArrayTable { /** * Associates the value { @ code null } with the specified keys , assuming both keys are valid . If
 * either key is null or isn ' t among the keys provided during construction , this method has no
 * effect .
 * < p > This method is equivalent to { @ code put ( rowKey , columnKey , null ) } when both provided keys
 * are valid .
 * @ param rowKey row key of mapping to be erased
 * @ param columnKey column key of mapping to be erased
 * @ return the value previously associated with the keys , or { @ code null } if no mapping existed
 * for the keys */
@ CanIgnoreReturnValue public V erase ( @ Nullable Object rowKey , @ Nullable Object columnKey ) { } }

implementation: Integer rowIndex = rowKeyToIndex . get ( rowKey ) ; Integer columnIndex = columnKeyToIndex . get ( columnKey ) ; if ( rowIndex == null || columnIndex == null ) { return null ; } return set ( rowIndex , columnIndex , null ) ;


signature:
public class ArrayTable { /** * Returns a view of all mappings that have the given column key . If the column key isn ' t in
 * { @ link # columnKeySet ( ) } , an empty immutable map is returned .
 * < p > Otherwise , for each row key in { @ link # rowKeySet ( ) } , the returned map associates the row key
 * with the corresponding value in the table . Changes to the returned map will update the
 * underlying table , and vice versa .
 * @ param columnKey key of column to search for in the table
 * @ return the corresponding map from row keys to values */
@ Override public Map < R , V > column ( C columnKey ) { } }

implementation: checkNotNull ( columnKey ) ; Integer columnIndex = columnKeyToIndex . get ( columnKey ) ; return ( columnIndex == null ) ? ImmutableMap . < R , V > of ( ) : new Column ( columnIndex ) ;


signature:
public class ArrayTable { /** * Returns a view of all mappings that have the given row key . If the row key isn ' t in { @ link
 * # rowKeySet ( ) } , an empty immutable map is returned .
 * < p > Otherwise , for each column key in { @ link # columnKeySet ( ) } , the returned map associates the
 * column key with the corresponding value in the table . Changes to the returned map will update
 * the underlying table , and vice versa .
 * @ param rowKey key of row to search for in the table
 * @ return the corresponding map from column keys to values */
@ Override public Map < C , V > row ( R rowKey ) { } }

implementation: checkNotNull ( rowKey ) ; Integer rowIndex = rowKeyToIndex . get ( rowKey ) ; return ( rowIndex == null ) ? ImmutableMap . < C , V > of ( ) : new Row ( rowIndex ) ;


signature:
public class LittleEndianDataOutputStream { /** * Writes a { @ code long } as specified by { @ link DataOutputStream # writeLong ( long ) } , except using
 * little - endian byte order .
 * @ throws IOException if an I / O error occurs */
@ Override public void writeLong ( long v ) throws IOException { } }

implementation: byte [ ] bytes = Longs . toByteArray ( Long . reverseBytes ( v ) ) ; write ( bytes , 0 , bytes . length ) ;


signature:
public class LittleEndianDataOutputStream { /** * Writes a { @ code short } as specified by { @ link DataOutputStream # writeShort ( int ) } , except using
 * little - endian byte order .
 * @ throws IOException if an I / O error occurs */
@ Override public void writeShort ( int v ) throws IOException { } }

implementation: out . write ( 0xFF & v ) ; out . write ( 0xFF & ( v >> 8 ) ) ;


signature:
public class ConfigurableMutableValueGraph { /** * Adds { @ code node } to the graph and returns the associated { @ link GraphConnections } .
 * @ throws IllegalStateException if { @ code node } is already present */
@ CanIgnoreReturnValue private GraphConnections < N , V > addNodeInternal ( N node ) { } }

implementation: GraphConnections < N , V > connections = newConnections ( ) ; checkState ( nodeConnections . put ( node , connections ) == null ) ; return connections ;


signature:
public class SequentialExecutor { /** * Adds a task to the queue and makes sure a worker thread is running .
 * < p > If this method throws , e . g . a { @ code RejectedExecutionException } from the delegate executor ,
 * execution of tasks will stop until a call to this method or to { @ link # resume ( ) } is made . */
@ Override public void execute ( final Runnable task ) { } }

implementation:
checkNotNull ( task ) ; final Runnable submittedTask ; final long oldRunCount ; synchronized ( queue ) { // If the worker is already running ( or execute ( ) on the delegate returned successfully , and
// the worker has yet to start ) then we don ' t need to start the worker .
if ( workerRunningState == RUNNING || workerRunningState == QUEUED ) { queue . add ( task ) ; return ; } oldRunCount = workerRunCount ; // If the worker is not yet running , the delegate Executor might reject our attempt to start
// it . To preserve FIFO order and failure atomicity of rejected execution when the same
// Runnable is executed more than once , allocate a wrapper that we know is safe to remove by
// object identity .
// A data structure that returned a removal handle from add ( ) would allow eliminating this
// allocation .
submittedTask = new Runnable ( ) { @ Override public void run ( ) { task . run ( ) ; } } ; queue . add ( submittedTask ) ; workerRunningState = QUEUING ; } try { executor . execute ( worker ) ; } catch ( RuntimeException | Error t ) { synchronized ( queue ) { boolean removed = ( workerRunningState == IDLE || workerRunningState == QUEUING ) && queue . removeLastOccurrence ( submittedTask ) ; // If the delegate is directExecutor ( ) , the submitted runnable could have thrown a REE . But
// that ' s handled by the log check that catches RuntimeExceptions in the queue worker .
if ( ! ( t instanceof RejectedExecutionException ) || removed ) { throw t ; } } return ; } /* * This is an unsynchronized read ! After the read , the function returns immediately or acquires
 * the lock to check again . Since an IDLE state was observed inside the preceding synchronized
 * block , and reference field assignment is atomic , this may save reacquiring the lock when
 * another thread or the worker task has cleared the count and set the state .
 * < p > When { @ link # executor } is a directExecutor ( ) , the value written to
 * { @ code workerRunningState } will be available synchronously , and behaviour will be
 * deterministic . */
@ SuppressWarnings ( "GuardedBy" ) boolean alreadyMarkedQueued = workerRunningState != QUEUING ; if ( alreadyMarkedQueued ) { return ; } synchronized ( queue ) { if ( workerRunCount == oldRunCount && workerRunningState == QUEUING ) { workerRunningState = QUEUED ; } }


signature:
public class ArrayTable { /** * Returns { @ code true } if the provided keys are among the keys provided when the table was
 * constructed . */
@ Override public boolean contains ( @ NullableDecl Object rowKey , @ NullableDecl Object columnKey ) { } }


signature:
public class ArrayTable { /** * { @ inheritDoc }
 * @ throws IllegalArgumentException if { @ code rowKey } is not in { @ link # rowKeySet ( ) } or { @ code
 * columnKey } is not in { @ link # columnKeySet ( ) } . */
@ CanIgnoreReturnValue @ Override public V put ( R rowKey , C columnKey , @ NullableDecl V value ) { } }

implementation: checkNotNull ( rowKey ) ; checkNotNull ( columnKey ) ; Integer rowIndex = rowKeyToIndex . get ( rowKey ) ; checkArgument ( rowIndex != null , "Row %s not in %s" , rowKey , rowList ) ; Integer columnIndex = columnKeyToIndex . get ( columnKey ) ; checkArgument ( columnIndex != null , "Column %s not in %s" , columnKey , columnList ) ; return set ( rowIndex , columnIndex , value ) ;


signature:
public class Optional { /** * If { @ code nullableReference } is non - null , returns an { @ code Optional } instance containing that
 * reference ; otherwise returns { @ link Optional # absent } .
 * < p > < b > Comparison to { @ code java . util . Optional } : < / b > this method is equivalent to Java 8 ' s
 * { @ code Optional . ofNullable } . */
public static < T > Optional < T > fromNullable ( @ NullableDecl T nullableReference ) { } }

implementation: return ( nullableReference == null ) ? Optional . < T > absent ( ) : new Present < T > ( nullableReference ) ;


signature:
public class ImmutableListMultimap { /** * Creates an ImmutableListMultimap from an asMap . entrySet . */
static < K , V > ImmutableListMultimap < K , V > fromMapEntries ( Collection < ? extends Map . Entry < ? extends K , ? extends Collection < ? extends V > > > mapEntries , @ NullableDecl Comparator < ? super V > valueComparator ) { } }

implementation: if ( mapEntries . isEmpty ( ) ) { return of ( ) ; } ImmutableMap . Builder < K , ImmutableList < V > > builder = new ImmutableMap . Builder < > ( mapEntries . size ( ) ) ; int size = 0 ; for ( Entry < ? extends K , ? extends Collection < ? extends V > > entry : mapEntries ) { K key = entry . getKey ( ) ; Collection < ? extends V > values = entry . getValue ( ) ; ImmutableList < V > list = ( valueComparator == null ) ? ImmutableList . copyOf ( values ) : ImmutableList . sortedCopyOf ( valueComparator , values ) ; if ( ! list . isEmpty ( ) ) { builder . put ( key , list ) ; size += list . size ( ) ; } } return new ImmutableListMultimap < > ( builder . build ( ) , size ) ;


signature:
public class ImmutableListMultimap { /** * Returns an immutable list of the values for the given key . If no mappings in the multimap have
 * the provided key , an empty immutable list is returned . The values are in the same order as the
 * parameters used to build this multimap . */
@ Override public ImmutableList < V > get ( @ NullableDecl K key ) { } }

implementation:
// This cast is safe as its type is known in constructor .
ImmutableList < V > list = ( ImmutableList < V > ) map . get ( key ) ; return ( list == null ) ? ImmutableList . < V > of ( ) : list ;


signature:
public class HashBiMap { /** * Constructs a new bimap containing initial values from { @ code map } . The bimap is created with an
 * initial capacity sufficient to hold the mappings in the specified map . */
public static < K , V > HashBiMap < K , V > create ( Map < ? extends K , ? extends V > map ) { } }

implementation: HashBiMap < K , V > bimap = create ( map . size ( ) ) ; bimap . putAll ( map ) ; return bimap ;


signature:
public class HashBiMap { /** * Finds and removes { @ code entry } from the bucket linked lists in both the key - to - value direction
 * and the value - to - key direction . */
private void delete ( BiEntry < K , V > entry ) { } }

implementation: int keyBucket = entry . keyHash & mask ; BiEntry < K , V > prevBucketEntry = null ; for ( BiEntry < K , V > bucketEntry = hashTableKToV [ keyBucket ] ; true ; bucketEntry = bucketEntry . nextInKToVBucket ) { if ( bucketEntry == entry ) { if ( prevBucketEntry == null ) { hashTableKToV [ keyBucket ] = entry . nextInKToVBucket ; } else { prevBucketEntry . nextInKToVBucket = entry . nextInKToVBucket ; } break ; } prevBucketEntry = bucketEntry ; } int valueBucket = entry . valueHash & mask ; prevBucketEntry = null ; for ( BiEntry < K , V > bucketEntry = hashTableVToK [ valueBucket ] ; true ; bucketEntry = bucketEntry . nextInVToKBucket ) { if ( bucketEntry == entry ) { if ( prevBucketEntry == null ) { hashTableVToK [ valueBucket ] = entry . nextInVToKBucket ; } else { prevBucketEntry . nextInVToKBucket = entry . nextInVToKBucket ; } break ; } prevBucketEntry = bucketEntry ; } if ( entry . prevInKeyInsertionOrder == null ) { firstInKeyInsertionOrder = entry . nextInKeyInsertionOrder ; } else { entry . prevInKeyInsertionOrder . nextInKeyInsertionOrder = entry . nextInKeyInsertionOrder ; } if ( entry . nextInKeyInsertionOrder == null ) { lastInKeyInsertionOrder = entry . prevInKeyInsertionOrder ; } else { entry . nextInKeyInsertionOrder . prevInKeyInsertionOrder = entry . prevInKeyInsertionOrder ; } size -- ; modCount ++ ;


signature:
public class ObjectArrays { /** * Returns a new array that prepends { @ code element } to { @ code array } .
 * @ param element the element to prepend to the front of { @ code array }
 * @ param array the array of elements to append
 * @ return an array whose size is one larger than { @ code array } , with { @ code element } occupying
 * the first position , and the elements of { @ code array } occupying the remaining elements . */
public static < T > T [ ] concat ( @ NullableDecl T element , T [ ] array ) { } }

implementation: T [ ] result = newArray ( array , array . length + 1 ) ; result [ 0 ] = element ; System . arraycopy ( array , 0 , result , 1 , array . length ) ; return result ;


signature:
public class Suppliers { /** * Returns a new supplier which is the composition of the provided function and supplier . In other
 * words , the new supplier ' s value will be computed by retrieving the value from { @ code supplier } ,
 * and then applying { @ code function } to that value . Note that the resulting supplier will not
 * call { @ code supplier } or invoke { @ code function } until it is called . */
public static < F , T > Supplier < T > compose ( Function < ? super F , T > function , Supplier < F > supplier ) { } }

implementation: return new SupplierComposition < > ( function , supplier ) ;


signature:
public class Suppliers { /** * Returns a supplier which caches the instance retrieved during the first call to { @ code get ( ) }
 * and returns that value on subsequent calls to { @ code get ( ) } . See : < a
 * href = " http : / / en . wikipedia . org / wiki / Memoization " > memoization < / a >
 * < p > The returned supplier is thread - safe . The delegate ' s { @ code get ( ) } method will be invoked at
 * most once unless the underlying { @ code get ( ) } throws an exception . The supplier ' s serialized
 * form does not contain the cached value , which will be recalculated when { @ code get ( ) } is called
 * on the reserialized instance .
 * < p > When the underlying delegate throws an exception then this memoizing supplier will keep
 * delegating calls until it returns valid data .
 * < p > If { @ code delegate } is an instance created by an earlier call to { @ code memoize } , it is
 * returned directly . */
public static < T > Supplier < T > memoize ( Supplier < T > delegate ) { } }

implementation: if ( delegate instanceof NonSerializableMemoizingSupplier || delegate instanceof MemoizingSupplier ) { return delegate ; } return delegate instanceof Serializable ? new MemoizingSupplier < T > ( delegate ) : new NonSerializableMemoizingSupplier < T > ( delegate ) ;


signature:
public class Suppliers { /** * Returns a supplier that always supplies { @ code instance } . */
public static < T > Supplier < T > ofInstance ( @ Nullable T instance ) { } }

implementation: return new SupplierOfInstance < T > ( instance ) ;


signature:
public class Suppliers { /** * Returns a supplier whose { @ code get ( ) } method synchronizes on { @ code delegate } before calling
 * it , making it thread - safe . */
public static < T > Supplier < T > synchronizedSupplier ( Supplier < T > delegate ) { } }

implementation: return new ThreadSafeSupplier < T > ( delegate ) ;


signature:
public class Suppliers { /** * Returns a function that accepts a supplier and returns the result of invoking { @ link
 * Supplier # get } on that supplier .
 * < p > < b > Java 8 users : < / b > use the method reference { @ code Supplier : : get } instead .
 * @ since 8.0 */
public static < T > Function < Supplier < T > , T > supplierFunction ( ) { } }

implementation:
@ SuppressWarnings ( "unchecked" ) // implementation is " fully variant "
SupplierFunction < T > sf = ( SupplierFunction < T > ) SupplierFunctionImpl . INSTANCE ; return sf ;


signature:
public class InterruptibleTask { /** * Interrupts the running task . Because this internally calls { @ link Thread # interrupt ( ) } which can
 * in turn invoke arbitrary code it is not safe to call while holding a lock . */
final void interruptTask ( ) { } }

implementation:
// Since the Thread is replaced by DONE before run ( ) invokes listeners or returns , if we succeed
// in this CAS , there ' s no risk of interrupting the wrong thread or interrupting a thread that
// isn ' t currently executing this task .
Runnable currentRunner = get ( ) ; if ( currentRunner instanceof Thread && compareAndSet ( currentRunner , INTERRUPTING ) ) { // Thread . interrupt can throw aribitrary exceptions due to the nio InterruptibleChannel API
// This will make sure that tasks don ' t get stuck busy waiting .
// Some of this is fixed in jdk11 ( see https : / / bugs . openjdk . java . net / browse / JDK - 8198692 ) but
// not all . See the test cases for examples on how this can happen .
try { ( ( Thread ) currentRunner ) . interrupt ( ) ; } finally { Runnable prev = getAndSet ( DONE ) ; if ( prev == PARKED ) { LockSupport . unpark ( ( Thread ) currentRunner ) ; } } }


signature:
public class BaseEncoding { /** * Encodes the specified range of the specified byte array , and returns the encoded { @ code
 * String } . */
public final String encode ( byte [ ] bytes , int off , int len ) { } }

implementation: checkPositionIndexes ( off , off + len , bytes . length ) ; StringBuilder result = new StringBuilder ( maxEncodedSize ( len ) ) ; try { encodeTo ( result , bytes , off , len ) ; } catch ( IOException impossible ) { throw new AssertionError ( impossible ) ; } return result . toString ( ) ;


signature:
public class BaseEncoding { /** * TODO ( lowasser ) : document the extent of leniency , probably after adding ignore ( CharMatcher ) */
private static byte [ ] extract ( byte [ ] result , int length ) { } }

implementation: if ( length == result . length ) { return result ; } else { byte [ ] trunc = new byte [ length ] ; System . arraycopy ( result , 0 , trunc , 0 , length ) ; return trunc ; }


signature:
public class BaseEncoding { /** * Decodes the specified character sequence , and returns the resulting { @ code byte [ ] } . This is the
 * inverse operation to { @ link # encode ( byte [ ] ) } .
 * @ throws DecodingException if the input is not a valid encoded string according to this
 * encoding . */
final byte [ ] decodeChecked ( CharSequence chars ) throws DecodingException { } }

implementation: chars = trimTrailingPadding ( chars ) ; byte [ ] tmp = new byte [ maxDecodedSize ( chars . length ( ) ) ] ; int len = decodeTo ( tmp , chars ) ; return extract ( tmp , len ) ;


signature:
public class LinkedListMultimap { /** * { @ inheritDoc }
 * < p > The returned list is immutable and implements { @ link java . util . RandomAccess } . */
@ CanIgnoreReturnValue @ Override public List < V > removeAll ( @ NullableDecl Object key ) { } }

implementation: List < V > oldValues = getCopy ( key ) ; removeAllNodes ( key ) ; return oldValues ;


signature:
public class Tables { /** * Creates a transposed view of a given table that flips its row and column keys . In other words ,
 * calling { @ code get ( columnKey , rowKey ) } on the generated table always returns the same value as
 * calling { @ code get ( rowKey , columnKey ) } on the original table . Updating the original table
 * changes the contents of the transposed table and vice versa .
 * < p > The returned table supports update operations as long as the input table supports the
 * analogous operation with swapped rows and columns . For example , in a { @ link HashBasedTable }
 * instance , { @ code rowKeySet ( ) . iterator ( ) } supports { @ code remove ( ) } but { @ code
 * columnKeySet ( ) . iterator ( ) } doesn ' t . With a transposed { @ link HashBasedTable } , it ' s the other
 * way around . */
public static < R , C , V > Table < C , R , V > transpose ( Table < R , C , V > table ) { } }

implementation: return ( table instanceof TransposeTable ) ? ( ( TransposeTable < R , C , V > ) table ) . original : new TransposeTable < C , R , V > ( table ) ;


signature:
public class Tables { /** * Returns a view of a table where each value is transformed by a function . All other properties
 * of the table , such as iteration order , are left intact .
 * < p > Changes in the underlying table are reflected in this view . Conversely , this view supports
 * removal operations , and these are reflected in the underlying table .
 * < p > It ' s acceptable for the underlying table to contain null keys , and even null values provided
 * that the function is capable of accepting null input . The transformed table might contain null
 * values , if the function sometimes gives a null result .
 * < p > The returned table is not thread - safe or serializable , even if the underlying table is .
 * < p > The function is applied lazily , invoked when needed . This is necessary for the returned
 * table to be a view , but it means that the function will be applied many times for bulk
 * operations like { @ link Table # containsValue } and { @ code Table . toString ( ) } . For this to perform
 * well , { @ code function } should be fast . To avoid lazy evaluation when the returned table doesn ' t
 * need to be a view , copy the returned table into a new table of your choosing .
 * @ since 10.0 */
@ Beta public static < R , C , V1 , V2 > Table < R , C , V2 > transformValues ( Table < R , C , V1 > fromTable , Function < ? super V1 , V2 > function ) { } }

implementation: return new TransformedTable < > ( fromTable , function ) ;


signature:
public class Tables { /** * Returns an unmodifiable view of the specified table . This method allows modules to provide
 * users with " read - only " access to internal tables . Query operations on the returned table " read
 * through " to the specified table , and attempts to modify the returned table , whether direct or
 * via its collection views , result in an { @ code UnsupportedOperationException } .
 * < p > The returned table will be serializable if the specified table is serializable .
 * < p > Consider using an { @ link ImmutableTable } , which is guaranteed never to change .
 * @ since 11.0 */
public static < R , C , V > Table < R , C , V > unmodifiableTable ( Table < ? extends R , ? extends C , ? extends V > table ) { } }

implementation: return new UnmodifiableTable < > ( table ) ;


signature:
public class Tables { /** * Returns an unmodifiable view of the specified row - sorted table . This method allows modules to
 * provide users with " read - only " access to internal tables . Query operations on the returned
 * table " read through " to the specified table , and attempts to modify the returned table , whether
 * direct or via its collection views , result in an { @ code UnsupportedOperationException } .
 * < p > The returned table will be serializable if the specified table is serializable .
 * @ param table the row - sorted table for which an unmodifiable view is to be returned
 * @ return an unmodifiable view of the specified table
 * @ since 11.0 */
@ Beta public static < R , C , V > RowSortedTable < R , C , V > unmodifiableRowSortedTable ( RowSortedTable < R , ? extends C , ? extends V > table ) { } }

implementation:
/* * It ' s not ? extends R , because it ' s technically not covariant in R . Specifically ,
 * table . rowMap ( ) . comparator ( ) could return a comparator that only works for the ? extends R .
 * Collections . unmodifiableSortedMap makes the same distinction . */
return new UnmodifiableRowSortedMap < > ( table ) ;


signature:
public class Tables { /** * Returns a synchronized ( thread - safe ) table backed by the specified table . In order to guarantee
 * serial access , it is critical that < b > all < / b > access to the backing table is accomplished
 * through the returned table .
 * < p > It is imperative that the user manually synchronize on the returned table when accessing any
 * of its collection views :
 * < pre > { @ code
 * Table < R , C , V > table = Tables . synchronizedTable ( HashBasedTable . < R , C , V > create ( ) ) ;
 * Map < C , V > row = table . row ( rowKey ) ; / / Needn ' t be in synchronized block
 * synchronized ( table ) { / / Synchronizing on table , not row !
 * Iterator < Entry < C , V > > i = row . entrySet ( ) . iterator ( ) ; / / Must be in synchronized block
 * while ( i . hasNext ( ) ) {
 * foo ( i . next ( ) ) ;
 * } < / pre >
 * < p > Failure to follow this advice may result in non - deterministic behavior .
 * < p > The returned table will be serializable if the specified table is serializable .
 * @ param table the table to be wrapped in a synchronized view
 * @ return a synchronized view of the specified table
 * @ since 22.0 */
public static < R , C , V > Table < R , C , V > synchronizedTable ( Table < R , C , V > table ) { } }

implementation: return Synchronized . table ( table , null ) ;


signature:
public class TreeMultiset { /** * Creates an empty multiset containing the given initial elements , sorted according to the
 * elements ' natural order .
 * < p > This implementation is highly efficient when { @ code elements } is itself a { @ link Multiset } .
 * < p > The type specification is { @ code < E extends Comparable > } , instead of the more specific
 * { @ code < E extends Comparable < ? super E > > } , to support classes defined without generics . */
public static < E extends Comparable > TreeMultiset < E > create ( Iterable < ? extends E > elements ) { } }

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


signature:
public class Defaults { /** * Returns the default value of { @ code type } as defined by JLS - - - { @ code 0 } for numbers , { @ code
 * false } for { @ code boolean } and { @ code ' \ 0 ' } for { @ code char } . For non - primitive types and
 * { @ code void } , { @ code null } is returned . */
@ SuppressWarnings ( "unchecked" ) public static < T > @ Nullable T defaultValue ( Class < T > type ) { } }

implementation: checkNotNull ( type ) ; if ( type == boolean . class ) { return ( T ) Boolean . FALSE ; } else if ( type == char . class ) { return ( T ) Character . valueOf ( '\0' ) ; } else if ( type == byte . class ) { return ( T ) Byte . valueOf ( ( byte ) 0 ) ; } else if ( type == short . class ) { return ( T ) Short . valueOf ( ( short ) 0 ) ; } else if ( type == int . class ) { return ( T ) Integer . valueOf ( 0 ) ; } else if ( type == long . class ) { return ( T ) Long . valueOf ( 0L ) ; } else if ( type == float . class ) { return ( T ) FLOAT_DEFAULT ; } else if ( type == double . class ) { return ( T ) DOUBLE_DEFAULT ; } else { return null ; }


signature:
public class Strings { /** * Returns a string consisting of a specific number of concatenated copies of an input string . For
 * example , { @ code repeat ( " hey " , 3 ) } returns the string { @ code " heyheyhey " } .
 * @ param string any non - null string
 * @ param count the number of times to repeat it ; a nonnegative integer
 * @ return a string containing { @ code string } repeated { @ code count } times ( the empty string if
 * { @ code count } is zero )
 * @ throws IllegalArgumentException if { @ code count } is negative */
public static String repeat ( String string , int count ) { } }

implementation:
checkNotNull ( string ) ; // eager for GWT .
if ( count <= 1 ) { checkArgument ( count >= 0 , "invalid count: %s" , count ) ; return ( count == 0 ) ? "" : string ; } // IF YOU MODIFY THE CODE HERE , you must update StringsRepeatBenchmark
final int len = string . length ( ) ; final long longSize = ( long ) len * ( long ) count ; final int size = ( int ) longSize ; if ( size != longSize ) { throw new ArrayIndexOutOfBoundsException ( "Required array size too large: " + longSize ) ; } final char [ ] array = new char [ size ] ; string . getChars ( 0 , len , array , 0 ) ; int n ; for ( n = len ; n < size - n ; n <<= 1 ) { System . arraycopy ( array , 0 , array , n , n ) ; } System . arraycopy ( array , 0 , array , n , size - n ) ; return new String ( array ) ;


signature:
public class Strings { /** * Returns the longest string { @ code prefix } such that { @ code a . toString ( ) . startsWith ( prefix ) & &
 * b . toString ( ) . startsWith ( prefix ) } , taking care not to split surrogate pairs . If { @ code a } and
 * { @ code b } have no common prefix , returns the empty string .
 * @ since 11.0 */
public static String commonPrefix ( CharSequence a , CharSequence b ) { } }

implementation: checkNotNull ( a ) ; checkNotNull ( b ) ; int maxPrefixLength = Math . min ( a . length ( ) , b . length ( ) ) ; int p = 0 ; while ( p < maxPrefixLength && a . charAt ( p ) == b . charAt ( p ) ) { p ++ ; } if ( validSurrogatePairAt ( a , p - 1 ) || validSurrogatePairAt ( b , p - 1 ) ) { p -- ; } return a . subSequence ( 0 , p ) . toString ( ) ;