summaryrefslogtreecommitdiff
path: root/javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java')
-rw-r--r--javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java24
1 files changed, 13 insertions, 11 deletions
diff --git a/javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java b/javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java
index 30037bad6..e00101ef2 100644
--- a/javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java
+++ b/javaSE/javaSE/src/main/java/com/livio/BSON/BsonEncoder.java
@@ -47,7 +47,7 @@ public class BsonEncoder {
private static final String TAG = "BsonEncoder";
public static byte[] encodeToBytes(HashMap<String, Object> map) throws ClassCastException {
- if(map != null) {
+ if (map != null) {
BasicBSONObject bson = new BasicBSONObject();
bson.putAll(sanitizeMap(map));
BasicBSONEncoder encoder = new BasicBSONEncoder();
@@ -60,7 +60,7 @@ public class BsonEncoder {
}
public static HashMap<String, Object> decodeFromBytes(byte[] bytes) {
- if(bytes != null) {
+ if (bytes != null) {
BasicBSONDecoder decoder = new BasicBSONDecoder();
BSONObject object = decoder.readObject(bytes);
if (object != null) {
@@ -77,28 +77,29 @@ public class BsonEncoder {
/**
* Goes through the map and ensures that all the values included are supported by SDL. If they are not of a supported
* value it is removed from the map
+ *
* @param map the map to be sanitized
* @return a sanitized HashMap with non-supported object type removes
*/
- private static HashMap<String, Object> sanitizeMap(HashMap<String, Object> map){
+ private static HashMap<String, Object> sanitizeMap(HashMap<String, Object> map) {
Set<String> keys = map.keySet();
Object value;
- for(String key : keys){
+ for (String key : keys) {
value = map.get(key);
//First check to see if it value is a valid type used in SDL
- if(isSupportedType(value)){
+ if (isSupportedType(value)) {
continue;
- }else if(value instanceof List){ //Next, check to see if it is a list of values
- List list = (List)value;
+ } else if (value instanceof List) { //Next, check to see if it is a list of values
+ List list = (List) value;
//If the list is empty, there shouldn't be a problem leaving it in the map
- if(list.isEmpty()){
+ if (list.isEmpty()) {
continue;
}
//Since the list isn't empty, check the first item
- if(isSupportedType(list.get(0))){
+ if (isSupportedType(list.get(0))) {
continue;
}
}
@@ -111,10 +112,11 @@ public class BsonEncoder {
/**
* Checks the value to ensure it is of a supported type
- * @param value the generic object value
+ *
+ * @param value the generic object value
* @return if the object is an instanceOf one of the supported SDL BSON objects
*/
- private static boolean isSupportedType(Object value){
+ private static boolean isSupportedType(Object value) {
return value instanceof Integer
|| value instanceof Long
|| value instanceof Double