@@ -97,72 +97,73 @@ public AbstractElement toAbstract(BsonValue value) {
9797 }
9898
9999 public BsonValue toBson (AbstractElement element ) {
100- if (element == null || element .isNull ())
100+ if (element == null || element .isNull ())
101101 return BsonNull .VALUE ;
102- if (element .isString ())
102+ if (element .isString ())
103103 return new BsonString (element .string ());
104- if (element .isBoolean ())
104+ if (element .isBoolean ())
105105 return new BsonBoolean (element .bool ());
106- if (element .isNumber ()) {
106+ if (element .isNumber ()) {
107107 Number n = element .number ();
108- if (n instanceof Integer || n instanceof Short || n instanceof Byte ) {
108+ if (n instanceof Integer || n instanceof Short || n instanceof Byte ) {
109109 return new BsonInt32 (n .intValue ());
110- } else if (n instanceof Long ) {
110+ } else if (n instanceof Long ) {
111111 return new BsonInt64 (n .longValue ());
112- } else if (n instanceof Float || n instanceof Double ) {
112+ } else if (n instanceof Float || n instanceof Double ) {
113113 return new BsonDouble (n .doubleValue ());
114114 }
115115 }
116- if (element .isArray ()) {
116+ if (element .isArray ()) {
117117 BsonArray a = new BsonArray ();
118- for (AbstractElement e : element .array ())
118+ for (AbstractElement e : element .array ())
119119 a .add (toBson (e ));
120120 return a ;
121121 }
122122 AbstractObject o = element .object ();
123- if (o .size () == 1 && o .has ("$oid" ) && o .get ("$oid" ).isString ())
123+ if (o .size () == 1 && o .has ("$oid" ) && o .get ("$oid" ).isString ())
124124 return new BsonObjectId (new ObjectId (o .string ("$oid" )));
125- if (o .size () == 1 && o .has ("$undefined" ) && o .get ("$undefined" ).isBoolean ())
125+ if (o .size () == 1 && o .has ("$undefined" ) && o .get ("$undefined" ).isBoolean ())
126126 return new BsonUndefined ();
127- if (o .size () == 1 && o .has ("$date" ) && o .get ("$date" ).isString ()) {
127+ if (o .size () == 1 && o .has ("$date" ) && o .get ("$date" ).isString ()) {
128128 try {
129129 return new BsonDateTime (dateFormat .parse (o .string ("$date" )).getTime ());
130- } catch (ParseException ignored ) {}
130+ } catch (ParseException ignored ) {
131+ }
131132 }
132- if (o .size () == 1 && o .has ("$numberDecimal" ) && o .get ("$numberDecimal" ).isString ())
133+ if (o .size () == 1 && o .has ("$numberDecimal" ) && o .get ("$numberDecimal" ).isString ())
133134 return new BsonDecimal128 (Decimal128 .parse (o .string ("$numberDecimal" )));
134- if (o .size () == 1 && o .has ("$minKey" ) && o .get ("$minKey" ).isNumber ())
135+ if (o .size () == 1 && o .has ("$minKey" ) && o .get ("$minKey" ).isNumber ())
135136 return new BsonMinKey ();
136- if (o .size () == 1 && o .has ("$maxKey" ) && o .get ("$maxKey" ).isNumber ())
137+ if (o .size () == 1 && o .has ("$maxKey" ) && o .get ("$maxKey" ).isNumber ())
137138 return new BsonMinKey ();
138- if (o .size () == 1 && o .has ("$symbol" ) && o .get ("$symbol" ).isString ())
139+ if (o .size () == 1 && o .has ("$symbol" ) && o .get ("$symbol" ).isString ())
139140 return new BsonSymbol (o .string ("$symbol" ));
140- if (o .size () == 1 && o .has ("$code" ) && o .get ("$code" ).isString ())
141+ if (o .size () == 1 && o .has ("$code" ) && o .get ("$code" ).isString ())
141142 return new BsonJavaScript (o .string ("$code" ));
142- if (o .size () == 2 && o .has ("$code" ) && o .has ("$scope" ) && o .get ("$code" ).isString () && o .get ("$scope" ).isObject ())
143+ if (o .size () == 2 && o .has ("$code" ) && o .has ("$scope" ) && o .get ("$code" ).isString () && o .get ("$scope" ).isObject ())
143144 return new BsonJavaScriptWithScope (o .string ("$code" ), toBson (o .get ("$scope" )).asDocument ());
144- if (o .size () == 1 && o .has ("$timestamp" ) && o .get ("$timestamp" ).isObject ()) {
145+ if (o .size () == 1 && o .has ("$timestamp" ) && o .get ("$timestamp" ).isObject ()) {
145146 AbstractObject ts = o .object ("$timestamp" );
146- if (ts .has ("t" ) && ts .has ("i" ) && ts .get ("t" ).isNumber () && ts .get ("i" ).isNumber ()) {
147+ if (ts .has ("t" ) && ts .has ("i" ) && ts .get ("t" ).isNumber () && ts .get ("i" ).isNumber ()) {
147148 return new BsonTimestamp ((int ) ts .number ("t" ).longValue (), (int ) ts .number ("i" ).longValue ());
148149 }
149150 }
150- if (o .size () == 1 && o .has ("$regularExpression" ) && o .get ("$regularExpression" ).isObject ()) {
151+ if (o .size () == 1 && o .has ("$regularExpression" ) && o .get ("$regularExpression" ).isObject ()) {
151152 AbstractObject re = o .object ("$regularExpression" );
152- if (re .has ("pattern" ) && re .has ("options" ) && re .get ("pattern" ).isString () && (re .get ("options" ).isString () || re .get ("options" ).isNull ())) {
153+ if (re .has ("pattern" ) && re .has ("options" ) && re .get ("pattern" ).isString () && (re .get ("options" ).isString () || re .get ("options" ).isNull ())) {
153154 return new BsonRegularExpression (re .string ("pattern" ), (String ) re .toObject ());
154155 }
155156 }
156- if (o .size () == 1 && o .has ("$binary" ) && o .get ("$binary" ).isObject ()) {
157+ if (o .size () == 1 && o .has ("$binary" ) && o .get ("$binary" ).isObject ()) {
157158 AbstractObject bin = o .object ("$binary" );
158- if (bin .has ("base64" ) && bin .has ("subType" ) && bin .get ("base64" ).isString () && bin .get ("subType" ).isString ()) {
159+ if (bin .has ("base64" ) && bin .has ("subType" ) && bin .get ("base64" ).isString () && bin .get ("subType" ).isString ()) {
159160 byte [] data = Base64 .getDecoder ().decode (bin .string ("base64" ));
160161 byte type = (byte ) Integer .parseInt (bin .string ("subType" ), 16 );
161162 return new BsonBinary (type , data );
162163 }
163164 }
164165 BsonDocument doc = new BsonDocument (o .size ());
165- for (String k : o .keys ())
166+ for (String k : o .keys ())
166167 doc .put (k , toBson (o .get (k )));
167168 return doc ;
168169 }
0 commit comments