signature:
public class MongoCredential { /** * Creates a new MongoCredential as a copy of this instance , with the specified mechanism property added .
 * @ param key the key to the property , which is treated as case - insensitive
 * @ param value the value of the property
 * @ param < T > the property type
 * @ return the credential
 * @ since 2.12 */
public < T > MongoCredential withMechanismProperty ( final String key , final T value ) { } }

implementation: return new MongoCredential ( this , key , value ) ;


signature:
public class MongoCredential { /** * Creates a new MongoCredential with the set mechanism . The existing mechanism must be null .
 * @ param mechanism the mechanism to set
 * @ return the credential
 * @ since 3.8 */
public MongoCredential withMechanism ( final AuthenticationMechanism mechanism ) { } }

implementation: if ( this . mechanism != null ) { throw new IllegalArgumentException ( "Mechanism already set" ) ; } return new MongoCredential ( mechanism , userName , source , password , mechanismProperties ) ;


signature:
public class MongoCredential { /** * Get the value of the given key to a mechanism property , or defaultValue if there is no mapping .
 * @ param key the mechanism property key , which is treated as case - insensitive
 * @ param defaultValue the default value , if no mapping exists
 * @ param < T > the value type
 * @ return the mechanism property value
 * @ since 2.12 */
@ SuppressWarnings ( "unchecked" ) @ Nullable public < T > T getMechanismProperty ( final String key , @ Nullable final T defaultValue ) { } }

implementation: notNull ( "key" , key ) ; T value = ( T ) mechanismProperties . get ( key . toLowerCase ( ) ) ; return ( value == null ) ? defaultValue : value ;


signature:
public class OutputBuffer { /** * Gets a copy of the buffered bytes .
 * @ return the byte array
 * @ see org . bson . io . OutputBuffer # pipe ( java . io . OutputStream ) */
public byte [ ] toByteArray ( ) { } }

implementation: try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( size ( ) ) ; pipe ( bout ) ; return bout . toByteArray ( ) ; } catch ( IOException ioe ) { throw new RuntimeException ( "should be impossible" , ioe ) ; }


signature:
public class BsonArray { /** * Parses a string in MongoDB Extended JSON format to a { @ code BsonArray }
 * @ param json the JSON string
 * @ return a corresponding { @ code BsonArray } object
 * @ see org . bson . json . JsonReader
 * @ mongodb . driver . manual reference / mongodb - extended - json / MongoDB Extended JSON
 * @ since 3.4 */
public static BsonArray parse ( final String json ) { } }

implementation: return new BsonArrayCodec ( ) . decode ( new JsonReader ( json ) , DecoderContext . builder ( ) . build ( ) ) ;


signature:
public class ClassMapBasedObjectSerializer { /** * Assign a ObjectSerializer to perform a type specific serialization scheme
 * @ param c this object ' s type serves as a key in the serialization map . ClassMapBasedObjectSerializer uses
 * org . bson . util . ClassMap and not only checks if ' c ' is a key in the Map , but also walks the up superclass and
 * interface graph of ' c ' to find matches . This means that it is only necessary assign ObjectSerializers to base
 * classes . @ see org . bson . util . ClassMap
 * @ param serializer performs the serialization mapping specific to the @ param key type */
@ SuppressWarnings ( "rawtypes" ) void addObjectSerializer ( final Class c , final ObjectSerializer serializer ) { } }

implementation: _serializers . put ( c , serializer ) ;


signature:
public class DefaultClusterFactory { /** * Creates a cluster with the given settings . The cluster mode will be based on the mode from the settings .
 * @ param settings the cluster settings
 * @ param serverSettings the server settings
 * @ param connectionPoolSettings the connection pool settings
 * @ param streamFactory the stream factory
 * @ param heartbeatStreamFactory the heartbeat stream factory
 * @ param credentialList the credential list
 * @ param clusterListener an optional listener for cluster - related events
 * @ param connectionPoolListener an optional listener for connection pool - related events
 * @ param connectionListener an optional listener for connection - related events
 * @ param commandListener an optional listener for command - related events
 * @ return the cluster
 * @ since 3.1
 * @ deprecated use { @ link # createCluster ( ClusterSettings , ServerSettings , ConnectionPoolSettings , StreamFactory , StreamFactory ,
 * List , CommandListener , String , MongoDriverInformation , List ) } instead */
@ Deprecated public Cluster create ( final ClusterSettings settings , final ServerSettings serverSettings , final ConnectionPoolSettings connectionPoolSettings , final StreamFactory streamFactory , final StreamFactory heartbeatStreamFactory , final List < MongoCredential > credentialList , final ClusterListener clusterListener , final ConnectionPoolListener connectionPoolListener , final com . mongodb . event . ConnectionListener connectionListener , final CommandListener commandListener ) { } }

implementation: return createCluster ( getClusterSettings ( settings , clusterListener ) , serverSettings , getConnectionPoolSettings ( connectionPoolSettings , connectionPoolListener ) , streamFactory , heartbeatStreamFactory , credentialList , commandListener , null , null , Collections . < MongoCompressor > emptyList ( ) ) ;


signature:
public class DefaultClusterFactory { /** * Creates a cluster with the given settings . The cluster mode will be based on the mode from the settings .
 * @ param clusterSettings the cluster settings
 * @ param serverSettings the server settings
 * @ param connectionPoolSettings the connection pool settings
 * @ param streamFactory the stream factory
 * @ param heartbeatStreamFactory the heartbeat stream factory
 * @ param credentialList the credential list
 * @ param commandListener an optional listener for command - related events
 * @ param applicationName an optional application name to associate with connections to the servers in this cluster
 * @ param mongoDriverInformation the optional driver information associate with connections to the servers in this cluster
 * @ return the cluster
 * @ since 3.5
 * @ deprecated use { @ link # createCluster ( ClusterSettings , ServerSettings , ConnectionPoolSettings , StreamFactory , StreamFactory ,
 * List , CommandListener , String , MongoDriverInformation , List ) } instead */
@ Deprecated public Cluster createCluster ( final ClusterSettings clusterSettings , final ServerSettings serverSettings , final ConnectionPoolSettings connectionPoolSettings , final StreamFactory streamFactory , final StreamFactory heartbeatStreamFactory , final List < MongoCredential > credentialList , final CommandListener commandListener , final String applicationName , final MongoDriverInformation mongoDriverInformation ) { } }

implementation: return createCluster ( clusterSettings , serverSettings , connectionPoolSettings , streamFactory , heartbeatStreamFactory , credentialList , commandListener , applicationName , mongoDriverInformation , Collections . < MongoCompressor > emptyList ( ) ) ;


signature:
public class DefaultClusterFactory { /** * Creates a cluster with the given settings . The cluster mode will be based on the mode from the settings .
 * @ param clusterSettings the cluster settings
 * @ param serverSettings the server settings
 * @ param connectionPoolSettings the connection pool settings
 * @ param streamFactory the stream factory
 * @ param heartbeatStreamFactory the heartbeat stream factory
 * @ param credentialList the credential list
 * @ param commandListener an optional listener for command - related events
 * @ param applicationName an optional application name to associate with connections to the servers in this cluster
 * @ param mongoDriverInformation the optional driver information associate with connections to the servers in this cluster
 * @ param compressorList the list of compressors to request , in priority order
 * @ return the cluster
 * @ since 3.6 */
public Cluster createCluster ( final ClusterSettings clusterSettings , final ServerSettings serverSettings , final ConnectionPoolSettings connectionPoolSettings , final StreamFactory streamFactory , final StreamFactory heartbeatStreamFactory , final List < MongoCredential > credentialList , final CommandListener commandListener , final String applicationName , final MongoDriverInformation mongoDriverInformation , final List < MongoCompressor > compressorList ) { } }

implementation: ClusterId clusterId = new ClusterId ( clusterSettings . getDescription ( ) ) ; ClusterableServerFactory serverFactory = new DefaultClusterableServerFactory ( clusterId , clusterSettings , serverSettings , connectionPoolSettings , streamFactory , heartbeatStreamFactory , credentialList , commandListener , applicationName , mongoDriverInformation != null ? mongoDriverInformation : MongoDriverInformation . builder ( ) . build ( ) , compressorList ) ; DnsSrvRecordMonitorFactory dnsSrvRecordMonitorFactory = new DefaultDnsSrvRecordMonitorFactory ( clusterId , serverSettings ) ; if ( clusterSettings . getMode ( ) == ClusterConnectionMode . SINGLE ) { return new SingleServerCluster ( clusterId , clusterSettings , serverFactory ) ; } else if ( clusterSettings . getMode ( ) == ClusterConnectionMode . MULTIPLE ) { if ( clusterSettings . getSrvHost ( ) == null ) { return new MultiServerCluster ( clusterId , clusterSettings , serverFactory ) ; } else { return new DnsMultiServerCluster ( clusterId , clusterSettings , serverFactory , dnsSrvRecordMonitorFactory ) ; } } else { throw new UnsupportedOperationException ( "Unsupported cluster mode: " + clusterSettings . getMode ( ) ) ; }


signature:
public class UpdateRequest { /** * Sets whether this will update all documents matching the query filter .
 * @ param isMulti whether this will update all documents matching the query filter
 * @ return this */
public UpdateRequest multi ( final boolean isMulti ) { } }

implementation: if ( isMulti && updateType == Type . REPLACE ) { throw new IllegalArgumentException ( "Replacements can not be multi" ) ; } this . isMulti = isMulti ; return this ;


signature:
public class RequestMessage { /** * Encoded the message to the given output .
 * @ param bsonOutput the output
 * @ param sessionContext the session context */
public void encode ( final BsonOutput bsonOutput , final SessionContext sessionContext ) { } }

implementation: notNull ( "sessionContext" , sessionContext ) ; int messageStartPosition = bsonOutput . getPosition ( ) ; writeMessagePrologue ( bsonOutput ) ; EncodingMetadata encodingMetadata = encodeMessageBodyWithMetadata ( bsonOutput , sessionContext ) ; backpatchMessageLength ( messageStartPosition , bsonOutput ) ; this . encodingMetadata = encodingMetadata ;


signature:
public class RequestMessage { /** * Writes the message prologue to the given output .
 * @ param bsonOutput the output */
protected void writeMessagePrologue ( final BsonOutput bsonOutput ) { } }

