java.util.Arraysjava.util.Arrays.asList-s



Project mongodb/mongo-java-driver in file ....atomicoperations.FindAndUpdateAcceptanceTest.java (2015-02-26)
@@ -25,13 +25,13 @@ import org.bson.Document;
 import org.bson.codecs.DocumentCodecProvider;
 import org.bson.codecs.ValueCodecProvider;
 import org.bson.codecs.configuration.CodecRegistry;
-import org.bson.codecs.configuration.RootCodecRegistry;
 import org.bson.types.ObjectId;
 import org.junit.Test;
 
-import java.util.Arrays;
 import java.util.Date;
 
+import static java.util.Arrays.asList;
+import static org.bson.codecs.configuration.CodecRegistryHelper.fromProviders;
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertNull;
@@ -73,8 +73,7 @@ public class FindAndUpdateAcceptanceTest extends DatabaseTestCase {
     @Test
     public void shouldFindAndReplaceWithDocumentRequiringACustomEncoder() {
         Worker pat = new Worker(new ObjectId(), "Pat", "Sales", new Date(), 7);
-        CodecRegistry codecRegistry = new RootCodecRegistry(Arrays.asList(new ValueCodecProvider(),
-                new DocumentCodecProvider(),
+        CodecRegistry codecRegistry = fromProviders(asList(new ValueCodecProvider(), new DocumentCodecProvider(),
                 new WorkerCodecProvider()));
         MongoCollection<Worker> collection = database
                 .getCollection(getCollectionName(), Worker.class)
Project mongodb/mongo-java-driver in file ...d7/son.src.main.org.bson.codecs.DocumentCodec.java (2014-10-17)
@@ -25,14 +25,13 @@ import org.bson.BsonValue;
 import org.bson.BsonWriter;
 import org.bson.Document;
 import org.bson.assertions.Assertions;
-import org.bson.codecs.configuration.CodecProvider;
 import org.bson.codecs.configuration.CodecRegistry;
 import org.bson.codecs.configuration.RootCodecRegistry;
 
-import java.util.Arrays;
 import java.util.Map;
 import java.util.UUID;
 
+import static java.util.Arrays.asList;
 
 /**
  * A Codec for Document instances.
@@ -43,7 +42,9 @@ import java.util.UUID;
 public class DocumentCodec implements CollectibleCodec<Document> {
 
     private static final String ID_FIELD_NAME = "_id";
-    private static final CodecRegistry DEFAULT_REGISTRY = new RootCodecRegistry(Arrays.<CodecProvider>asList(new DocumentCodecProvider()));
+    private static final CodecRegistry DEFAULT_REGISTRY = new RootCodecRegistry(asList(new ValueCodecProvider(),
+                                                                                       new BsonValueCodecProvider(),
+                                                                                       new DocumentCodecProvider()));
     private static final BsonTypeClassMap DEFAULT_BSON_TYPE_CLASS_MAP = new BsonTypeClassMap();
 
     private final BsonTypeClassMap bsonTypeClassMap;
Project mongodb/mongo-java-driver in file ...rc.main.com.mongodb.operation.OperationHelper.java (2014-09-29)
@@ -31,13 +31,14 @@ import com.mongodb.connection.Connection;
 import com.mongodb.connection.ServerVersion;
 import com.mongodb.protocol.Protocol;
 
-import java.util.Arrays;
 import java.util.List;
 
+import static java.util.Arrays.asList;
+
 final class OperationHelper {
 
     // TODO: This is duplicated in ProtocolHelper, but I don't want it to be public
-    static final List<Integer> DUPLICATE_KEY_ERROR_CODES = Arrays.asList(11000, 11001, 12582);
+    static final List<Integer> DUPLICATE_KEY_ERROR_CODES = asList(11000, 11001, 12582);
 
 
     interface CallableWithConnection<T> {
@@ -74,6 +75,11 @@ final class OperationHelper {
         return connection.getServerDescription().getVersion().compareTo(new ServerVersion(2, 6)) >= 0;
     }
 
+    static boolean serverIsAtLeastVersionTwoDotEight(final Connection connection) {
+        // Todo update to 2.8 once released
+        return connection.getServerDescription().getVersion().compareTo(new ServerVersion(asList(2, 7, 7))) >= 0;
+    }
+
     static <T> T executeProtocol(final Protocol<T> protocol, final ConnectionSource source) {
         Connection connection = source.getConnection();
         try {
Project mongodb/mongo-java-driver in file ...er-core.src.main.com.mongodb.ConnectionString.java (2014-10-06)
@@ -22,7 +22,6 @@ import com.mongodb.diagnostics.logging.Loggers;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -37,6 +36,7 @@ import static com.mongodb.AuthenticationMechanism.MONGODB_X509;
 import static com.mongodb.AuthenticationMechanism.PLAIN;
 import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_1;
 import static java.lang.String.format;
+import static java.util.Arrays.asList;
 
 
 /**
@@ -472,6 +472,10 @@ public class ConnectionString {
         if (optionsMap.containsKey("wtimeout") && !optionsMap.containsKey("wtimeoutms")) {
             optionsMap.put("wtimeoutms", optionsMap.remove("wtimeout"));
         }
+        // JAVA-1433 handle legacy slaveok settings
+        if (optionsMap.containsKey("slaveok") && !optionsMap.containsKey("readpreference")) {
+            optionsMap.put("readpreference", asList("secondaryPreferred"));
+        }
 
         return optionsMap;
     }
@@ -593,7 +597,7 @@ public class ConnectionString {
      * @return the credentials
      */
     public List<MongoCredential> getCredentialList() {
-        return credentials != null ? Arrays.asList(credentials) : new ArrayList<MongoCredential>();
+        return credentials != null ? asList(credentials) : new ArrayList<MongoCredential>();
     }
 
     /**
Project mongodb/mongo-java-driver in file ...atomicoperations.FindAndReplaceAcceptanceTest.java (2015-02-26)
@@ -25,13 +25,13 @@ import org.bson.Document;
 import org.bson.codecs.DocumentCodecProvider;
 import org.bson.codecs.ValueCodecProvider;
 import org.bson.codecs.configuration.CodecRegistry;
-import org.bson.codecs.configuration.RootCodecRegistry;
 import org.bson.types.ObjectId;
 import org.junit.Test;
 
-import java.util.Arrays;
 import java.util.Date;
 
+import static java.util.Arrays.asList;
+import static org.bson.codecs.configuration.CodecRegistryHelper.fromProviders;
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertNull;
@@ -63,8 +63,7 @@ public class FindAndReplaceAcceptanceTest extends DatabaseTestCase {
     @Test
     public void shouldReplaceAndReturnOriginalItemWithDocumentRequiringACustomEncoder() {
         Worker pat = new Worker(new ObjectId(), "Pat", "Sales", new Date(), 0);
-        CodecRegistry codecRegistry = new RootCodecRegistry(Arrays.asList(new ValueCodecProvider(),
-                new DocumentCodecProvider(),
+        CodecRegistry codecRegistry = fromProviders(asList(new ValueCodecProvider(), new DocumentCodecProvider(),
                 new WorkerCodecProvider()));
         MongoCollection<Worker> collection = database
                 .getCollection(getCollectionName(), Worker.class)
@@ -84,8 +83,7 @@ public class FindAndReplaceAcceptanceTest extends DatabaseTestCase {
     @Test
     public void shouldReplaceAndReturnNewItemWithDocumentRequiringACustomEncoder() {
         Worker pat = new Worker(new ObjectId(), "Pat", "Sales", new Date(), 3);
-        CodecRegistry codecRegistry = new RootCodecRegistry(Arrays.asList(new ValueCodecProvider(),
-                new DocumentCodecProvider(),
+        CodecRegistry codecRegistry = fromProviders(asList(new ValueCodecProvider(), new DocumentCodecProvider(),
                 new WorkerCodecProvider()));
         MongoCollection<Worker> collection = database
                 .getCollection(getCollectionName(), Worker.class)