@@ -52,7 +52,7 @@ public static Gson gson() {
5252                    @ Override 
5353                    /** 
5454                     * Deserialize a parse tree JSON to ParseTree class object. 
55-                      * @author: Adam Yi < xuan@yiad.am>  
55+                      * @author: Adam Yi < xuan@yiad.am>  
5656                     */ 
5757                    public  ParseTree  deserialize (JsonElement  json , Type  typeOfT , JsonDeserializationContext  context ) throws  JsonParseException  {
5858                        JsonObject  treeObj  = json .getAsJsonObject ();
@@ -187,7 +187,7 @@ public static String simpleObjectToJson(Object object, String typeKey) {
187187                break ;
188188
189189            case  Globals .TYPE_CARD_LIST :
190-                 type  = new  TypeToken <ArrayList <HashMap <String ,Object >>>(){
190+                 type  = new  TypeToken <ArrayList <HashMap <String ,  Object >>>()  {
191191                }.getType ();
192192                break ;
193193            default :
@@ -224,7 +224,7 @@ public static Object jsonToSimpleObject(String json, String typeKey) {
224224                }.getType ();
225225                break ;
226226            case  Globals .TYPE_CARD_LIST :
227-                 type  = new  TypeToken <ArrayList <HashMap <String ,Object >>>(){
227+                 type  = new  TypeToken <ArrayList <HashMap <String ,  Object >>>()  {
228228                }.getType ();
229229                break ;
230230            default :
@@ -237,15 +237,21 @@ public static HashMap<String, Object> refactorHashMap(HashMap<String, Object> mM
237237        return  refactorHashMap (mMap , 0 );
238238    }
239239
240-     //-1: integer only mode 
241-     //0: smart mode 
242-     //1: long only mode 
243-     public  static  HashMap <String ,Object > refactorHashMap (HashMap <String ,Object > mMap , int  mode ){
244-         for (String  key :mMap .keySet ()){
245-             if (mMap .get (key )!=null  && (mMap .get (key ) instanceof  Double ||mMap .get (key ) instanceof  Float )){
240+     /** 
241+      * Check all double and float values in a hash map. If they are integers, cast them to 
242+      * the data type that they should be. 
243+      * 
244+      * @param mMap the hash map to be refactored 
245+      * @param mode -1: Integer only Mode; 0: Smart Mode; 1: Long only Mode 
246+      * @return the hash map after refactoring 
247+      * @author Adam Yi <xuan@yiad.am> 
248+      */ 
249+     public  static  HashMap <String , Object > refactorHashMap (HashMap <String , Object > mMap , int  mode ) {
250+         for  (String  key  : mMap .keySet ()) {
251+             if  (mMap .get (key ) != null  && (mMap .get (key ) instanceof  Double  || mMap .get (key ) instanceof  Float )) {
246252                Double  mDouble  = (Double ) mMap .get (key );
247253                long  mLong  = mDouble .longValue ();
248-                 if (mDouble  == mLong ){
254+                 if   (mDouble  == mLong )  {
249255                    if  (mode  == 1 ) {
250256                        mMap .put (key , mLong );
251257                        continue ;
@@ -256,7 +262,7 @@ public static HashMap<String,Object> refactorHashMap(HashMap<String,Object> mMap
256262                        continue ;
257263                    }
258264                    if  (mInt  == mLong )
259-                         mMap .put (key ,mInt );
265+                         mMap .put (key ,  mInt );
260266                    else 
261267                        mMap .put (key , mLong );
262268                }
@@ -265,27 +271,43 @@ public static HashMap<String,Object> refactorHashMap(HashMap<String,Object> mMap
265271        return  mMap ;
266272    }
267273
268-     public  static  Long  longValue (Object  num ) throws  UnsupportedOperationException {
274+     /** 
275+      * Cast a number Object to Long 
276+      * 
277+      * @param num the object to be casted 
278+      * @return the casted Long 
279+      * @throws UnsupportedOperationException 
280+      * @author Adam Yi <xuan@yiad.am> 
281+      */ 
282+     public  static  Long  longValue (Object  num ) throws  UnsupportedOperationException  {
269283        if  (num  instanceof  Long )
270-             return  (Long )num ;
284+             return  (Long )  num ;
271285        if  (num  instanceof  Integer )
272-             return  Long .valueOf ((int )num );
286+             return  Long .valueOf ((int )  num );
273287        if  (num  instanceof  Double )
274-             return  Long .valueOf ((long )(double )num );
288+             return  Long .valueOf ((long )  (double )  num );
275289        if  (num  instanceof  Float )
276-             return  Long .valueOf ((long )(float )num );
290+             return  Long .valueOf ((long )  (float )  num );
277291        throw  new  UnsupportedOperationException ();
278292    }
279293
280-     public  static  Integer  intValue (Object  num ) throws  UnsupportedOperationException {
294+     /** 
295+      * Cast a number Object to Integer 
296+      * 
297+      * @param num the object to be casted 
298+      * @return the casted Integer 
299+      * @throws UnsupportedOperationException 
300+      * @author Adam Yi <xuan@yiad.am> 
301+      */ 
302+     public  static  Integer  intValue (Object  num ) throws  UnsupportedOperationException  {
281303        if  (num  instanceof  Integer )
282304            return  (Integer ) num ;
283305        if  (num  instanceof  Long )
284-             return  Integer .valueOf ((int )(long )num );
306+             return  Integer .valueOf ((int )  (long )  num );
285307        if  (num  instanceof  Double )
286-             return  Integer .valueOf ((int )(double )num );
308+             return  Integer .valueOf ((int )  (double )  num );
287309        if  (num  instanceof  Float )
288-             return  Integer .valueOf ((int )(float )num );
310+             return  Integer .valueOf ((int )  (float )  num );
289311        throw  new  UnsupportedOperationException ();
290312    }
291313}
0 commit comments