implementation:
bsonOutput . writeInt32 ( 0 ) ; // length : will set this later
bsonOutput . writeInt32 ( id ) ; bsonOutput . writeInt32 ( 0 ) ; // response to
bsonOutput . writeInt32 ( opCode . getValue ( ) ) ;


signature:
public class RequestMessage { /** * Appends a document to the message .
 * @ param document the document
 * @ param bsonOutput the output
 * @ param validator the field name validator */
protected void addDocument ( final BsonDocument document , final BsonOutput bsonOutput , final FieldNameValidator validator ) { } }

implementation: addDocument ( document , getCodec ( document ) , EncoderContext . builder ( ) . build ( ) , bsonOutput , validator , settings . getMaxDocumentSize ( ) + DOCUMENT_HEADROOM , null ) ;


signature:
public class RequestMessage { /** * Appends a document to the message that is intended for storage in a collection .
 * @ param document the document
 * @ param bsonOutput the output
 * @ param validator the field name validator */
protected void addCollectibleDocument ( final BsonDocument document , final BsonOutput bsonOutput , final FieldNameValidator validator ) { } }

implementation: addDocument ( document , getCodec ( document ) , EncoderContext . builder ( ) . isEncodingCollectibleDocument ( true ) . build ( ) , bsonOutput , validator , settings . getMaxDocumentSize ( ) , null ) ;


signature:
public class RequestMessage { /** * Backpatches the message length into the beginning of the message .
 * @ param startPosition the start position of the message
 * @ param bsonOutput the output */
protected void backpatchMessageLength ( final int startPosition , final BsonOutput bsonOutput ) { } }

implementation: int messageLength = bsonOutput . getPosition ( ) - startPosition ; bsonOutput . writeInt32 ( bsonOutput . getPosition ( ) - messageLength , messageLength ) ;


signature:
public class CommandOperationHelper { /** * / * Read Binding Helpers */
static BsonDocument executeCommand ( final ReadBinding binding , final String database , final CommandCreator commandCreator , final boolean retryReads ) { } }

implementation: return executeCommand ( binding , database , commandCreator , new BsonDocumentCodec ( ) , retryReads ) ;


signature:
public class CommandOperationHelper { /** * / * Write Binding Helpers */
static BsonDocument executeCommand ( final WriteBinding binding , final String database , final BsonDocument command ) { } }

implementation: return executeCommand ( binding , database , command , new IdentityWriteTransformer < BsonDocument > ( ) ) ;


signature:
public class CommandOperationHelper { /** * / * Private Read Connection Source Helpers */
private static < T > T executeCommand ( final String database , final BsonDocument command , final FieldNameValidator fieldNameValidator , final Decoder < T > decoder , final ConnectionSource source , final Connection connection , final ReadPreference readPreference ) { } }

implementation: return executeCommand ( database , command , fieldNameValidator , decoder , source , connection , readPreference , new IdentityReadTransformer < T > ( ) , source . getSessionContext ( ) ) ;


signature:
public class CommandOperationHelper { /** * / * Private Connection Helpers */
private static < D , T > T executeCommand ( final String database , final BsonDocument command , final Decoder < D > decoder , final ConnectionSource source , final Connection connection , final ReadPreference readPreference , final CommandReadTransformer < D , T > transformer , final SessionContext sessionContext ) { } }

implementation: return executeCommand ( database , command , new NoOpFieldNameValidator ( ) , decoder , source , connection , readPreference , transformer , sessionContext ) ;


signature:
public class CommandOperationHelper { /** * / * Private Connection Helpers */
private static < T > T executeWriteCommand ( final String database , final BsonDocument command , final Decoder < T > decoder , final Connection connection , final ReadPreference readPreference , final SessionContext sessionContext ) { } }

implementation: return executeWriteCommand ( database , command , new NoOpFieldNameValidator ( ) , decoder , connection , readPreference , new IdentityWriteTransformer < T > ( ) , sessionContext ) ;


signature:
public class CommandOperationHelper { /** * / * Async Read Binding Helpers */
static void executeCommandAsync ( final AsyncReadBinding binding , final String database , final CommandCreator commandCreator , final boolean retryReads , final SingleResultCallback < BsonDocument > callback ) { } }

implementation: executeCommandAsync ( binding , database , commandCreator , new BsonDocumentCodec ( ) , retryReads , callback ) ;


signature:
public class CommandOperationHelper { /** * / * Async Write Binding Helpers */
static void executeCommandAsync ( final AsyncWriteBinding binding , final String database , final BsonDocument command , final SingleResultCallback < BsonDocument > callback ) { } }

implementation: executeCommandAsync ( binding , database , command , new BsonDocumentCodec ( ) , callback ) ;


signature:
public class CommandOperationHelper { /** * / * Async Connection Helpers */
private static < D , T > void executeCommandAsync ( final String database , final BsonDocument command , final Decoder < D > decoder , final AsyncConnection connection , final ReadPreference readPreference , final CommandWriteTransformerAsync < D , T > transformer , final SessionContext sessionContext , final SingleResultCallback < T > callback ) { } }

implementation: connection . commandAsync ( database , command , new NoOpFieldNameValidator ( ) , readPreference , decoder , sessionContext , new SingleResultCallback < D > ( ) { @ Override public void onResult ( final D result , final Throwable t ) { if ( t != null ) { callback . onResult ( null , t ) ; } else { try { T transformedResult = transformer . apply ( result , connection ) ; callback . onResult ( transformedResult , null ) ; } catch ( Exception e ) { callback . onResult ( null , e ) ; } } } } ) ;


signature:
public class CommandOperationHelper { /** * / * Retryable write helpers */
static < T , R > R executeRetryableCommand ( final WriteBinding binding , final String database , final ReadPreference readPreference , final FieldNameValidator fieldNameValidator , final Decoder < T > commandResultDecoder , final CommandCreator commandCreator , final CommandWriteTransformer < T , R > transformer ) { } }

implementation: return executeRetryableCommand ( binding , database , readPreference , fieldNameValidator , commandResultDecoder , commandCreator , transformer , noOpRetryCommandModifier ( ) ) ;


signature:
public class GridFSInputFile { /** * This method first calls saveChunks ( long ) if the file data has not been saved yet . Then it persists the file entry to GridFS .
 * @ param chunkSize Size of chunks for file in bytes .
 * @ throws MongoException if there ' s a problem saving the file . */
public void save ( final long chunkSize ) { } }

implementation:
if ( outputStream != null ) { throw new MongoException ( "cannot mix OutputStream and regular save()" ) ; } // note that chunkSize only changes chunkSize in case we actually save chunks
// otherwise there is a risk file and chunks are not compatible
if ( ! savedChunks ) { try { saveChunks ( chunkSize ) ; } catch ( IOException ioe ) { throw new MongoException ( "couldn't save chunks" , ioe ) ; } } super . save ( ) ;


signature:
public class GridFSInputFile { /** * Saves all data into chunks from configured { @ link java . io . InputStream } input stream to GridFS . A non - default chunk size can be
 * specified . This method does NOT save the file object itself , one must call save ( ) to do so .
 * @ param chunkSize Size of chunks for file in bytes .
 * @ return Number of the next chunk .
 * @ throws IOException on problems reading the new entry ' s { @ link java . io . InputStream } .
 * @ throws MongoException if there ' s a failure */
public int saveChunks ( final long chunkSize ) throws IOException { } }

implementation:
if ( outputStream != null ) { throw new MongoException ( "Cannot mix OutputStream and regular save()" ) ; } if ( savedChunks ) { throw new MongoException ( "Chunks already saved!" ) ; } if ( chunkSize <= 0 ) { throw new MongoException ( "chunkSize must be greater than zero" ) ; } if ( this . chunkSize != chunkSize ) { this . chunkSize = chunkSize ; buffer = new byte [ ( int ) this . chunkSize ] ; } int bytesRead = 0 ; while ( bytesRead >= 0 ) { currentBufferPosition = 0 ; bytesRead = _readStream2Buffer ( ) ; dumpBuffer ( true ) ; } // only finish data , do not write file , in case one wants to change metadata
finishData ( ) ; return currentChunkNumber ;


signature:
public class GridFSInputFile { /** * Dumps a new chunk into the chunks collection . Depending on the flag , also partial buffers ( at the end ) are going to be written
 * immediately .
 * @ param writePartial Write also partial buffers full .
 * @ throws MongoException if there ' s a failure */
private void dumpBuffer ( final boolean writePartial ) { } }

implementation:
if ( ( currentBufferPosition < chunkSize ) && ! writePartial ) { // Bail out , chunk not complete yet
return ; } if ( currentBufferPosition == 0 ) { // chunk is empty , may be last chunk
return ; } byte [ ] writeBuffer = buffer ; if ( currentBufferPosition != chunkSize ) { writeBuffer = new byte [ currentBufferPosition ] ; System . arraycopy ( buffer , 0 , writeBuffer , 0 , currentBufferPosition ) ; } DBObject chunk = createChunk ( id , currentChunkNumber , writeBuffer ) ; fs . getChunksCollection ( ) . save ( chunk ) ; currentChunkNumber ++ ; totalBytes += writeBuffer . length ; messageDigester . update ( writeBuffer ) ; currentBufferPosition = 0 ;


signature:
public class GridFSInputFile { /** * Creates a new chunk of this file . Can be over - ridden , if input files need to be split into chunks using a different mechanism .
 * @ param id the file ID
 * @ param currentChunkNumber the unique id for this chunk
 * @ param writeBuffer the byte array containing the data for this chunk
 * @ return a DBObject representing this chunk . */
protected DBObject createChunk ( final Object id , final int currentChunkNumber , final byte [ ] writeBuffer ) { } }

implementation: return new BasicDBObject ( "files_id" , id ) . append ( "n" , currentChunkNumber ) . append ( "data" , writeBuffer ) ;


signature:
public class GridFSInputFile { /** * Reads a buffer full from the { @ link java . io . InputStream } .
 * @ return Number of bytes read from stream .
 * @ throws IOException if the reading from the stream fails . */
private int _readStream2Buffer ( ) throws IOException { } }

implementation: int bytesRead = 0 ; while ( currentBufferPosition < chunkSize && bytesRead >= 0 ) { bytesRead = inputStream . read ( buffer , currentBufferPosition , ( int ) chunkSize - currentBufferPosition ) ; if ( bytesRead > 0 ) { currentBufferPosition += bytesRead ; } else if ( bytesRead == 0 ) { throw new RuntimeException ( "i'm doing something wrong" ) ; } } return bytesRead ;


