Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 7d1ff12

Browse files
committed
Added type aliases and companion objects
Code now under the org.mongodb.scala namespace - Unified the api docs - Fixed Documentation syntax errors - Added type aliases and companion objects to mirror the Java API SCALA-157
1 parent d341402 commit 7d1ff12

File tree

94 files changed

+6009
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+6009
-532
lines changed

core/rootdoc.txt

-4
This file was deleted.

core/src/main/scala/com/mongodb/scala/Implicits.scala

-166
This file was deleted.

core/src/main/scala/com/mongodb/scala/Helpers.scala renamed to core/src/main/scala/org/mongodb/scala/Helpers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala
17+
package org.mongodb.scala
1818

1919
import scala.language.implicitConversions
2020

core/src/main/scala/com/mongodb/scala/codecs/DocumentCodecProvider.scala renamed to core/src/main/scala/org/mongodb/scala/codecs/DocumentCodecProvider.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala.codecs
17+
package org.mongodb.scala.codecs
1818

1919
import org.bson.codecs.Codec
2020
import org.bson.codecs.configuration.{CodecProvider, CodecRegistry}
21-
import com.mongodb.scala.collection.{immutable, mutable}
21+
import org.mongodb.scala.collection.{immutable, mutable}
2222

2323
/**
24-
* A {@code CodecProvider} for the Document class and all the default Codec implementations on which it depends.
25-
*
24+
* A [[http://api.mongodb.org/java/current/org/bson/codecs/configuration/CodecProvider.html CodecProvider]] for the Document
25+
* class and all the default Codec implementations on which it depends.
2626
*/
2727
case class DocumentCodecProvider() extends CodecProvider {
2828

core/src/main/scala/com/mongodb/scala/codecs/ImmutableDocumentCodec.scala renamed to core/src/main/scala/org/mongodb/scala/codecs/ImmutableDocumentCodec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala.codecs
17+
package org.mongodb.scala.codecs
1818

1919
import org.bson.codecs.configuration.CodecRegistry
2020
import org.bson.codecs.{BsonDocumentCodec, CollectibleCodec, DecoderContext, EncoderContext}
2121
import org.bson.{BsonReader, BsonValue, BsonWriter}
22-
import com.mongodb.scala.collection.immutable.Document
22+
import org.mongodb.scala.collection.immutable.Document
2323

2424
/**
2525
* Companion helper for immutable Document instances.

core/src/main/scala/com/mongodb/scala/codecs/MutableDocumentCodec.scala renamed to core/src/main/scala/org/mongodb/scala/codecs/MutableDocumentCodec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala.codecs
17+
package org.mongodb.scala.codecs
1818

1919
import org.bson.codecs.configuration.CodecRegistry
2020
import org.bson.codecs.{BsonDocumentCodec, CollectibleCodec, DecoderContext, EncoderContext}
2121
import org.bson.{BsonReader, BsonValue, BsonWriter}
22-
import com.mongodb.scala.collection.mutable.Document
22+
import org.mongodb.scala.collection.mutable.Document
2323

2424
/**
2525
* Companion helper for mutable Document instances.

core/src/main/scala/com/mongodb/scala/codecs/package.scala renamed to core/src/main/scala/org/mongodb/scala/codecs/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala
17+
package org.mongodb.scala
1818

1919
import org.bson.codecs.configuration.CodecRegistries._
2020
import org.bson.codecs.configuration.CodecRegistry

core/src/main/scala/com/mongodb/scala/collection/BaseDocument.scala renamed to core/src/main/scala/org/mongodb/scala/collection/BaseDocument.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala.collection
17+
package org.mongodb.scala.collection
1818

1919
import scala.collection.JavaConverters._
2020
import scala.collection.{GenTraversableOnce, Traversable}
@@ -24,7 +24,7 @@ import scala.util.{Failure, Success, Try}
2424
import org.bson._
2525
import org.bson.codecs.configuration.CodecRegistry
2626
import org.bson.conversions.Bson
27-
import com.mongodb.scala.Helpers.DefaultsTo
27+
import org.mongodb.scala.Helpers.DefaultsTo
2828

2929
/**
3030
* Base Document trait.
@@ -69,12 +69,9 @@ trait BaseDocument[T] extends Traversable[(String, BsonValue)] with Bson {
6969
* @param key the key.
7070
* @param default a computation that yields a default value in case no binding for `key` is
7171
* found in the map.
72-
* @tparam B1 the result type of the default computation.
72+
* @tparam B the result type of the default computation.
7373
* @return the value associated with `key` if it exists,
7474
* otherwise the result of the `default` computation.
75-
*
76-
* @usecase def getOrElse(key: A, default: => B): B
77-
* @inheritdoc
7875
*/
7976
def getOrElse[B >: BsonValue](key: String, default: => B): B = get(key) match {
8077
case Some(v) => v

core/src/main/scala/com/mongodb/scala/collection/immutable/Document.scala renamed to core/src/main/scala/org/mongodb/scala/collection/immutable/Document.scala

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.mongodb.scala.collection.immutable
17+
package org.mongodb.scala.collection.immutable
1818

1919
import scala.collection.JavaConverters._
2020
import scala.collection.generic.CanBuildFrom
2121
import scala.collection.mutable.{Builder, ListBuffer}
2222
import scala.collection.{Traversable, TraversableLike}
2323

2424
import org.bson.{BsonDocument, BsonValue}
25-
import com.mongodb.scala.collection.BaseDocument
25+
import org.mongodb.scala.collection.BaseDocument
2626

2727

2828
/**
@@ -42,6 +42,16 @@ object Document {
4242
*/
4343
def apply(): Document = Document(new BsonDocument())
4444

45+
/**
46+
* Parses a string in MongoDB Extended JSON format to a `Document`
47+
*
48+
* @param json the JSON string
49+
* @return a corresponding `Document` object
50+
* @see org.bson.json.JsonReader
51+
* @see [[http://docs.mongodb.com/manual/reference/mongodb-extended-json/ MongoDB Extended JSON]]
52+
*/
53+
def apply(json: String): Document = Document(BsonDocument.parse(json))
54+
4555
/**
4656
* Create a new document from the elems
4757
* @param elems the key/value pairs that make up the Document
@@ -68,6 +78,7 @@ object Document {
6878
implicit def canBuildFrom: CanBuildFrom[Traversable[(String, BsonValue)], (String, BsonValue), Document] = {
6979
new CanBuildFrom[Traversable[(String, BsonValue)], (String, BsonValue), Document] {
7080
def apply(): Builder[(String, BsonValue), Document] = builder
81+
7182
def apply(from: Traversable[(String, BsonValue)]): Builder[(String, BsonValue), Document] = builder
7283
}
7384
}
@@ -85,15 +96,13 @@ object Document {
8596
* An immutable Document implementation.
8697
*
8798
* A strictly typed `Map[String, BsonValue]` like structure that traverses the elements in insertion order. Unlike native scala maps there
88-
* is no variance in the value type and it always has to be a `BsonValue`. The [[com.mongodb.scala.Implicits]]
99+
* is no variance in the value type and it always has to be a `BsonValue`. The [[org.mongodb.scala.implicits]]
89100
* helper provides simple interactions with Documents taking native data types and converting them to `BsonValues`.
90101
*
91-
* @note All user operations on the document are immutable. The *only* time the document can mutate state is when an `_id` is added by
92-
* the underlying [[com.mongodb.scala.codecs.ImmutableDocumentCodec]] codec on insertion to the database.
93102
* @param underlying the underlying BsonDocument which stores the data.
94103
*/
95104
case class Document(protected[scala] val underlying: BsonDocument)
96-
extends BaseDocument[Document] with TraversableLike[(String, BsonValue), Document] {
105+
extends BaseDocument[Document] with TraversableLike[(String, BsonValue), Document] {
97106

98107
/**
99108
* Creates a new immutable document
@@ -112,8 +121,6 @@ case class Document(protected[scala] val underlying: BsonDocument)
112121
* This result will always be ignored. Typically `U` is `Unit`,
113122
* but this is not necessary.
114123
*
115-
* @usecase def foreach(f: A => Unit): Unit
116-
* @inheritdoc
117124
*/
118125
override def foreach[U](f: ((String, BsonValue)) => U): Unit = underlying.asScala foreach f
119126

0 commit comments

Comments
 (0)