14
14
* limitations under the License.
15
15
*/
16
16
17
- package com .mongodb .scala . reactivestreams . client
17
+ package com .mongodb .scala
18
18
19
19
import java .util .Date
20
20
21
- import com .mongodb .scala .reactivestreams .client .Helpers .DefaultsTo
22
- import com .mongodb .scala .reactivestreams .client .collection .immutable .{ Document => ImmutableDocument }
23
- import com .mongodb .scala .reactivestreams .client .collection .mutable .{ Document => MutableDocument }
24
- import com .mongodb .scala .reactivestreams .client .collection .immutable .Document
25
- import org .bson ._
26
- import org .bson .types .ObjectId
21
+ import scala .language .implicitConversions
27
22
28
23
import scala .collection .JavaConverters ._
29
- import scala .language .implicitConversions
30
24
import scala .util .matching .Regex
31
- import scala .util .{ Failure , Success , Try }
25
+ import scala .util .{Failure , Success , Try }
26
+
27
+ import org .bson .types .ObjectId
28
+ import org .bson .{Document => JDocument , _ }
29
+ import com .mongodb .scala .Helpers .DefaultsTo
30
+ import com .mongodb .scala .collection .{immutable , mutable }
32
31
33
32
object Implicits extends FromAnyImplicits with IterableImplicits with DateTimeImplicits {
34
33
35
- implicit def immutableDocumentToBsonDocument (value : ImmutableDocument ): BsonDocument = value.underlying
34
+ implicit def immutableDocumentToBsonDocument (value : immutable. Document ): BsonDocument = value.underlying
36
35
37
- implicit def bsonDocumentToImmutableDocument (value : BsonDocument ): ImmutableDocument = ImmutableDocument (value)
36
+ implicit def bsonDocumentToImmutableDocument (value : BsonDocument ): immutable. Document = immutable. Document (value)
38
37
39
- implicit def mutableDocumentToBsonDocument (value : MutableDocument ): BsonDocument = value.underlying
38
+ implicit def mutableDocumentToBsonDocument (value : mutable. Document ): BsonDocument = value.underlying
40
39
41
- implicit def bsonDocumentToMutableDocument (value : BsonDocument ): MutableDocument = MutableDocument (value)
40
+ implicit def bsonDocumentToMutableDocument (value : BsonDocument ): mutable. Document = mutable. Document (value)
42
41
43
42
implicit def binaryArrayToBsonBinary (value : Array [Byte ]): BsonBinary = new BsonBinary (value)
44
43
@@ -107,7 +106,11 @@ trait IterableImplicits {
107
106
108
107
implicit def bsonArrayToIterableSymbol (value : BsonArray ): Iterable [Symbol ] = value.asScala map (v => Symbol (v.asSymbol().getSymbol))
109
108
110
- implicit def bsonArrayToIterableDocument (value : BsonArray ): Iterable [Document ] = value.asScala map (v => Document (v.asDocument()))
109
+ implicit def bsonArrayToIterableImmutableDocument (value : BsonArray ): Iterable [immutable.Document ] = value.asScala map (v =>
110
+ immutable.Document (v.asDocument()))
111
+
112
+ implicit def bsonArrayToIterableMutableDocument (value : BsonArray ): Iterable [mutable.Document ] = value.asScala map (v =>
113
+ mutable.Document (v.asDocument()))
111
114
112
115
implicit def bsonArrayToIterableIterable (value : BsonArray ): Iterable [Iterable [BsonValue ]] = value.asScala map (v => v.asArray().getValues.asScala)
113
116
@@ -132,31 +135,30 @@ trait FromAnyImplicits {
132
135
// scalastyle:off cyclomatic.complexity
133
136
implicit def anyToBsonValue (v : Any ): BsonValue = {
134
137
v match {
135
- case x @ (v : BsonValue ) => v
136
- case x @ (v : Array [Byte ]) => new BsonBinary (v)
137
- case x @ (v : Boolean ) => new BsonBoolean (v)
138
- case x @ (v : Date ) => new BsonDateTime (v.getTime)
139
- case x @ (v : Double ) => new BsonDouble (v)
140
- case x @ (v : Int ) => new BsonInt32 (v)
141
- case x @ (v : Long ) => new BsonInt64 (v)
142
- case x @ (v : ObjectId ) => new BsonObjectId (v)
143
- case x @ (v : String ) => new BsonString (v)
144
- case x @ (v : Symbol ) => new BsonSymbol (v.name)
145
- case x @ (v : Regex ) => new BsonRegularExpression (v.regex)
146
- case None => new BsonNull
147
- case x @ (v : ImmutableDocument ) => v.underlying
148
- case x @ (v : MutableDocument ) => v.underlying
149
- case x @ (v : Iterable [_]) => {
138
+ case x@ (v : BsonValue ) => v
139
+ case x@ (v : Array [Byte ]) => new BsonBinary (v)
140
+ case x@ (v : Boolean ) => new BsonBoolean (v)
141
+ case x@ (v : Date ) => new BsonDateTime (v.getTime)
142
+ case x@ (v : Double ) => new BsonDouble (v)
143
+ case x@ (v : Int ) => new BsonInt32 (v)
144
+ case x@ (v : Long ) => new BsonInt64 (v)
145
+ case x@ (v : ObjectId ) => new BsonObjectId (v)
146
+ case x@ (v : String ) => new BsonString (v)
147
+ case x@ (v : Symbol ) => new BsonSymbol (v.name)
148
+ case x@ (v : Regex ) => new BsonRegularExpression (v.regex)
149
+ case None => new BsonNull
150
+ case x@ (v : immutable. Document ) => v.underlying
151
+ case x@ (v : mutable. Document ) => v.underlying
152
+ case x@ (v : Iterable [_]) => {
150
153
Try (iterableAnyToBsonArray(v)) match {
151
154
case Success (bsonValue) => bsonValue
152
- case Failure (ex) => throw new BsonInvalidOperationException (s " Invalid type cannot be converted to a BsonValue: $v" )
155
+ case Failure (ex) => throw new BsonInvalidOperationException (s " Invalid type cannot be converted to a BsonValue: $v" )
153
156
}
154
157
}
155
158
case _ =>
156
159
throw new BsonInvalidOperationException (s " Invalid type cannot be converted to a BsonValue: $v" )
157
160
}
158
161
}
159
-
160
162
// scalastyle:on cyclomatic.complexity
161
163
162
164
private def iterableAnyToBsonArray [B ](value : Iterable [B ])(implicit e : B DefaultsTo BsonValue , ev : B => BsonValue ): BsonArray =
0 commit comments