signature:
public class GridFSInputFile { /** * Marks the data as fully written . This needs to be called before super . save ( ) */
private void finishData ( ) { } }

implementation:
if ( ! savedChunks ) { md5 = Util . toHex ( messageDigester . digest ( ) ) ; messageDigester = null ; length = totalBytes ; savedChunks = true ; try { if ( inputStream != null && closeStreamOnPersist ) { inputStream . close ( ) ; } } catch ( IOException e ) { // ignore
} }


signature:
public class DBCursor { /** * Creates a copy of an existing database cursor . The new cursor is an iterator , even if the original was an array .
 * @ return the new cursor */
public DBCursor copy ( ) { } }

implementation: return new DBCursor ( collection , filter , findOptions , executor , decoderFactory , decoder , retryReads ) ;


signature:
public class DBCursor { /** * Checks if there is another object available .
 * < p > < em > Note < / em > : Automatically adds the { @ link Bytes # QUERYOPTION _ AWAITDATA } option to any cursors with the
 * { @ link Bytes # QUERYOPTION _ TAILABLE } option set . For non blocking tailable cursors see { @ link # tryNext } . < / p >
 * @ return true if there is another object available
 * @ mongodb . driver . manual / core / cursors / # cursor - batches Cursor Batches */
@ Override public boolean hasNext ( ) { } }

implementation: if ( closed ) { throw new IllegalStateException ( "Cursor has been closed" ) ; } if ( cursor == null ) { FindOperation < DBObject > operation = getQueryOperation ( decoder ) ; if ( operation . getCursorType ( ) == CursorType . Tailable ) { operation . cursorType ( CursorType . TailableAwait ) ; } initializeCursor ( operation ) ; } boolean hasNext = cursor . hasNext ( ) ; setServerCursorOnFinalizer ( cursor . getServerCursor ( ) ) ; return hasNext ;


signature:
public class DBCursor { /** * Non blocking check for tailable cursors to see if another object is available .
 * < p > Returns the object the cursor is at and moves the cursor ahead by one or
 * return null if no documents is available . < / p >
 * @ return the next element or null
 * @ throws MongoException if failed
 * @ throws IllegalArgumentException if the cursor is not tailable
 * @ mongodb . driver . manual / core / cursors / # cursor - batches Cursor Batches */
@ Nullable public DBObject tryNext ( ) { } }

implementation: if ( cursor == null ) { FindOperation < DBObject > operation = getQueryOperation ( decoder ) ; if ( ! operation . getCursorType ( ) . isTailable ( ) ) { throw new IllegalArgumentException ( "Can only be used with a tailable cursor" ) ; } initializeCursor ( operation ) ; } DBObject next = cursor . tryNext ( ) ; setServerCursorOnFinalizer ( cursor . getServerCursor ( ) ) ; return currentObject ( next ) ;


signature:
public class DBCursor { /** * Sets the query option - see Bytes . QUERYOPTION _ * for list .
 * @ param options the bitmask of options
 * @ return { @ code this } so calls can be chained
 * @ see Bytes
 * @ mongodb . driver . manual . . / meta - driver / latest / legacy / mongodb - wire - protocol / # op - query Query Flags */
@ Deprecated public DBCursor setOptions ( final int options ) { } }

implementation: if ( ( options & Bytes . QUERYOPTION_EXHAUST ) != 0 ) { throw new UnsupportedOperationException ( "exhaust query option is not supported" ) ; } this . options = options ; return this ;


signature:
public class DBCursor { /** * Adds a special operator like $ comment or $ returnKey . For example :
 * < pre >
 * addSpecial ( " $ returnKey " , 1)
 * addSpecial ( " $ comment " , " this is a special query )
 * < / pre >
 * @ param name the name of the special query operator
 * @ param value the value of the special query operator
 * @ return { @ code this } so calls can be chained
 * @ mongodb . driver . manual reference / operator Special Operators
 * @ deprecated Prefer per - operator methods , e . g . { @ link # comment ( String ) } , { @ link # explain ( ) } , etc . */
@ SuppressWarnings ( "deprecation" ) @ Deprecated public DBCursor addSpecial ( @ Nullable final String name , @ Nullable final Object value ) { } }

implementation: if ( name == null || value == null ) { return this ; } if ( "$comment" . equals ( name ) ) { comment ( value . toString ( ) ) ; } else if ( "$explain" . equals ( name ) ) { findOptions . getModifiers ( ) . put ( "$explain" , true ) ; } else if ( "$hint" . equals ( name ) ) { if ( value instanceof String ) { hint ( ( String ) value ) ; } else { hint ( ( DBObject ) value ) ; } } else if ( "$maxScan" . equals ( name ) ) { maxScan ( ( ( Number ) value ) . intValue ( ) ) ; } else if ( "$maxTimeMS" . equals ( name ) ) { maxTime ( ( ( Number ) value ) . longValue ( ) , MILLISECONDS ) ; } else if ( "$max" . equals ( name ) ) { max ( ( DBObject ) value ) ; } else if ( "$min" . equals ( name ) ) { min ( ( DBObject ) value ) ; } else if ( "$orderby" . equals ( name ) ) { sort ( ( DBObject ) value ) ; } else if ( "$returnKey" . equals ( name ) ) { returnKey ( ) ; } else if ( "$showDiskLoc" . equals ( name ) ) { showDiskLoc ( ) ; } else if ( "$snapshot" . equals ( name ) ) { snapshot ( ) ; } else if ( "$natural" . equals ( name ) ) { sort ( new BasicDBObject ( "$natural" , ( ( Number ) value ) . intValue ( ) ) ) ; } else { throw new IllegalArgumentException ( name + "is not a supported modifier" ) ; } return this ;


signature:
public class DBCursor { /** * Returns an object containing basic information about the execution of the query that created this cursor . This creates a { @ code
 * DBObject } with a number of fields , including but not limited to :
 * < ul >
 * < li > < i > cursor : < / i > cursor type < / li >
 * < li > < i > nScanned : < / i > number of records examined by the database for this query < / li >
 * < li > < i > n : < / i > the number of records that the database returned < / li >
 * < li > < i > millis : < / i > how long it took the database to execute the query < / li >
 * < / ul >
 * @ return a { @ code DBObject } containing the explain output for this DBCursor ' s query
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / explain Explain Output */
public DBObject explain ( ) { } }

implementation: return toDBObject ( executor . execute ( getQueryOperation ( collection . getObjectCodec ( ) ) . asExplainableOperation ( ExplainVerbosity . QUERY_PLANNER ) , getReadPreference ( ) , getReadConcern ( ) ) ) ;


signature:
public class DBCursor { /** * Converts this cursor to an array .
 * @ param max the maximum number of objects to return
 * @ return an array of objects
 * @ throws MongoException if failed */
public List < DBObject > toArray ( final int max ) { } }

implementation: checkIteratorOrArray ( IteratorOrArray . ARRAY ) ; fillArray ( max - 1 ) ; return all ;


signature:
public class DBCursor { /** * Returns the first document that matches the query .
 * @ return the first matching document
 * @ since 2.12 */
@ Nullable public DBObject one ( ) { } }

implementation: DBCursor findOneCursor = copy ( ) . limit ( - 1 ) ; try { return findOneCursor . hasNext ( ) ? findOneCursor . next ( ) : null ; } finally { findOneCursor . close ( ) ; }


signature:
public class DBCursor { /** * Counts the number of objects matching the query this does take limit / skip into consideration
 * @ return the number of objects
 * @ throws MongoException if the operation failed
 * @ see # count ( ) */
public int size ( ) { } }

implementation: DBCollectionCountOptions countOptions = getDbCollectionCountOptions ( ) . skip ( findOptions . getSkip ( ) ) . limit ( findOptions . getLimit ( ) ) ; return ( int ) collection . getCount ( getQuery ( ) , countOptions ) ;


signature:
public class DBCursor { /** * Gets the default read preference .
 * @ return the readPreference used by this cursor */
public ReadPreference getReadPreference ( ) { } }

implementation: ReadPreference readPreference = findOptions . getReadPreference ( ) ; if ( readPreference != null ) { return readPreference ; } return collection . getReadPreference ( ) ;


signature:
public class DBCursor { /** * Get the read concern for this collection .
 * @ return the { @ link com . mongodb . ReadConcern }
 * @ since 3.2
 * @ mongodb . server . release 3.2
 * @ mongodb . driver . manual reference / readConcern / Read Concern */
ReadConcern getReadConcern ( ) { } }

implementation: ReadConcern readConcern = findOptions . getReadConcern ( ) ; if ( readConcern != null ) { return readConcern ; } return collection . getReadConcern ( ) ;


signature:
public class DBCursor { /** * Sets the factory that will be used create a { @ code DBDecoder } that will be used to decode BSON documents into DBObject instances .
 * @ param factory the DBDecoderFactory
 * @ return { @ code this } so calls can be chained */
public DBCursor setDecoderFactory ( final DBDecoderFactory factory ) { } }

implementation:
this . decoderFactory = factory ; // Not creating new CompoundDBObjectCodec because we don ' t care about encoder .
this . decoder = new DBDecoderAdapter ( factory . create ( ) , collection , getCollection ( ) . getBufferPool ( ) ) ; return this ;


signature:
public class BasicBSONCallback { /** * Puts a new value into the document .
 * @ param name the name of the field
 * @ param value the value */
protected void _put ( final String name , final Object value ) { } }

implementation: cur ( ) . put ( name , ! BSON . hasDecodeHooks ( ) ? value : BSON . applyDecodingHooks ( value ) ) ;


signature:
public class DefaultDBEncoder { /** * Deals with encoding database references .
 * @ param name the name of the field in the document
 * @ param ref the database reference object */
protected void putDBRef ( final String name , final DBRef ref ) { } }

implementation: BasicDBObject dbRefDocument = new BasicDBObject ( "$ref" , ref . getCollectionName ( ) ) . append ( "$id" , ref . getId ( ) ) ; if ( ref . getDatabaseName ( ) != null ) { dbRefDocument . put ( "$db" , ref . getDatabaseName ( ) ) ; } putObject ( name , dbRefDocument ) ;


signature:
public class PojoQuickTour { /** * Run this main method to see the output of this quick example .
 * @ param args takes an optional single argument for the connection string */
public static void main ( final String [ ] args ) { } }

