_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q165900 | DefaultConnectionPool.incrementGenerationOnSocketException | validation | private void incrementGenerationOnSocketException(final InternalConnection connection, final Throwable t) {
if (t instanceof MongoSocketException && !(t instanceof MongoSocketReadTimeoutException)) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(format("Got socket exception on connection [%s] to %s. All connections to %s will be closed.",
getId(connection), serverId.getAddress(), serverId.getAddress()));
}
invalidate();
}
} | java | {
"resource": ""
} |
q165901 | ClassMap.getAncestry | validation | public static <T> List<Class<?>> getAncestry(final Class<T> clazz) {
return ClassAncestry.getAncestry(clazz);
} | java | {
"resource": ""
} |
q165902 | ReplaceOptions.createReplaceOptions | validation | @Deprecated
public static ReplaceOptions createReplaceOptions(final UpdateOptions updateOptions) {
notNull("updateOptions", updateOptions);
List<? extends Bson> arrayFilters = updateOptions.getArrayFilters();
isTrue("ArrayFilters should be empty.", arrayFilters == null || arrayFilters.isEmpty());
return new ReplaceOptions()
.bypassDocumentValidation(updateOptions.getBypassDocumentValidation())
.collation(updateOptions.getCollation())
.upsert(updateOptions.isUpsert());
} | java | {
"resource": ""
} |
q165903 | Base64.decode | validation | public static byte[] decode(final String s) {
int delta = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
byte[] buffer = new byte[s.length() * BYTES_PER_UNENCODED_BLOCK / BYTES_PER_ENCODED_BLOCK - delta];
int mask = 0xFF;
int pos = 0;
for (int i = 0; i < s.length(); i += BYTES_PER_ENCODED_BLOCK) {
int c0 = DECODE_TABLE[s.charAt(i)];
int c1 = DECODE_TABLE[s.charAt(i + 1)];
buffer[pos++] = (byte) (((c0 << 2) | (c1 >> 4)) & mask);
if (pos >= buffer.length) {
return buffer;
}
int c2 = DECODE_TABLE[s.charAt(i + 2)];
buffer[pos++] = (byte) (((c1 << 4) | (c2 >> 2)) & mask);
if (pos >= buffer.length) {
return buffer;
}
int c3 = DECODE_TABLE[s.charAt(i + 3)];
buffer[pos++] = (byte) (((c2 << 6) | c3) & mask);
}
return buffer;
} | java | {
"resource": ""
} |
q165904 | Base64.encode | validation | public static String encode(final byte[] in) {
int modulus = 0;
int bitWorkArea = 0;
int numEncodedBytes = (in.length / BYTES_PER_UNENCODED_BLOCK) * BYTES_PER_ENCODED_BLOCK
+ ((in.length % BYTES_PER_UNENCODED_BLOCK == 0) ? 0 : 4);
byte[] buffer = new byte[numEncodedBytes];
int pos = 0;
for (int b : in) {
modulus = (modulus + 1) % BYTES_PER_UNENCODED_BLOCK;
if (b < 0) {
b += 256;
}
bitWorkArea = (bitWorkArea << 8) + b; // BITS_PER_BYTE
if (0 == modulus) { // 3 bytes = 24 bits = 4 * 6 bits to extract
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 18) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 12) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 6) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[bitWorkArea & SIX_BIT_MASK];
}
}
switch (modulus) { // 0-2
case 1: // 8 bits = 6 + 2
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 2) & SIX_BIT_MASK]; // top 6 bits
buffer[pos++] = ENCODE_TABLE[(bitWorkArea << 4) & SIX_BIT_MASK]; // remaining 2
buffer[pos++] = PAD;
buffer[pos] = PAD; // Last entry no need to ++
break;
case 2: // 16 bits = 6 + 6 + 4
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 10) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 4) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea << 2) & SIX_BIT_MASK];
buffer[pos] = PAD; // Last entry no need to ++
break;
default:
break;
}
return byteArrayToString(buffer);
} | java | {
"resource": ""
} |
q165905 | Mongo.getAddress | validation | @Deprecated
@SuppressWarnings("deprecation")
@Nullable
public ServerAddress getAddress() {
ClusterDescription description = getClusterDescription();
if (description.getPrimaries().isEmpty()) {
return null;
}
return description.getPrimaries().get(0).getAddress();
} | java | {
"resource": ""
} |
q165906 | Mongo.getReplicaSetStatus | validation | @SuppressWarnings("deprecation")
@Deprecated
@Nullable
public ReplicaSetStatus getReplicaSetStatus() {
ClusterDescription clusterDescription = getClusterDescription();
return clusterDescription.getType() == REPLICA_SET && clusterDescription.getConnectionMode() == MULTIPLE
? new ReplicaSetStatus(delegate.getCluster()) : null; // this is intended behavior in 2.x
} | java | {
"resource": ""
} |
q165907 | Mongo.getDatabaseNames | validation | @Deprecated
public List<String> getDatabaseNames() {
return new MongoIterableImpl<DBObject>(null, createOperationExecutor(), ReadConcern.DEFAULT, primary(),
options.getRetryReads()) {
@Override
public ReadOperation<BatchCursor<DBObject>> asReadOperation() {
return new ListDatabasesOperation<DBObject>(MongoClient.getCommandCodec());
}
}.map(new Function<DBObject, String>() {
@Override
public String apply(final DBObject result) {
return (String) result.get("name");
}
}).into(new ArrayList<String>());
} | java | {
"resource": ""
} |
q165908 | Mongo.fsync | validation | @Deprecated
public CommandResult fsync(final boolean async) {
DBObject command = new BasicDBObject("fsync", 1);
if (async) {
command.put("async", 1);
}
return getDB(ADMIN_DATABASE_NAME).command(command);
} | java | {
"resource": ""
} |
q165909 | Mongo.fsyncAndLock | validation | @Deprecated
public CommandResult fsyncAndLock() {
DBObject command = new BasicDBObject("fsync", 1);
command.put("lock", 1);
return getDB(ADMIN_DATABASE_NAME).command(command);
} | java | {
"resource": ""
} |
q165910 | Mongo.unlock | validation | @Deprecated
public DBObject unlock() {
return DBObjects.toDBObject(createOperationExecutor().execute(new FsyncUnlockOperation(), readPreference, readConcern));
} | java | {
"resource": ""
} |
q165911 | BsonValue.asNumber | validation | public BsonNumber asNumber() {
if (getBsonType() != BsonType.INT32 && getBsonType() != BsonType.INT64 && getBsonType() != BsonType.DOUBLE) {
throw new BsonInvalidOperationException(format("Value expected to be of a numerical BSON type is of unexpected type %s",
getBsonType()));
}
return (BsonNumber) this;
} | java | {
"resource": ""
} |
q165912 | ConnectionId.withServerValue | validation | public ConnectionId withServerValue(final int serverValue) {
isTrue("server value is null", this.serverValue == null);
return new ConnectionId(serverId, localValue, serverValue);
} | java | {
"resource": ""
} |
q165913 | ClassAncestry.computeAncestry | validation | private static List<Class<?>> computeAncestry(final Class<?> c) {
List<Class<?>> result = new ArrayList<Class<?>>();
result.add(Object.class);
computeAncestry(c, result);
Collections.reverse(result);
return unmodifiableList(new ArrayList<Class<?>>(result));
} | java | {
"resource": ""
} |
q165914 | Geometry.toJson | validation | @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
public String toJson() {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter, new JsonWriterSettings());
Codec codec = getRegistry().get(getClass());
codec.encode(writer, this, EncoderContext.builder().build());
return stringWriter.toString();
} | java | {
"resource": ""
} |
q165915 | MapReduceWithInlineResultsOperation.execute | validation | @Override
@SuppressWarnings("unchecked")
public MapReduceBatchCursor<T> execute(final ReadBinding binding) {
return executeCommand(binding, namespace.getDatabaseName(), getCommandCreator(binding.getSessionContext()),
CommandResultDocumentCodec.create(decoder, "results"), transformer(), false);
} | java | {
"resource": ""
} |
q165916 | IndexOptions.getExpireAfter | validation | @Nullable
public Long getExpireAfter(final TimeUnit timeUnit) {
if (expireAfterSeconds == null) {
return null;
}
return timeUnit.convert(expireAfterSeconds, TimeUnit.SECONDS);
} | java | {
"resource": ""
} |
q165917 | GroupCommand.toDBObject | validation | public DBObject toDBObject() {
DBObject args = new BasicDBObject("ns", collectionName).append("cond", condition)
.append("$reduce", reduce)
.append("initial", initial);
if (keys != null) {
args.put("key", keys);
}
if (keyf != null) {
args.put("$keyf", keyf);
}
if (finalize != null) {
args.put("finalize", finalize);
}
return new BasicDBObject("group", args);
} | java | {
"resource": ""
} |
q165918 | ClusterDescription.getLogicalSessionTimeoutMinutes | validation | public Integer getLogicalSessionTimeoutMinutes() {
Integer retVal = null;
for (ServerDescription cur : getServersByPredicate(new Predicate() {
@Override
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isPrimary() || serverDescription.isSecondary();
}
})) {
if (cur.getLogicalSessionTimeoutMinutes() == null) {
return null;
}
if (retVal == null) {
retVal = cur.getLogicalSessionTimeoutMinutes();
} else {
retVal = Math.min(retVal, cur.getLogicalSessionTimeoutMinutes());
}
}
return retVal;
} | java | {
"resource": ""
} |
q165919 | ClusterDescription.getAll | validation | @Deprecated
public Set<ServerDescription> getAll() {
Set<ServerDescription> serverDescriptionSet = new TreeSet<ServerDescription>(new Comparator<ServerDescription>() {
@Override
public int compare(final ServerDescription o1, final ServerDescription o2) {
int val = o1.getAddress().getHost().compareTo(o2.getAddress().getHost());
if (val != 0) {
return val;
}
return integerCompare(o1.getAddress().getPort(), o2.getAddress().getPort());
}
private int integerCompare(final int p1, final int p2) {
return (p1 < p2) ? -1 : ((p1 == p2) ? 0 : 1);
}
});
serverDescriptionSet.addAll(serverDescriptions);
return Collections.unmodifiableSet(serverDescriptionSet);
} | java | {
"resource": ""
} |
q165920 | ClusterDescription.getByServerAddress | validation | @Deprecated
public ServerDescription getByServerAddress(final ServerAddress serverAddress) {
for (final ServerDescription cur : serverDescriptions) {
if (cur.isOk() && cur.getAddress().equals(serverAddress)) {
return cur;
}
}
return null;
} | java | {
"resource": ""
} |
q165921 | ClusterDescription.getPrimaries | validation | @Deprecated
public List<ServerDescription> getPrimaries() {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isPrimary();
}
});
} | java | {
"resource": ""
} |
q165922 | ClusterDescription.getSecondaries | validation | @Deprecated
public List<ServerDescription> getSecondaries() {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isSecondary();
}
});
} | java | {
"resource": ""
} |
q165923 | ClusterDescription.getSecondaries | validation | @Deprecated
public List<ServerDescription> getSecondaries(final TagSet tagSet) {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isSecondary() && serverDescription.hasTags(tagSet);
}
});
} | java | {
"resource": ""
} |
q165924 | ClusterDescription.getAny | validation | @Deprecated
public List<ServerDescription> getAny() {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isOk();
}
});
} | java | {
"resource": ""
} |
q165925 | ClusterDescription.getAnyPrimaryOrSecondary | validation | @Deprecated
public List<ServerDescription> getAnyPrimaryOrSecondary() {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return serverDescription.isPrimary() || serverDescription.isSecondary();
}
});
} | java | {
"resource": ""
} |
q165926 | ClusterDescription.getAnyPrimaryOrSecondary | validation | @Deprecated
public List<ServerDescription> getAnyPrimaryOrSecondary(final TagSet tagSet) {
return getServersByPredicate(new Predicate() {
public boolean apply(final ServerDescription serverDescription) {
return (serverDescription.isPrimary() || serverDescription.isSecondary()) && serverDescription.hasTags(tagSet);
}
});
} | java | {
"resource": ""
} |
q165927 | ClusterDescription.getShortDescription | validation | public String getShortDescription() {
StringBuilder serverDescriptions = new StringBuilder();
String delimiter = "";
for (final ServerDescription cur : this.serverDescriptions) {
serverDescriptions.append(delimiter).append(cur.getShortDescription());
delimiter = ", ";
}
if (srvResolutionException == null) {
return format("{type=%s, servers=[%s]", type, serverDescriptions);
} else {
return format("{type=%s, srvResolutionException=%s, servers=[%s]", type, srvResolutionException, serverDescriptions);
}
} | java | {
"resource": ""
} |
q165928 | MongoCredential.createCredential | validation | public static MongoCredential createCredential(final String userName, final String database, final char[] password) {
return new MongoCredential(null, userName, database, password);
} | java | {
"resource": ""
} |
q165929 | MongoCredential.createScramSha256Credential | validation | public static MongoCredential createScramSha256Credential(final String userName, final String source, final char[] password) {
return new MongoCredential(SCRAM_SHA_256, userName, source, password);
} | java | {
"resource": ""
} |
q165930 | MongoCredential.createPlainCredential | validation | public static MongoCredential createPlainCredential(final String userName, final String source, final char[] password) {
return new MongoCredential(PLAIN, userName, source, password);
} | java | {
"resource": ""
} |
q165931 | MongoCredential.withMechanismProperty | validation | public <T> MongoCredential withMechanismProperty(final String key, final T value) {
return new MongoCredential(this, key, value);
} | java | {
"resource": ""
} |
q165932 | MongoCredential.withMechanism | validation | public MongoCredential withMechanism(final AuthenticationMechanism mechanism) {
if (this.mechanism != null) {
throw new IllegalArgumentException("Mechanism already set");
}
return new MongoCredential(mechanism, userName, source, password, mechanismProperties);
} | java | {
"resource": ""
} |
q165933 | MongoCredential.getMechanismProperty | validation | @SuppressWarnings("unchecked")
@Nullable
public <T> T getMechanismProperty(final String key, @Nullable final T defaultValue) {
notNull("key", key);
T value = (T) mechanismProperties.get(key.toLowerCase());
return (value == null) ? defaultValue : value;
} | java | {
"resource": ""
} |
q165934 | OutputBuffer.toByteArray | validation | public byte[] toByteArray() {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream(size());
pipe(bout);
return bout.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException("should be impossible", ioe);
}
} | java | {
"resource": ""
} |
q165935 | ClassMapBasedObjectSerializer.addObjectSerializer | validation | @SuppressWarnings("rawtypes")
void addObjectSerializer(final Class c, final ObjectSerializer serializer) {
_serializers.put(c, serializer);
} | java | {
"resource": ""
} |
q165936 | UpdateRequest.multi | validation | public UpdateRequest multi(final boolean isMulti) {
if (isMulti && updateType == Type.REPLACE) {
throw new IllegalArgumentException("Replacements can not be multi");
}
this.isMulti = isMulti;
return this;
} | java | {
"resource": ""
} |
q165937 | RequestMessage.encode | validation | public void encode(final BsonOutput bsonOutput, final SessionContext sessionContext) {
notNull("sessionContext", sessionContext);
int messageStartPosition = bsonOutput.getPosition();
writeMessagePrologue(bsonOutput);
EncodingMetadata encodingMetadata = encodeMessageBodyWithMetadata(bsonOutput, sessionContext);
backpatchMessageLength(messageStartPosition, bsonOutput);
this.encodingMetadata = encodingMetadata;
} | java | {
"resource": ""
} |
q165938 | RequestMessage.writeMessagePrologue | validation | protected void writeMessagePrologue(final BsonOutput bsonOutput) {
bsonOutput.writeInt32(0); // length: will set this later
bsonOutput.writeInt32(id);
bsonOutput.writeInt32(0); // response to
bsonOutput.writeInt32(opCode.getValue());
} | java | {
"resource": ""
} |
q165939 | RequestMessage.addDocument | validation | protected void addDocument(final BsonDocument document, final BsonOutput bsonOutput,
final FieldNameValidator validator) {
addDocument(document, getCodec(document), EncoderContext.builder().build(), bsonOutput, validator,
settings.getMaxDocumentSize() + DOCUMENT_HEADROOM, null);
} | java | {
"resource": ""
} |
q165940 | RequestMessage.addCollectibleDocument | validation | protected void addCollectibleDocument(final BsonDocument document, final BsonOutput bsonOutput, final FieldNameValidator validator) {
addDocument(document, getCodec(document), EncoderContext.builder().isEncodingCollectibleDocument(true).build(), bsonOutput,
validator, settings.getMaxDocumentSize(), null);
} | java | {
"resource": ""
} |
q165941 | RequestMessage.backpatchMessageLength | validation | protected void backpatchMessageLength(final int startPosition, final BsonOutput bsonOutput) {
int messageLength = bsonOutput.getPosition() - startPosition;
bsonOutput.writeInt32(bsonOutput.getPosition() - messageLength, messageLength);
} | java | {
"resource": ""
} |
q165942 | GridFSInputFile.createChunk | validation | protected DBObject createChunk(final Object id, final int currentChunkNumber, final byte[] writeBuffer) {
return new BasicDBObject("files_id", id)
.append("n", currentChunkNumber)
.append("data", writeBuffer);
} | java | {
"resource": ""
} |
q165943 | DBCursor.copy | validation | public DBCursor copy() {
return new DBCursor(collection, filter, findOptions, executor, decoderFactory, decoder, retryReads);
} | java | {
"resource": ""
} |
q165944 | DBCursor.hasNext | validation | @Override
public boolean hasNext() {
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;
} | java | {
"resource": ""
} |
q165945 | DBCursor.tryNext | validation | @Nullable
public DBObject tryNext() {
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);
} | java | {
"resource": ""
} |
q165946 | DBCursor.toArray | validation | public List<DBObject> toArray(final int max) {
checkIteratorOrArray(IteratorOrArray.ARRAY);
fillArray(max - 1);
return all;
} | java | {
"resource": ""
} |
q165947 | DBCursor.one | validation | @Nullable
public DBObject one() {
DBCursor findOneCursor = copy().limit(-1);
try {
return findOneCursor.hasNext() ? findOneCursor.next() : null;
} finally {
findOneCursor.close();
}
} | java | {
"resource": ""
} |
q165948 | DBCursor.getReadPreference | validation | public ReadPreference getReadPreference() {
ReadPreference readPreference = findOptions.getReadPreference();
if (readPreference != null) {
return readPreference;
}
return collection.getReadPreference();
} | java | {
"resource": ""
} |
q165949 | DBCursor.getReadConcern | validation | ReadConcern getReadConcern() {
ReadConcern readConcern = findOptions.getReadConcern();
if (readConcern != null) {
return readConcern;
}
return collection.getReadConcern();
} | java | {
"resource": ""
} |
q165950 | BasicBSONCallback._put | validation | protected void _put(final String name, final Object value) {
cur().put(name, !BSON.hasDecodeHooks() ? value : BSON.applyDecodingHooks(value));
} | java | {
"resource": ""
} |
q165951 | DefaultDBEncoder.putDBRef | validation | protected void putDBRef(final String name, final DBRef ref) {
BasicDBObject dbRefDocument = new BasicDBObject("$ref", ref.getCollectionName()).append("$id", ref.getId());
if (ref.getDatabaseName() != null) {
dbRefDocument.put("$db", ref.getDatabaseName());
}
putObject(name, dbRefDocument);
} | java | {
"resource": ""
} |
q165952 | BulkWriteResult.unacknowledged | validation | public static BulkWriteResult unacknowledged() {
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");
}
};
} | java | {
"resource": ""
} |
q165953 | ServerAddress.getSocketAddress | validation | public InetSocketAddress getSocketAddress() {
try {
return new InetSocketAddress(InetAddress.getByName(host), port);
} catch (UnknownHostException e) {
throw new MongoSocketException(e.getMessage(), this, e);
}
} | java | {
"resource": ""
} |
q165954 | ServerAddress.getSocketAddresses | validation | public List<InetSocketAddress> getSocketAddresses() {
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);
}
} | java | {
"resource": ""
} |
q165955 | Filters.ne | validation | public static <TItem> Bson ne(final String fieldName, @Nullable final TItem value) {
return new OperatorFilter<TItem>("$ne", fieldName, value);
} | java | {
"resource": ""
} |
q165956 | Filters.gt | validation | public static <TItem> Bson gt(final String fieldName, final TItem value) {
return new OperatorFilter<TItem>("$gt", fieldName, value);
} | java | {
"resource": ""
} |
q165957 | Filters.lt | validation | public static <TItem> Bson lt(final String fieldName, final TItem value) {
return new OperatorFilter<TItem>("$lt", fieldName, value);
} | java | {
"resource": ""
} |
q165958 | Filters.gte | validation | public static <TItem> Bson gte(final String fieldName, final TItem value) {
return new OperatorFilter<TItem>("$gte", fieldName, value);
} | java | {
"resource": ""
} |
q165959 | Filters.lte | validation | public static <TItem> Bson lte(final String fieldName, final TItem value) {
return new OperatorFilter<TItem>("$lte", fieldName, value);
} | java | {
"resource": ""
} |
q165960 | Filters.or | validation | public static Bson or(final Iterable<Bson> filters) {
return new OrNorFilter(OrNorFilter.Operator.OR, filters);
} | java | {
"resource": ""
} |
q165961 | Filters.nor | validation | public static Bson nor(final Iterable<Bson> filters) {
return new OrNorFilter(OrNorFilter.Operator.NOR, filters);
} | java | {
"resource": ""
} |
q165962 | Filters.exists | validation | public static Bson exists(final String fieldName, final boolean exists) {
return new OperatorFilter<BsonBoolean>("$exists", fieldName, BsonBoolean.valueOf(exists));
} | java | {
"resource": ""
} |
q165963 | Filters.text | validation | @Deprecated
public static Bson text(final String search, final String language) {
notNull("search", search);
return text(search, new TextSearchOptions().language(language));
} | java | {
"resource": ""
} |
q165964 | Filters.text | validation | public static Bson text(final String search, final TextSearchOptions textSearchOptions) {
notNull("search", search);
notNull("textSearchOptions", textSearchOptions);
return new TextFilter(search, textSearchOptions);
} | java | {
"resource": ""
} |
q165965 | Filters.elemMatch | validation | public static Bson elemMatch(final String fieldName, final Bson filter) {
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)));
}
};
} | java | {
"resource": ""
} |
q165966 | Filters.geoWithinBox | validation | public static Bson geoWithinBox(final String fieldName, final double lowerLeftX, final double lowerLeftY, final double upperRightX,
final double upperRightY) {
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);
} | java | {
"resource": ""
} |
q165967 | Filters.geoWithinPolygon | validation | public static Bson geoWithinPolygon(final String fieldName, final List<List<Double>> points) {
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);
} | java | {
"resource": ""
} |
q165968 | Filters.geoWithinCenter | validation | public static Bson geoWithinCenter(final String fieldName, final double x, final double y, final double radius) {
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);
} | java | {
"resource": ""
} |
q165969 | Filters.near | validation | public static Bson near(final String fieldName, final Point geometry, @Nullable final Double maxDistance,
@Nullable final Double minDistance) {
return new GeometryOperatorFilter<Point>("$near", fieldName, geometry, maxDistance, minDistance);
} | java | {
"resource": ""
} |
q165970 | Filters.near | validation | public static Bson near(final String fieldName, final double x, final double y, @Nullable final Double maxDistance,
@Nullable final Double minDistance) {
return createNearFilterDocument(fieldName, x, y, maxDistance, minDistance, "$near");
} | java | {
"resource": ""
} |
q165971 | BSON.regexFlags | validation | public static int regexFlags(final String s) {
int flags = 0;
if (s == null) {
return flags;
}
for (final char f : s.toLowerCase().toCharArray()) {
flags |= regexFlag(f);
}
return flags;
} | java | {
"resource": ""
} |
q165972 | BSON.regexFlag | validation | public static int regexFlag(final char c) {
int flag = FLAG_LOOKUP[c];
if (flag == 0) {
throw new IllegalArgumentException(String.format("Unrecognized flag [%c]", c));
}
return flag;
} | java | {
"resource": ""
} |
q165973 | BSON.regexFlags | validation | public static String regexFlags(final int flags) {
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();
} | java | {
"resource": ""
} |
q165974 | IndexRequest.textVersion | validation | public IndexRequest textVersion(final Integer textVersion) {
if (textVersion != null) {
isTrueArgument("textVersion must be 1, 2 or 3", VALID_TEXT_INDEX_VERSIONS.contains(textVersion));
}
this.textVersion = textVersion;
return this;
} | java | {
"resource": ""
} |
q165975 | IndexRequest.sphereVersion | validation | public IndexRequest sphereVersion(final Integer sphereVersion) {
if (sphereVersion != null) {
isTrueArgument("sphereIndexVersion must be 1, 2 or 3", VALID_SPHERE_INDEX_VERSIONS.contains(sphereVersion));
}
this.sphereVersion = sphereVersion;
return this;
} | java | {
"resource": ""
} |
q165976 | DBCollectionFindOptions.copy | validation | public DBCollectionFindOptions copy() {
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;
} | java | {
"resource": ""
} |
q165977 | Assertions.convertToType | validation | @SuppressWarnings("unchecked")
public static <T> T convertToType(final Class<T> clazz, final Object value, final String errorMessage) {
if (!clazz.isAssignableFrom(value.getClass())) {
throw new IllegalArgumentException(errorMessage);
}
return (T) value;
} | java | {
"resource": ""
} |
q165978 | DBEncoderAdapter.encode | validation | @Override
public void encode(final BsonWriter writer, final DBObject document, final EncoderContext encoderContext) {
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();
}
} | java | {
"resource": ""
} |
q165979 | MixedBulkWriteOperation.execute | validation | @Override
public BulkWriteResult execute(final WriteBinding binding) {
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);
}
}
});
} | java | {
"resource": ""
} |
q165980 | BulkWriteRequestBuilder.upsert | validation | public BulkUpdateRequestBuilder upsert() {
return new BulkUpdateRequestBuilder(bulkWriteOperation, query, true, codec, replacementCodec, collation, null);
} | java | {
"resource": ""
} |
q165981 | BulkWriteRequestBuilder.arrayFilters | validation | public BulkUpdateRequestBuilder arrayFilters(final List<? extends DBObject> arrayFilters) {
return new BulkUpdateRequestBuilder(bulkWriteOperation, query, false, codec, replacementCodec, collation, arrayFilters);
} | java | {
"resource": ""
} |
q165982 | MapReduceToCollectionOperation.execute | validation | @Override
public MapReduceStatistics execute(final WriteBinding binding) {
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());
}
});
} | java | {
"resource": ""
} |
q165983 | MongoClients.init | validation | public static synchronized void init(final MongoEmbeddedSettings mongoEmbeddedSettings) {
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);
}
} | java | {
"resource": ""
} |
q165984 | MongoClients.create | validation | public static synchronized MongoClient create(final MongoClientSettings mongoClientSettings) {
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);
}
} | java | {
"resource": ""
} |
q165985 | MongoClients.close | validation | public static synchronized void close() {
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;
}
} | java | {
"resource": ""
} |
q165986 | SslHelper.enableSni | validation | public static void enableSni(final String host, final SSLParameters sslParameters) {
if (SNI_SSL_HELPER != null) {
SNI_SSL_HELPER.enableSni(host, sslParameters);
}
} | java | {
"resource": ""
} |
q165987 | Bytes.getType | validation | @SuppressWarnings("deprecation")
public static byte getType(final Object object) {
if (object == null) {
return NULL;
}
if (object instanceof Integer
|| object instanceof Short
|| object instanceof Byte
|| object instanceof AtomicInteger) {
return NUMBER_INT;
}
if (object instanceof Long || object instanceof AtomicLong) {
return NUMBER_LONG;
}
if (object instanceof Number) {
return NUMBER;
}
if (object instanceof String) {
return STRING;
}
if (object instanceof java.util.List) {
return ARRAY;
}
if (object instanceof byte[]) {
return BINARY;
}
if (object instanceof ObjectId) {
return OID;
}
if (object instanceof Boolean) {
return BOOLEAN;
}
if (object instanceof java.util.Date) {
return DATE;
}
if (object instanceof BSONTimestamp) {
return TIMESTAMP;
}
if (object instanceof java.util.regex.Pattern) {
return REGEX;
}
if (object instanceof DBObject || object instanceof DBRef) {
return OBJECT;
}
if (object instanceof CodeWScope) {
return CODE_W_SCOPE;
}
if (object instanceof Code) {
return CODE;
}
return -1;
} | java | {
"resource": ""
} |
q165988 | MapReduceCommand.toDBObject | validation | public DBObject toDBObject() {
BasicDBObject cmd = new BasicDBObject();
cmd.put("mapreduce", mapReduce);
cmd.put("map", map);
cmd.put("reduce", reduce);
if (verbose != null) {
cmd.put("verbose", verbose);
}
BasicDBObject out = new BasicDBObject();
switch (outputType) {
case INLINE:
out.put("inline", 1);
break;
case REPLACE:
out.put("replace", outputCollection);
break;
case MERGE:
out.put("merge", outputCollection);
break;
case REDUCE:
out.put("reduce", outputCollection);
break;
default:
throw new IllegalArgumentException("Unexpected output type");
}
if (outputDB != null) {
out.put("db", outputDB);
}
cmd.put("out", out);
if (query != null) {
cmd.put("query", query);
}
if (finalize != null) {
cmd.put("finalize", finalize);
}
if (sort != null) {
cmd.put("sort", sort);
}
if (limit > 0) {
cmd.put("limit", limit);
}
if (scope != null) {
cmd.put("scope", scope);
}
if (jsMode != null) {
cmd.put("jsMode", jsMode);
}
if (maxTimeMS != 0) {
cmd.put("maxTimeMS", maxTimeMS);
}
return cmd;
} | java | {
"resource": ""
} |
q165989 | ClusterSettings.getShortDescription | validation | public String getShortDescription() {
return "{"
+ (hosts.isEmpty() ? "" : "hosts=" + hosts)
+ (srvHost == null ? "" : ", srvHost=" + srvHost)
+ ", mode=" + mode
+ ", requiredClusterType=" + requiredClusterType
+ ", serverSelectionTimeout='" + serverSelectionTimeoutMS + " ms" + '\''
+ ", maxWaitQueueSize=" + maxWaitQueueSize
+ (requiredReplicaSetName == null ? "" : ", requiredReplicaSetName='" + requiredReplicaSetName + '\'')
+ (description == null ? "" : ", description='" + description + '\'')
+ '}';
} | java | {
"resource": ""
} |
q165990 | UpdateResult.acknowledged | validation | public static UpdateResult acknowledged(final long matchedCount, @Nullable final Long modifiedCount,
@Nullable final BsonValue upsertedId) {
return new AcknowledgedUpdateResult(matchedCount, modifiedCount, upsertedId);
} | java | {
"resource": ""
} |
q165991 | GridFSFile.getContentType | validation | @Deprecated
public String getContentType() {
if (extraElements != null && extraElements.containsKey("contentType")) {
return extraElements.getString("contentType");
} else {
throw new MongoGridFSException("No contentType data for this GridFS file");
}
} | java | {
"resource": ""
} |
q165992 | GridFSFile.getAliases | validation | @Deprecated
@SuppressWarnings("unchecked")
public List<String> getAliases() {
if (extraElements != null && extraElements.containsKey("aliases")) {
return (List<String>) extraElements.get("aliases");
} else {
throw new MongoGridFSException("No aliases data for this GridFS file");
}
} | java | {
"resource": ""
} |
q165993 | AbstractByteBufBsonDocument.getFirstKey | validation | public String getFirstKey() {
return findInDocument(new Finder<String>() {
@Override
public String find(final BsonReader bsonReader) {
return bsonReader.readName();
}
@Override
public String notFound() {
throw new NoSuchElementException();
}
});
} | java | {
"resource": ""
} |
q165994 | EncoderContext.encodeWithChildContext | validation | public <T> void encodeWithChildContext(final Encoder<T> encoder, final BsonWriter writer, final T value) {
encoder.encode(writer, value, DEFAULT_CONTEXT);
} | java | {
"resource": ""
} |
q165995 | ReadConcern.asDocument | validation | public BsonDocument asDocument() {
BsonDocument readConcern = new BsonDocument();
if (level != null) {
readConcern.put("level", new BsonString(level.getValue()));
}
return readConcern;
} | java | {
"resource": ""
} |
q165996 | SnappyCompressor.compress | validation | @Override
public void compress(final List<ByteBuf> source, final BsonOutput target) {
int uncompressedSize = getUncompressedSize(source);
byte[] singleByteArraySource = new byte[uncompressedSize];
copy(source, singleByteArraySource);
try {
byte[] out = new byte[Snappy.maxCompressedLength(uncompressedSize)];
int compressedSize = Snappy.compress(singleByteArraySource, 0, singleByteArraySource.length, out, 0);
target.writeBytes(out, 0, compressedSize);
} catch (IOException e) {
throw new MongoInternalException("Unexpected IOException", e);
}
} | java | {
"resource": ""
} |
q165997 | BasicBSONObject.getString | validation | public String getString(final String key) {
Object foo = get(key);
if (foo == null) {
return null;
}
return foo.toString();
} | java | {
"resource": ""
} |
q165998 | BasicBSONObject.getBoolean | validation | public boolean getBoolean(final String key, final boolean def) {
Object foo = get(key);
if (foo == null) {
return def;
}
if (foo instanceof Number) {
return ((Number) foo).intValue() > 0;
}
if (foo instanceof Boolean) {
return (Boolean) foo;
}
throw new IllegalArgumentException("can't coerce to bool:" + foo.getClass());
} | java | {
"resource": ""
} |
q165999 | BasicBSONObject.getObjectId | validation | public ObjectId getObjectId(final String field, final ObjectId def) {
Object foo = get(field);
return (foo != null) ? (ObjectId) foo : def;
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.