| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of gcloud.db; | 5 part of gcloud.db; |
| 6 | 6 |
| 7 /// Annotation used to mark dart classes which can be stored into datastore. | 7 /// Annotation used to mark dart classes which can be stored into datastore. |
| 8 /// | 8 /// |
| 9 /// The `Kind` annotation on a class as well as other `Property` annotations on | 9 /// The `Kind` annotation on a class as well as other `Property` annotations on |
| 10 /// fields or getters of the class itself (and any of it's superclasses) up to | 10 /// fields or getters of the class itself (and any of it's superclasses) up to |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 for (var entry in value) { | 251 for (var entry in value) { |
| 252 if (!subProperty.validate(db, entry)) return false; | 252 if (!subProperty.validate(db, entry)) return false; |
| 253 } | 253 } |
| 254 return true; | 254 return true; |
| 255 } | 255 } |
| 256 | 256 |
| 257 Object encodeValue(ModelDB db, Object value) { | 257 Object encodeValue(ModelDB db, Object value) { |
| 258 if (value == null) return null; | 258 if (value == null) return null; |
| 259 List list = value; | 259 List list = value; |
| 260 if (list.length == 0) return null; | 260 if (list.length == 0) return null; |
| 261 if (list.length == 1) return list[0]; | 261 if (list.length == 1) return subProperty.encodeValue(db, list[0]); |
| 262 return list.map( | 262 return list.map( |
| 263 (value) => subProperty.encodeValue(db, value)).toList(); | 263 (value) => subProperty.encodeValue(db, value)).toList(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 Object decodePrimitiveValue(ModelDB db, Object value) { | 266 Object decodePrimitiveValue(ModelDB db, Object value) { |
| 267 if (value == null) return []; | 267 if (value == null) return []; |
| 268 if (value is! List) return [value]; | 268 if (value is! List) return [subProperty.decodePrimitiveValue(db, value)]; |
| 269 return (value as List) | 269 return (value as List) |
| 270 .map((entry) => subProperty.decodePrimitiveValue(db, entry)) | 270 .map((entry) => subProperty.decodePrimitiveValue(db, entry)) |
| 271 .toList(); | 271 .toList(); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 /// A convenience [Property] for list of strings. | 275 /// A convenience [Property] for list of strings. |
| 276 class StringListProperty extends ListProperty { | 276 class StringListProperty extends ListProperty { |
| 277 const StringListProperty({String propertyName, bool indexed: true}) | 277 const StringListProperty({String propertyName, bool indexed: true}) |
| 278 : super(const StringProperty(), | 278 : super(const StringProperty(), |
| 279 propertyName: propertyName, indexed: indexed); | 279 propertyName: propertyName, indexed: indexed); |
| 280 } | 280 } |
| OLD | NEW |