implementation:
MongoClient mongoClient ; if ( args . length == 0 ) { // connect to the local database server
mongoClient = MongoClients . create ( ) ; } else { mongoClient = MongoClients . create ( args [ 0 ] ) ; } // create codec registry for POJOs
CodecRegistry pojoCodecRegistry = fromRegistries ( MongoClientSettings . getDefaultCodecRegistry ( ) , fromProviders ( PojoCodecProvider . builder ( ) . automatic ( true ) . build ( ) ) ) ; // get handle to " mydb " database
MongoDatabase database = mongoClient . getDatabase ( "mydb" ) . withCodecRegistry ( pojoCodecRegistry ) ; // get a handle to the " people " collection
MongoCollection < Person > collection = database . getCollection ( "people" , Person . class ) ; // drop all the data in it
collection . drop ( ) ; // make a document and insert it
Person ada = new Person ( "Ada Byron" , 20 , new Address ( "St James Square" , "London" , "W1" ) ) ; System . out . println ( "Original Person Model: " + ada ) ; collection . insertOne ( ada ) ; // Person will now have an ObjectId
System . out . println ( "Mutated Person Model: " + ada ) ; // get it ( since it ' s the only one in there since we dropped the rest earlier on )
Person somebody = collection . find ( ) . first ( ) ; System . out . println ( somebody ) ; // now , lets add some more people so we can explore queries and cursors
List < Person > people = asList ( new Person ( "Charles Babbage" , 45 , new Address ( "5 Devonshire Street" , "London" , "W11" ) ) , new Person ( "Alan Turing" , 28 , new Address ( "Bletchley Hall" , "Bletchley Park" , "MK12" ) ) , new Person ( "Timothy Berners-Lee" , 61 , new Address ( "Colehill" , "Wimborne" , null ) ) ) ; collection . insertMany ( people ) ; System . out . println ( "total # of people " + collection . countDocuments ( ) ) ; System . out . println ( "" ) ; // lets get all the documents in the collection and print them out
Block < Person > printBlock = new Block < Person > ( ) { @ Override public void apply ( final Person person ) { System . out . println ( person ) ; } } ; collection . find ( ) . forEach ( printBlock ) ; System . out . println ( "" ) ; // now use a query to get 1 document out
somebody = collection . find ( eq ( "address.city" , "Wimborne" ) ) . first ( ) ; System . out . println ( somebody ) ; System . out . println ( "" ) ; // now lets find every over 30
collection . find ( gt ( "age" , 30 ) ) . forEach ( printBlock ) ; System . out . println ( "" ) ; // Update One
collection . updateOne ( eq ( "name" , "Ada Byron" ) , combine ( set ( "age" , 23 ) , set ( "name" , "Ada Lovelace" ) ) ) ; System . out . println ( "" ) ; // Update Many
UpdateResult updateResult = collection . updateMany ( not ( eq ( "zip" , null ) ) , set ( "zip" , null ) ) ; System . out . println ( updateResult . getModifiedCount ( ) ) ; System . out . println ( "" ) ; // Replace One
updateResult = collection . replaceOne ( eq ( "name" , "Ada Lovelace" ) , ada ) ; System . out . println ( updateResult . getModifiedCount ( ) ) ; // Delete One
collection . deleteOne ( eq ( "address.city" , "Wimborne" ) ) ; // Delete Many
DeleteResult deleteResult = collection . deleteMany ( eq ( "address.city" , "London" ) ) ; System . out . println ( deleteResult . getDeletedCount ( ) ) ; // Clean up
database . drop ( ) ; // release resources
mongoClient . close ( ) ;


signature:
public class BulkWriteResult { /** * Create an acknowledged BulkWriteResult
 * @ param type the type of the write
 * @ param count the number of documents matched
 * @ param upserts the list of upserts
 * @ return an acknowledged BulkWriteResult */
public static BulkWriteResult acknowledged ( final WriteRequest . Type type , final int count , final List < BulkWriteUpsert > upserts ) { } }

implementation: return acknowledged ( type , count , 0 , upserts ) ;


signature:
public class BulkWriteResult { /** * Create an acknowledged BulkWriteResult
 * @ param type the type of the write
 * @ param count the number of documents matched
 * @ param modifiedCount the number of documents modified , which may be null if the server was not able to provide the count
 * @ param upserts the list of upserts
 * @ return an acknowledged BulkWriteResult */
public static BulkWriteResult acknowledged ( final WriteRequest . Type type , final int count , final Integer modifiedCount , final List < BulkWriteUpsert > upserts ) { } }

implementation: return acknowledged ( type == WriteRequest . Type . INSERT ? count : 0 , ( type == WriteRequest . Type . UPDATE || type == WriteRequest . Type . REPLACE ) ? count : 0 , type == WriteRequest . Type . DELETE ? count : 0 , modifiedCount , upserts ) ;


signature:
public class BulkWriteResult { /** * Create an acknowledged BulkWriteResult
 * @ param insertedCount the number of documents inserted by the write operation
 * @ param matchedCount the number of documents matched by the write operation
 * @ param removedCount the number of documents removed by the write operation
 * @ param modifiedCount the number of documents modified , which may not be null
 * @ param upserts the list of upserts
 * @ return an acknowledged BulkWriteResult */
public static BulkWriteResult acknowledged ( final int insertedCount , final int matchedCount , final int removedCount , final Integer modifiedCount , final List < BulkWriteUpsert > upserts ) { } }

implementation: return new BulkWriteResult ( ) { @ Override public boolean wasAcknowledged ( ) { return true ; } @ Override public int getInsertedCount ( ) { return insertedCount ; } @ Override public int getMatchedCount ( ) { return matchedCount ; } @ Override public int getDeletedCount ( ) { return removedCount ; } @ Override @ Deprecated public boolean isModifiedCountAvailable ( ) { return true ; } @ Override public int getModifiedCount ( ) { return modifiedCount ; } @ Override public List < BulkWriteUpsert > getUpserts ( ) { return upserts ; } @ Override public boolean equals ( final Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } BulkWriteResult that = ( BulkWriteResult ) o ; if ( ! that . wasAcknowledged ( ) ) { return false ; } if ( insertedCount != that . getInsertedCount ( ) ) { return false ; } if ( modifiedCount != null && ! modifiedCount . equals ( that . getModifiedCount ( ) ) ) { return false ; } if ( removedCount != that . getDeletedCount ( ) ) { return false ; } if ( matchedCount != that . getMatchedCount ( ) ) { return false ; } if ( ! upserts . equals ( that . getUpserts ( ) ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { int result = upserts . hashCode ( ) ; result = 31 * result + insertedCount ; result = 31 * result + matchedCount ; result = 31 * result + removedCount ; result = 31 * result + ( modifiedCount != null ? modifiedCount . hashCode ( ) : 0 ) ; return result ; } @ Override public String toString ( ) { return "AcknowledgedBulkWriteResult{" + "insertedCount=" + insertedCount + ", matchedCount=" + matchedCount + ", removedCount=" + removedCount + ", modifiedCount=" + modifiedCount + ", upserts=" + upserts + '}' ; } } ;


signature:
public class BulkWriteResult { /** * Create an unacknowledged BulkWriteResult
 * @ return an unacknowledged BulkWriteResult */
public static BulkWriteResult unacknowledged ( ) { } }

implementation: return new BulkWriteResult ( ) { @ Override public boolean wasAcknowledged ( ) { return false ; } @ Override public int getInsertedCount ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override public int getMatchedCount ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override public int getDeletedCount ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override @ Deprecated public boolean isModifiedCountAvailable ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override public int getModifiedCount ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override public List < BulkWriteUpsert > getUpserts ( ) { throw getUnacknowledgedWriteException ( ) ; } @ Override public boolean equals ( final Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } BulkWriteResult that = ( BulkWriteResult ) o ; return ! that . wasAcknowledged ( ) ; } @ Override public int hashCode ( ) { return 0 ; } @ Override public String toString ( ) { return "UnacknowledgedBulkWriteResult{}" ; } private UnsupportedOperationException getUnacknowledgedWriteException ( ) { return new UnsupportedOperationException ( "Cannot get information about an unacknowledged write" ) ; } } ;


signature:
public class AggregateOperation { /** * Sets the maximum await execution time on the server for this operation .
 * @ param maxAwaitTime the max await time . A value less than one will be ignored , and indicates that the driver should respect the
 * server ' s default value
 * @ param timeUnit the time unit , which may not be null
 * @ return this
 * @ mongodb . server . release 3.6 */
public AggregateOperation < T > maxAwaitTime ( final long maxAwaitTime , final TimeUnit timeUnit ) { } }

implementation: wrapped . maxAwaitTime ( maxAwaitTime , timeUnit ) ; return this ;


signature:
public class AggregateOperation { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this
 * @ mongodb . driver . manual reference / method / cursor . maxTimeMS / # cursor . maxTimeMS Max Time */
public AggregateOperation < T > maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: wrapped . maxTime ( maxTime , timeUnit ) ; return this ;


signature:
public class AggregateOperation { /** * Returns the hint for which index to use . The default is not to set a hint .
 * @ return the hint
 * @ since 3.6
 * @ mongodb . server . release 3.6 */
public BsonDocument getHint ( ) { } }

implementation: BsonValue hint = wrapped . getHint ( ) ; if ( hint == null ) { return null ; } if ( ! hint . isDocument ( ) ) { throw new IllegalArgumentException ( "Hint is not a BsonDocument please use the #getHintBsonValue() method. " ) ; } return hint . asDocument ( ) ;


signature:
public class AggregateOperation { /** * Gets an operation whose execution explains this operation .
 * @ param explainVerbosity the explain verbosity
 * @ return a read operation that when executed will explain this operation */
public ReadOperation < BsonDocument > asExplainableOperation ( final ExplainVerbosity explainVerbosity ) { } }

implementation: return new AggregateExplainOperation ( getNamespace ( ) , getPipeline ( ) ) . allowDiskUse ( getAllowDiskUse ( ) ) . maxTime ( getMaxAwaitTime ( TimeUnit . MILLISECONDS ) , TimeUnit . MILLISECONDS ) . hint ( wrapped . getHint ( ) ) . retryReads ( getRetryReads ( ) ) ;


signature:
public class ServerAddress { /** * Gets the underlying socket address
 * @ return socket address */
public InetSocketAddress getSocketAddress ( ) { } }

implementation: try { return new InetSocketAddress ( InetAddress . getByName ( host ) , port ) ; } catch ( UnknownHostException e ) { throw new MongoSocketException ( e . getMessage ( ) , this , e ) ; }


signature:
public class ServerAddress { /** * Gets all underlying socket addresses
 * @ return array of socket addresses
 * @ since 3.9 */
public List < InetSocketAddress > getSocketAddresses ( ) { } }

implementation: try { InetAddress [ ] inetAddresses = InetAddress . getAllByName ( host ) ; List < InetSocketAddress > inetSocketAddressList = new ArrayList < InetSocketAddress > ( ) ; for ( InetAddress inetAddress : inetAddresses ) { inetSocketAddressList . add ( new InetSocketAddress ( inetAddress , port ) ) ; } return inetSocketAddressList ; } catch ( UnknownHostException e ) { throw new MongoSocketException ( e . getMessage ( ) , this , e ) ; }


signature:
public class FindOneAndDeleteOptions { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this */
public FindOneAndDeleteOptions maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: notNull ( "timeUnit" , timeUnit ) ; this . maxTimeMS = MILLISECONDS . convert ( maxTime , timeUnit ) ; return this ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field name equals the specified value . Note that this doesn ' t
 * actually generate a $ eq operator , as the query language doesn ' t require it .
 * @ param fieldName the field name
 * @ param value the value , which may be null
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / eq $ eq */
public static < TItem > Bson eq ( final String fieldName , @ Nullable final TItem value ) { } }

implementation: return new SimpleEncodingFilter < TItem > ( fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field name does not equal the specified value .
 * @ param fieldName the field name
 * @ param value the value , which may be null
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / ne $ ne */
public static < TItem > Bson ne ( final String fieldName , @ Nullable final TItem value ) { } }

implementation: return new OperatorFilter < TItem > ( "$ne" , fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the given field is greater than the specified value .
 * @ param fieldName the field name
 * @ param value the value
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / gt $ gt */
public static < TItem > Bson gt ( final String fieldName , final TItem value ) { } }

implementation: return new OperatorFilter < TItem > ( "$gt" , fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the given field is less than the specified value .
 * @ param fieldName the field name
 * @ param value the value
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / lt $ lt */
public static < TItem > Bson lt ( final String fieldName , final TItem value ) { } }

implementation: return new OperatorFilter < TItem > ( "$lt" , fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the given field is greater than or equal to the specified value .
 * @ param fieldName the field name
 * @ param value the value
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / gte $ gte */
public static < TItem > Bson gte ( final String fieldName , final TItem value ) { } }

implementation: return new OperatorFilter < TItem > ( "$gte" , fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the given field is less than or equal to the specified value .
 * @ param fieldName the field name
 * @ param value the value
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / lte $ lte */
public static < TItem > Bson lte ( final String fieldName , final TItem value ) { } }

implementation: return new OperatorFilter < TItem > ( "$lte" , fieldName , value ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field equals any value in the list of specified values .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / in $ in */
public static < TItem > Bson in ( final String fieldName , final TItem ... values ) { } }

implementation: return in ( fieldName , asList ( values ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field equals any value in the list of specified values .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / in $ in */
public static < TItem > Bson in ( final String fieldName , final Iterable < TItem > values ) { } }

implementation: return new IterableOperatorFilter < TItem > ( fieldName , "$in" , values ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / nin $ nin */
public static < TItem > Bson nin ( final String fieldName , final TItem ... values ) { } }

implementation: return nin ( fieldName , asList ( values ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field does not equal any of the specified values or does not exist .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / nin $ nin */
public static < TItem > Bson nin ( final String fieldName , final Iterable < TItem > values ) { } }

implementation: return new IterableOperatorFilter < TItem > ( fieldName , "$nin" , values ) ;


signature:
public class Filters { /** * Creates a filter that preforms a logical OR of the provided list of filters .
 * @ param filters the list of filters to and together
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / or $ or */
public static Bson or ( final Iterable < Bson > filters ) { } }

implementation: return new OrNorFilter ( OrNorFilter . Operator . OR , filters ) ;


signature:
public class Filters { /** * Creates a filter that performs a logical NOR operation on all the specified filters .
 * @ param filters the list of values
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / nor $ nor */
public static Bson nor ( final Iterable < Bson > filters ) { } }

implementation: return new OrNorFilter ( OrNorFilter . Operator . NOR , filters ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents that either contain or do not contain the given field , depending on the value of the
 * exists parameter .
 * @ param fieldName the field name
 * @ param exists true to check for existence , false to check for absence
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / exists $ exists */
public static Bson exists ( final String fieldName , final boolean exists ) { } }

implementation: return new OperatorFilter < BsonBoolean > ( "$exists" , fieldName , BsonBoolean . valueOf ( exists ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field is of the specified BSON type .
 * @ param fieldName the field name
 * @ param type the BSON type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / type $ type */
public static Bson type ( final String fieldName , final BsonType type ) { } }

implementation: return new OperatorFilter < BsonInt32 > ( "$type" , fieldName , new BsonInt32 ( type . getValue ( ) ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field is of the specified BSON type .
 * @ param fieldName the field name
 * @ param type the string representation of the BSON type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / type $ type */
public static Bson type ( final String fieldName , final String type ) { } }

implementation: return new OperatorFilter < BsonString > ( "$type" , fieldName , new BsonString ( type ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field divided by a divisor has the specified remainder ( i . e . perform
 * a modulo operation to select documents ) .
 * @ param fieldName the field name
 * @ param divisor the modulus
 * @ param remainder the remainder
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / mod $ mod */
public static Bson mod ( final String fieldName , final long divisor , final long remainder ) { } }

implementation: return new OperatorFilter < BsonArray > ( "$mod" , fieldName , new BsonArray ( asList ( new BsonInt64 ( divisor ) , new BsonInt64 ( remainder ) ) ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
 * options applied .
 * @ param fieldName the field name
 * @ param pattern the pattern
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / regex $ regex */
public static Bson regex ( final String fieldName , final String pattern ) { } }

implementation: return regex ( fieldName , pattern , null ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
 * options applied .
 * @ param fieldName the field name
 * @ param pattern the pattern
 * @ param options the options
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / regex $ regex */
public static Bson regex ( final String fieldName , final String pattern , @ Nullable final String options ) { } }

implementation: notNull ( "pattern" , pattern ) ; return new SimpleFilter ( fieldName , new BsonRegularExpression ( pattern , options ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of the field matches the given regular expression pattern with the given
 * options applied .
 * @ param fieldName the field name
 * @ param pattern the pattern
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / regex $ regex */
public static Bson regex ( final String fieldName , final Pattern pattern ) { } }

implementation: notNull ( "pattern" , pattern ) ; return new SimpleEncodingFilter < Pattern > ( fieldName , pattern ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents matching the given search term using the given language .
 * @ param search the search term
 * @ param language the language to use for stop words
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / text $ text
 * @ deprecated use { @ link Filters # text ( String , TextSearchOptions ) } */
@ Deprecated public static Bson text ( final String search , final String language ) { } }

implementation: notNull ( "search" , search ) ; return text ( search , new TextSearchOptions ( ) . language ( language ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents matching the given the search term with the given text search options .
 * @ param search the search term
 * @ param textSearchOptions the text search options to use
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / text $ text
 * @ since 3.2 */
public static Bson text ( final String search , final TextSearchOptions textSearchOptions ) { } }

implementation: notNull ( "search" , search ) ; notNull ( "textSearchOptions" , textSearchOptions ) ; return new TextFilter ( search , textSearchOptions ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field is an array that contains all the specified values .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / all $ all */
public static < TItem > Bson all ( final String fieldName , final TItem ... values ) { } }

implementation: return all ( fieldName , asList ( values ) ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents where the value of a field is an array that contains all the specified values .
 * @ param fieldName the field name
 * @ param values the list of values
 * @ param < TItem > the value type
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / all $ all */
public static < TItem > Bson all ( final String fieldName , final Iterable < TItem > values ) { } }

implementation: return new IterableOperatorFilter < TItem > ( fieldName , "$all" , values ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field that is an array where at least one member of the array matches the
 * given filter .
 * @ param fieldName the field name
 * @ param filter the filter to apply to each element
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / elemMatch $ elemMatch */
public static Bson elemMatch ( final String fieldName , final Bson filter ) { } }

implementation: return new Bson ( ) { @ Override public < TDocument > BsonDocument toBsonDocument ( final Class < TDocument > documentClass , final CodecRegistry codecRegistry ) { return new BsonDocument ( fieldName , new BsonDocument ( "$elemMatch" , filter . toBsonDocument ( documentClass , codecRegistry ) ) ) ; } } ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape .
 * @ param fieldName the field name
 * @ param geometry the bounding GeoJSON geometry object
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . server . release 2.4 */
public static Bson geoWithin ( final String fieldName , final Geometry geometry ) { } }

implementation: return new GeometryOperatorFilter < Geometry > ( "$geoWithin" , fieldName , geometry ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that exists entirely within the specified shape .
 * @ param fieldName the field name
 * @ param geometry the bounding GeoJSON geometry object
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . server . release 2.4 */
public static Bson geoWithin ( final String fieldName , final Bson geometry ) { } }

implementation: return new GeometryOperatorFilter < Bson > ( "$geoWithin" , fieldName , geometry ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
 * box .
 * @ param fieldName the field name
 * @ param lowerLeftX the lower left x coordinate of the box
 * @ param lowerLeftY the lower left y coordinate of the box
 * @ param upperRightX the upper left x coordinate of the box
 * @ param upperRightY the upper left y coordinate of the box
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . driver . manual reference / operator / query / box / # op . _ S _ box $ box
 * @ mongodb . server . release 2.4
 * @ since 3.1 */
public static Bson geoWithinBox ( final String fieldName , final double lowerLeftX , final double lowerLeftY , final double upperRightX , final double upperRightY ) { } }

implementation: BsonDocument box = new BsonDocument ( "$box" , new BsonArray ( asList ( new BsonArray ( asList ( new BsonDouble ( lowerLeftX ) , new BsonDouble ( lowerLeftY ) ) ) , new BsonArray ( asList ( new BsonDouble ( upperRightX ) , new BsonDouble ( upperRightY ) ) ) ) ) ) ; return new OperatorFilter < BsonDocument > ( "$geoWithin" , fieldName , box ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
 * polygon .
 * @ param fieldName the field name
 * @ param points a list of pairs of x , y coordinates . Any extra dimensions are ignored
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . driver . manual reference / operator / query / polygon / # op . _ S _ polygon $ polygon
 * @ mongodb . server . release 2.4
 * @ since 3.1 */
public static Bson geoWithinPolygon ( final String fieldName , final List < List < Double > > points ) { } }

implementation: BsonArray pointsArray = new BsonArray ( ) ; for ( List < Double > point : points ) { pointsArray . add ( new BsonArray ( asList ( new BsonDouble ( point . get ( 0 ) ) , new BsonDouble ( point . get ( 1 ) ) ) ) ) ; } BsonDocument polygon = new BsonDocument ( "$polygon" , pointsArray ) ; return new OperatorFilter < BsonDocument > ( "$geoWithin" , fieldName , polygon ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
 * circle .
 * @ param fieldName the field name
 * @ param x the x coordinate of the circle
 * @ param y the y coordinate of the circle
 * @ param radius the radius of the circle , as measured in the units used by the coordinate system
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . driver . manual reference / operator / query / center / # op . _ S _ center $ center
 * @ mongodb . server . release 2.4
 * @ since 3.1 */
public static Bson geoWithinCenter ( final String fieldName , final double x , final double y , final double radius ) { } }

implementation: BsonDocument center = new BsonDocument ( "$center" , new BsonArray ( Arrays . < BsonValue > asList ( new BsonArray ( asList ( new BsonDouble ( x ) , new BsonDouble ( y ) ) ) , new BsonDouble ( radius ) ) ) ) ; return new OperatorFilter < BsonDocument > ( "$geoWithin" , fieldName , center ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data ( GeoJSON or legacy coordinate pairs ) that exist
 * entirely within the specified circle , using spherical geometry . If using longitude and latitude , specify longitude first .
 * @ param fieldName the field name
 * @ param x the x coordinate of the circle
 * @ param y the y coordinate of the circle
 * @ param radius the radius of the circle , in radians
 * @ return the filter
 * @ mongodb . driver . manual reference / operator / query / geoWithin / $ geoWithin
 * @ mongodb . driver . manual reference / operator / query / centerSphere / # op . _ S _ centerSphere $ centerSphere
 * @ mongodb . server . release 2.4
 * @ since 3.1 */
public static Bson geoWithinCenterSphere ( final String fieldName , final double x , final double y , final double radius ) { } }

implementation: BsonDocument centerSphere = new BsonDocument ( "$centerSphere" , new BsonArray ( Arrays . < BsonValue > asList ( new BsonArray ( asList ( new BsonDouble ( x ) , new BsonDouble ( y ) ) ) , new BsonDouble ( radius ) ) ) ) ; return new OperatorFilter < BsonDocument > ( "$geoWithin" , fieldName , centerSphere ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape .
 * @ param fieldName the field name
 * @ param geometry the bounding GeoJSON geometry object
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / geoIntersects / $ geoIntersects
 * @ mongodb . server . release 2.4 */
public static Bson geoIntersects ( final String fieldName , final Bson geometry ) { } }

implementation: return new GeometryOperatorFilter < Bson > ( "$geoIntersects" , fieldName , geometry ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that intersects with the specified shape .
 * @ param fieldName the field name
 * @ param geometry the bounding GeoJSON geometry object
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / geoIntersects / $ geoIntersects
 * @ mongodb . server . release 2.4 */
public static Bson geoIntersects ( final String fieldName , final Geometry geometry ) { } }

implementation: return new GeometryOperatorFilter < Geometry > ( "$geoIntersects" , fieldName , geometry ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that is near the specified GeoJSON point .
 * @ param fieldName the field name
 * @ param geometry the bounding GeoJSON geometry object
 * @ param maxDistance the maximum distance from the point , in meters . It may be null .
 * @ param minDistance the minimum distance from the point , in meters . It may be null .
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / near / $ near
 * @ mongodb . server . release 2.4 */
public static Bson near ( final String fieldName , final Point geometry , @ Nullable final Double maxDistance , @ Nullable final Double minDistance ) { } }

implementation: return new GeometryOperatorFilter < Point > ( "$near" , fieldName , geometry , maxDistance , minDistance ) ;


signature:
public class Filters { /** * Creates a filter that matches all documents containing a field with geospatial data that is near the specified point .
 * @ param fieldName the field name
 * @ param x the x coordinate
 * @ param y the y coordinate
 * @ param maxDistance the maximum distance from the point , in radians . It may be null .
 * @ param minDistance the minimum distance from the point , in radians . It may be null .
 * @ return the filter
 * @ since 3.1
 * @ mongodb . driver . manual reference / operator / query / near / $ near
 * @ mongodb . server . release 2.4 */
public static Bson near ( final String fieldName , final double x , final double y , @ Nullable final Double maxDistance , @ Nullable final Double minDistance ) { } }

implementation: return createNearFilterDocument ( fieldName , x , y , maxDistance , minDistance , "$near" ) ;


signature:
public class MongoClientOptions { /** * < p > The socket factory for creating sockets to the mongo server . < / p >
 * < p > Default is SocketFactory . getDefault ( ) < / p >
 * @ return the socket factory
 * @ deprecated Prefer { @ link # isSslEnabled ( ) } and { @ link # getSslContext ( ) } */
@ Deprecated public SocketFactory getSocketFactory ( ) { } }

implementation: if ( socketFactory != null ) { return socketFactory ; } else if ( getSslSettings ( ) . isEnabled ( ) ) { return sslContext == null ? DEFAULT_SSL_SOCKET_FACTORY : sslContext . getSocketFactory ( ) ; } else { return DEFAULT_SOCKET_FACTORY ; }


signature:
public class CountOperation { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this */
public CountOperation maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: notNull ( "timeUnit" , timeUnit ) ; this . maxTimeMS = TimeUnit . MILLISECONDS . convert ( maxTime , timeUnit ) ; return this ;


signature:
public class CountOperation { /** * Gets an operation whose execution explains this operation .
 * @ param explainVerbosity the explain verbosity
 * @ return a read operation that when executed will explain this operation */
public ReadOperation < BsonDocument > asExplainableOperation ( final ExplainVerbosity explainVerbosity ) { } }

implementation: if ( countStrategy . equals ( CountStrategy . COMMAND ) ) { return createExplainableOperation ( explainVerbosity ) ; } else { return getAggregateOperation ( ) . asExplainableOperation ( explainVerbosity ) ; }


signature:
public class CountOperation { /** * Gets an operation whose execution explains this operation .
 * @ param explainVerbosity the explain verbosity
 * @ return a read operation that when executed will explain this operation */
public AsyncReadOperation < BsonDocument > asExplainableOperationAsync ( final ExplainVerbosity explainVerbosity ) { } }

implementation: if ( countStrategy . equals ( CountStrategy . COMMAND ) ) { return createExplainableOperation ( explainVerbosity ) ; } else { return getAggregateOperation ( ) . asExplainableOperationAsync ( explainVerbosity ) ; }


signature:
public class BsonArrayCodec { /** * This method may be overridden to change the behavior of reading the current value from the given { @ code BsonReader } . It is required
 * that the value be fully consumed before returning .
 * @ param reader the read to read the value from
 * @ param decoderContext the decoder context
 * @ return the non - null value read from the reader */
protected BsonValue readValue ( final BsonReader reader , final DecoderContext decoderContext ) { } }

implementation: return codecRegistry . get ( BsonValueCodecProvider . getClassForBsonType ( reader . getCurrentBsonType ( ) ) ) . decode ( reader , decoderContext ) ;


signature:
public class BSON { /** * Registers a { @ code Transformer } to use to encode a specific class into BSON .
 * @ param clazz the class to be transformed during encoding
 * @ param transformer the transformer to use during encoding */
public static void addEncodingHook ( final Class < ? > clazz , final Transformer transformer ) { } }

implementation: encodeHooks = true ; List < Transformer > transformersForClass = encodingHooks . get ( clazz ) ; if ( transformersForClass == null ) { transformersForClass = new CopyOnWriteArrayList < Transformer > ( ) ; encodingHooks . put ( clazz , transformersForClass ) ; } transformersForClass . add ( transformer ) ;


signature:
public class BSON { /** * Registers a { @ code Transformer } to use when decoding a specific class from BSON . This class will be one of the basic types supported
 * by BSON .
 * @ param clazz the class to be transformed during decoding
 * @ param transformer the transformer to use during decoding */
public static void addDecodingHook ( final Class < ? > clazz , final Transformer transformer ) { } }

implementation: decodeHooks = true ; List < Transformer > transformersForClass = decodingHooks . get ( clazz ) ; if ( transformersForClass == null ) { transformersForClass = new CopyOnWriteArrayList < Transformer > ( ) ; decodingHooks . put ( clazz , transformersForClass ) ; } transformersForClass . add ( transformer ) ;


signature:
public class BSON { /** * Transforms the { @ code objectToEncode } using all transformers registered for the class of this object .
 * @ param objectToEncode the object being written to BSON .
 * @ return the transformed object */
public static Object applyEncodingHooks ( final Object objectToEncode ) { } }

implementation: Object transformedObject = objectToEncode ; if ( ! hasEncodeHooks ( ) || objectToEncode == null || encodingHooks . size ( ) == 0 ) { return transformedObject ; } List < Transformer > transformersForObject = encodingHooks . get ( objectToEncode . getClass ( ) ) ; if ( transformersForObject != null ) { for ( final Transformer transformer : transformersForObject ) { transformedObject = transformer . transform ( objectToEncode ) ; } } return transformedObject ;


signature:
public class BSON { /** * Transforms the { @ code objectToDecode } using all transformers registered for the class of this object .
 * @ param objectToDecode the BSON object to decode
 * @ return the transformed object */
public static Object applyDecodingHooks ( final Object objectToDecode ) { } }

implementation: Object transformedObject = objectToDecode ; if ( ! hasDecodeHooks ( ) || objectToDecode == null || decodingHooks . size ( ) == 0 ) { return transformedObject ; } List < Transformer > transformersForObject = decodingHooks . get ( objectToDecode . getClass ( ) ) ; if ( transformersForObject != null ) { for ( final Transformer transformer : transformersForObject ) { transformedObject = transformer . transform ( objectToDecode ) ; } } return transformedObject ;


signature:
public class BSON { /** * Converts a sequence of regular expression modifiers from the database into Java regular expression flags .
 * @ param s regular expression modifiers
 * @ return the Java flags
 * @ throws IllegalArgumentException If sequence contains invalid flags . */
public static int regexFlags ( final String s ) { } }

implementation: int flags = 0 ; if ( s == null ) { return flags ; } for ( final char f : s . toLowerCase ( ) . toCharArray ( ) ) { flags |= regexFlag ( f ) ; } return flags ;


signature:
public class BSON { /** * Converts a regular expression modifier from the database into Java regular expression flags .
 * @ param c regular expression modifier
 * @ return the Java flags
 * @ throws IllegalArgumentException If sequence contains invalid flags . */
public static int regexFlag ( final char c ) { } }

implementation: int flag = FLAG_LOOKUP [ c ] ; if ( flag == 0 ) { throw new IllegalArgumentException ( String . format ( "Unrecognized flag [%c]" , c ) ) ; } return flag ;


signature:
public class BSON { /** * Converts Java regular expression flags into regular expression modifiers from the database .
 * @ param flags the Java flags
 * @ return the Java flags
 * @ throws IllegalArgumentException if some flags couldn ' t be recognized . */
public static String regexFlags ( final int flags ) { } }

implementation: int processedFlags = flags ; StringBuilder buf = new StringBuilder ( ) ; for ( int i = 0 ; i < FLAG_LOOKUP . length ; i ++ ) { if ( ( processedFlags & FLAG_LOOKUP [ i ] ) > 0 ) { buf . append ( ( char ) i ) ; processedFlags -= FLAG_LOOKUP [ i ] ; } } if ( processedFlags > 0 ) { throw new IllegalArgumentException ( "Some flags could not be recognized." ) ; } return buf . toString ( ) ;


signature:
public class BSON { /** * Provides an integer representation of Boolean or Number . If argument is { @ link Boolean } , then { @ code 1 } for { @ code true } will be
 * returned or @ { code 0 } otherwise . If argument is { @ code Number } , then { @ link Number # intValue ( ) } will be called .
 * @ param number the number to convert to an int
 * @ return integer value
 * @ throws IllegalArgumentException if the argument is { @ code null } or not { @ link Boolean } or { @ link Number } */
public static int toInt ( final Object number ) { } }

implementation: if ( number == null ) { throw new IllegalArgumentException ( "Argument shouldn't be null" ) ; } if ( number instanceof Number ) { return ( ( Number ) number ) . intValue ( ) ; } if ( number instanceof Boolean ) { return ( ( Boolean ) number ) ? 1 : 0 ; } throw new IllegalArgumentException ( "Can't convert: " + number . getClass ( ) . getName ( ) + " to int" ) ;


signature:
public class IndexRequest { /** * Sets the time to live for documents in the collection
 * @ param expireAfter the time to live for documents in the collection
 * @ param timeUnit the time unit
 * @ return this
 * @ mongodb . driver . manual tutorial / expire - data TTL */
public IndexRequest expireAfter ( final Long expireAfter , final TimeUnit timeUnit ) { } }

implementation: if ( expireAfter == null ) { this . expireAfterSeconds = null ; } else { this . expireAfterSeconds = TimeUnit . SECONDS . convert ( expireAfter , timeUnit ) ; } return this ;


signature:
public class IndexRequest { /** * Set the text index version number .
 * @ param textVersion the text index version number .
 * @ return this */
public IndexRequest textVersion ( final Integer textVersion ) { } }

implementation: if ( textVersion != null ) { isTrueArgument ( "textVersion must be 1, 2 or 3" , VALID_TEXT_INDEX_VERSIONS . contains ( textVersion ) ) ; } this . textVersion = textVersion ; return this ;


signature:
public class IndexRequest { /** * Sets the 2dsphere index version number .
 * @ param sphereVersion the 2dsphere index version number .
 * @ return this */
public IndexRequest sphereVersion ( final Integer sphereVersion ) { } }

implementation: if ( sphereVersion != null ) { isTrueArgument ( "sphereIndexVersion must be 1, 2 or 3" , VALID_SPHERE_INDEX_VERSIONS . contains ( sphereVersion ) ) ; } this . sphereVersion = sphereVersion ; return this ;


signature:
public class DBCollectionFindOptions { /** * Copy this DBCollectionFindOptions instance into a new instance .
 * @ return the new DBCollectionFindOptions with the same settings as this instance . */
public DBCollectionFindOptions copy ( ) { } }

implementation: DBCollectionFindOptions copiedOptions = new DBCollectionFindOptions ( ) ; copiedOptions . batchSize ( batchSize ) ; copiedOptions . limit ( limit ) ; copiedOptions . modifiers ( modifiers ) ; copiedOptions . projection ( projection ) ; copiedOptions . maxTime ( maxTimeMS , TimeUnit . MILLISECONDS ) ; copiedOptions . maxAwaitTime ( maxAwaitTimeMS , TimeUnit . MILLISECONDS ) ; copiedOptions . skip ( skip ) ; copiedOptions . sort ( sort ) ; copiedOptions . cursorType ( cursorType ) ; copiedOptions . noCursorTimeout ( noCursorTimeout ) ; copiedOptions . oplogReplay ( oplogReplay ) ; copiedOptions . partial ( partial ) ; copiedOptions . readPreference ( readPreference ) ; copiedOptions . readConcern ( readConcern ) ; copiedOptions . collation ( collation ) ; copiedOptions . comment ( comment ) ; copiedOptions . hint ( hint ) ; copiedOptions . max ( max ) ; copiedOptions . min ( min ) ; copiedOptions . returnKey ( returnKey ) ; copiedOptions . showRecordId ( showRecordId ) ; return copiedOptions ;


signature:
public class DBCollectionFindOptions { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this
 * @ mongodb . driver . manual reference / method / cursor . maxTimeMS / # cursor . maxTimeMS Max Time */
public DBCollectionFindOptions maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: notNull ( "timeUnit" , timeUnit ) ; isTrueArgument ( "maxTime > = 0" , maxTime >= 0 ) ; this . maxTimeMS = TimeUnit . MILLISECONDS . convert ( maxTime , timeUnit ) ; return this ;


signature:
public class Util { /** * Produce hex representation of the MD5 digest of a byte array .
 * @ param buf byte buffer containing the bytes to digest
 * @ param offset the position to start reading bytes from
 * @ param len the number of bytes to read from the buffer
 * @ return hex string of the MD5 digest */
public static String hexMD5 ( final ByteBuffer buf , final int offset , final int len ) { } }

implementation: return HexUtils . hexMD5 ( buf , offset , len ) ;


signature:
public class Assertions { /** * Throw IllegalArgumentException if the condition if false , otherwise return the value . This is useful when arguments must be checked
 * within an expression , as when using { @ code this } to call another constructor , which must be the first line of the calling
 * constructor .
 * @ param < T > the value type
 * @ param name the name of the state that is being checked
 * @ param value the value of the argument
 * @ param condition the condition about the parameter to check
 * @ return the value
 * @ throws java . lang . IllegalArgumentException if the condition is false */
public static < T > T isTrueArgument ( final String name , final T value , final boolean condition ) { } }

implementation: if ( ! condition ) { throw new IllegalArgumentException ( "state should be: " + name ) ; } return value ;


signature:
public class Assertions { /** * Cast an object to the given class and return it , or throw IllegalArgumentException if it ' s not assignable to that class .
 * @ param clazz the class to cast to
 * @ param value the value to cast
 * @ param errorMessage the error message to include in the exception
 * @ param < T > the Class type
 * @ return value cast to clazz
 * @ throws IllegalArgumentException if value is not assignable to clazz */
@ SuppressWarnings ( "unchecked" ) public static < T > T convertToType ( final Class < T > clazz , final Object value , final String errorMessage ) { } }

implementation: if ( ! clazz . isAssignableFrom ( value . getClass ( ) ) ) { throw new IllegalArgumentException ( errorMessage ) ; } return ( T ) value ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the sum of the values of the given expression when applied to all members of
 * the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / sum / $ sum */
public static < TExpression > BsonField sum ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$sum" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the average of the values of the given expression when applied to all
 * members of the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / avg / $ avg */
public static < TExpression > BsonField avg ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$avg" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the value of the given expression when applied to the first member of
 * the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / first / $ first */
public static < TExpression > BsonField first ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$first" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the value of the given expression when applied to the last member of
 * the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / last / $ last */
public static < TExpression > BsonField last ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$last" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the maximum of the values of the given expression when applied to all
 * members of the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / max / $ max */
public static < TExpression > BsonField max ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$max" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the minimum of the values of the given expression when applied to all
 * members of the group .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / min / $ min */
public static < TExpression > BsonField min ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$min" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing an array of all values that results from applying an expression to each
 * document in a group of documents that share the same group by key .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / push / $ push */
public static < TExpression > BsonField push ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$push" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing all unique values that results from applying the given expression to each
 * document in a group of documents that share the same group by key .
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / addToSet / $ addToSet */
public static < TExpression > BsonField addToSet ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$addToSet" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the sample standard deviation of the values of the given expression
 * when applied to all members of the group .
 * < p > Use if the values encompass the entire population of data you want to represent and do not wish to generalize about
 * a larger population . < / p >
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / stdDevPop / $ stdDevPop
 * @ mongodb . server . release 3.2
 * @ since 3.2 */
public static < TExpression > BsonField stdDevPop ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$stdDevPop" , fieldName , expression ) ;


signature:
public class Accumulators { /** * Gets a field name for a $ group operation representing the sample standard deviation of the values of the given expression
 * when applied to all members of the group .
 * < p > Use if the values encompass a sample of a population of data from which to generalize about the population . < / p >
 * @ param fieldName the field name
 * @ param expression the expression
 * @ param < TExpression > the expression type
 * @ return the field
 * @ mongodb . driver . manual reference / operator / aggregation / stdDevSamp / $ stdDevSamp
 * @ mongodb . server . release 3.2
 * @ since 3.2 */
public static < TExpression > BsonField stdDevSamp ( final String fieldName , final TExpression expression ) { } }

implementation: return accumulator ( "$stdDevSamp" , fieldName , expression ) ;


signature:
public class DBEncoderAdapter { /** * over an array of ByteBuffer instances from a PooledByteBufferOutputBuffer */
@ Override public void encode ( final BsonWriter writer , final DBObject document , final EncoderContext encoderContext ) { } }

implementation: BasicOutputBuffer buffer = new BasicOutputBuffer ( ) ; try { encoder . writeObject ( buffer , document ) ; BsonBinaryReader reader = new BsonBinaryReader ( new ByteBufferBsonInput ( new ByteBufNIO ( wrap ( buffer . toByteArray ( ) ) ) ) ) ; try { writer . pipe ( reader ) ; } finally { reader . close ( ) ; } } finally { buffer . close ( ) ; }


signature:
public class MixedBulkWriteOperation { /** * Executes a bulk write operation .
 * @ param binding the WriteBinding for the operation
 * @ return the bulk write result .
 * @ throws MongoBulkWriteException if a failure to complete the bulk write is detected based on the server response */
@ Override public BulkWriteResult execute ( final WriteBinding binding ) { } }

implementation: return withReleasableConnection ( binding , new CallableWithConnectionAndSource < BulkWriteResult > ( ) { @ Override public BulkWriteResult call ( final ConnectionSource connectionSource , final Connection connection ) { validateWriteRequestsAndReleaseConnectionIfError ( connection ) ; if ( getWriteConcern ( ) . isAcknowledged ( ) || serverIsAtLeastVersionThreeDotSix ( connection . getDescription ( ) ) ) { BulkWriteBatch bulkWriteBatch = BulkWriteBatch . createBulkWriteBatch ( namespace , connectionSource . getServerDescription ( ) , connection . getDescription ( ) , ordered , writeConcern , bypassDocumentValidation , retryWrites , writeRequests , binding . getSessionContext ( ) ) ; return executeBulkWriteBatch ( binding , connection , bulkWriteBatch ) ; } else { return executeLegacyBatches ( connection ) ; } } } ) ;


signature:
public class CausalConsistencyExamples { /** * Run this main method to see the output of this quick example .
 * @ param args takes an optional single argument for the connection string */
public static void main ( final String [ ] args ) { } }

implementation:
setupDatabase ( ) ; MongoClient client = MongoClients . create ( ) ; // Start Causal Consistency Example 1
// Example 1 : Use a causally consistent session to ensure that the update occurs before the insert .
ClientSession session1 = client . startSession ( ClientSessionOptions . builder ( ) . causallyConsistent ( true ) . build ( ) ) ; Date currentDate = new Date ( ) ; MongoCollection < Document > items = client . getDatabase ( "test" ) . withReadConcern ( ReadConcern . MAJORITY ) . withWriteConcern ( WriteConcern . MAJORITY . withWTimeout ( 1000 , TimeUnit . MILLISECONDS ) ) . getCollection ( "test" ) ; items . updateOne ( session1 , eq ( "sku" , "111" ) , set ( "end" , currentDate ) ) ; Document document = new Document ( "sku" , "nuts-111" ) . append ( "name" , "Pecans" ) . append ( "start" , currentDate ) ; items . insertOne ( session1 , document ) ; // End Causal Consistency Example 1
// Start Causal Consistency Example 2
// Example 2 : Advance the cluster time and the operation time to that of the other session to ensure that
// this client is causally consistent with the other session and read after the two writes .
ClientSession session2 = client . startSession ( ClientSessionOptions . builder ( ) . causallyConsistent ( true ) . build ( ) ) ; session2 . advanceClusterTime ( session1 . getClusterTime ( ) ) ; session2 . advanceOperationTime ( session1 . getOperationTime ( ) ) ; items = client . getDatabase ( "test" ) . withReadPreference ( ReadPreference . secondary ( ) ) . withReadConcern ( ReadConcern . MAJORITY ) . withWriteConcern ( WriteConcern . MAJORITY . withWTimeout ( 1000 , TimeUnit . MILLISECONDS ) ) . getCollection ( "items" ) ; for ( Document item : items . find ( session2 , eq ( "end" , BsonNull . VALUE ) ) ) { System . out . println ( item ) ; } // End Causal Consistency Example 2


signature:
public class BulkWriteRequestBuilder { /** * Adds a request to replace one document in the collection that matches the query with which this builder was created .
 * @ param document the replacement document , which must be structured just as a document you would insert . It can not contain any
 * update operators . */
public void replaceOne ( final DBObject document ) { } }

implementation: new BulkUpdateRequestBuilder ( bulkWriteOperation , query , false , codec , replacementCodec , collation , null ) . replaceOne ( document ) ;


signature:
public class BulkWriteRequestBuilder { /** * Adds a request to update all documents in the collection that match the query with which this builder was created .
 * @ param update the update criteria */
public void update ( final DBObject update ) { } }

implementation: new BulkUpdateRequestBuilder ( bulkWriteOperation , query , false , codec , replacementCodec , collation , null ) . update ( update ) ;


signature:
public class BulkWriteRequestBuilder { /** * Specifies that the request being built should be an upsert .
 * @ return a new builder that allows only update and replace , since upsert does not apply to remove .
 * @ mongodb . driver . manual tutorial / modify - documents / # upsert - option Upsert */
public BulkUpdateRequestBuilder upsert ( ) { } }

implementation: return new BulkUpdateRequestBuilder ( bulkWriteOperation , query , true , codec , replacementCodec , collation , null ) ;


signature:
public class BulkWriteRequestBuilder { /** * Specifies that the request being built should use the given array filters for an update . Note that this option only applies to
 * update operations and will be ignored for replace operations
 * @ param arrayFilters the array filters to apply to the update operation
 * @ return a new builder that allows only update and replace , since upsert does not apply to remove .
 * @ since 3.6
 * @ mongodb . server . release 3.6 */
public BulkUpdateRequestBuilder arrayFilters ( final List < ? extends DBObject > arrayFilters ) { } }

implementation: return new BulkUpdateRequestBuilder ( bulkWriteOperation , query , false , codec , replacementCodec , collation , arrayFilters ) ;


signature:
public class MapReduceToCollectionOperation { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this
 * @ mongodb . driver . manual reference / method / cursor . maxTimeMS / # cursor . maxTimeMS Max Time */
public MapReduceToCollectionOperation maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: notNull ( "timeUnit" , timeUnit ) ; this . maxTimeMS = TimeUnit . MILLISECONDS . convert ( maxTime , timeUnit ) ; return this ;


signature:
public class MapReduceToCollectionOperation { /** * Sets the output action one of : " replace " , " merge " , " reduce "
 * @ param action the output action
 * @ return this
 * @ mongodb . driver . manual reference / command / mapReduce / # output - to - a - collection - with - an - action output with an action */
public MapReduceToCollectionOperation action ( final String action ) { } }

implementation: notNull ( "action" , action ) ; isTrue ( "action must be one of: \"replace\", \"merge\", \"reduce\"" , VALID_ACTIONS . contains ( action ) ) ; this . action = action ; return this ;


signature:
public class MapReduceToCollectionOperation { /** * Executing this will return a cursor with your results in .
 * @ param binding the binding
 * @ return a MongoCursor that can be iterated over to find all the results of the Map Reduce operation . */
@ Override public MapReduceStatistics execute ( final WriteBinding binding ) { } }

implementation: return withConnection ( binding , new OperationHelper . CallableWithConnection < MapReduceStatistics > ( ) { @ Override public MapReduceStatistics call ( final Connection connection ) { validateCollation ( connection , collation ) ; return executeCommand ( binding , namespace . getDatabaseName ( ) , getCommand ( connection . getDescription ( ) ) , connection , transformer ( ) ) ; } } ) ;


signature:
public class DropIndexOptions { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this */
public DropIndexOptions maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }


signature:
public class MongoClients { /** * Initializes the mongod library for use .
 * < p > The library must be called at most once per process before calling { @ link # create ( MongoClientSettings ) } . < / p >
 * @ param mongoEmbeddedSettings the settings for the embedded driver . */
public static synchronized void init ( final MongoEmbeddedSettings mongoEmbeddedSettings ) { } }

implementation: if ( mongoEmbeddedLibrary != null ) { throw new MongoClientEmbeddedException ( "The mongo embedded library has already been initialized" ) ; } try { mongoEmbeddedLibrary = MongoEmbeddedCAPI . create ( mongoEmbeddedSettings . getYamlConfig ( ) , mongoEmbeddedSettings . getLogLevel ( ) . toCapiLogLevel ( ) , mongoEmbeddedSettings . getLibraryPath ( ) ) ; } catch ( Exception e ) { throw new MongoClientEmbeddedException ( format ( "The mongo embedded library could not be initialized%n" + "Server error message: %s" , e . getMessage ( ) ) , e ) ; }


signature:
public class MongoClients { /** * Creates a new client .
 * @ param mongoClientSettings the mongoClientSettings
 * @ return the client */
public static synchronized MongoClient create ( final MongoClientSettings mongoClientSettings ) { } }

implementation: if ( mongoEmbeddedLibrary == null ) { throw new MongoClientEmbeddedException ( "The mongo embedded library must be initialized first." ) ; } try { Cluster cluster = new EmbeddedCluster ( mongoEmbeddedLibrary , mongoClientSettings ) ; return new MongoClientImpl ( cluster , mongoClientSettings . getWrappedMongoClientSettings ( ) , null ) ; } catch ( Exception e ) { throw new MongoClientEmbeddedException ( format ( "Could not create a new embedded cluster.%n" + "Please ensure any existing MongoClients are fully closed before trying to create a new one.%n" + "Server error message: %s" , e . getMessage ( ) ) , e ) ; }


signature:
public class MongoClients { /** * Closes down the mongod library */
public static synchronized void close ( ) { } }

implementation: if ( mongoEmbeddedLibrary != null ) { try { mongoEmbeddedLibrary . close ( ) ; } catch ( Exception e ) { throw new MongoClientEmbeddedException ( format ( "Could not close the mongo embedded library.%n" + "Please ensure that any MongoClient instances have been closed first.%n" + "Server error message: %s" , e . getMessage ( ) ) , e ) ; } mongoEmbeddedLibrary = null ; }


signature:
public class SslHelper { /** * Enable SNI if running on Java 8 or later . Otherwise fail silently to enable SNI .
 * @ param host the server host
 * @ param sslParameters the SSL parameters */
public static void enableSni ( final String host , final SSLParameters sslParameters ) { } }

implementation: if ( SNI_SSL_HELPER != null ) { SNI_SSL_HELPER . enableSni ( host , sslParameters ) ; }