java - Comparing two ArrayList using Gson? -


i trying compare 2 arraylist< map< string, object>> objects problem need compare them in different app sessions. saving first arraylist in sharedpreferences after converting string using gson. query string in next session compare it. tried converting arraylist comparing list generated during new session. tried converting new list json , comparing both texts. result same. below relevant code:

declaration:

arraylist<map<string, object>> tweetmaparray = new arraylist<>(); 

then in method :

list<twitter4j.status> statuses = twitter.getusertimeline(params[0], new paging(1, 200));              tweetmaparray.clear(); // reusing                 (twitter4j.status status : statuses) {                     map<string, object> valuestoputinmarker = new hashmap<>();                     valuestoputinmarker.put("id", status.getid());                     valuestoputinmarker.put("status", status.gettext());                     tweetmaparray.add(valuestoputinmarker); } 

now saving tweetmaparray in sharedpreferences:

                        string jsonstr = gson.tojson(tweetmaparray);                         editor = configdata.edit();                         editor.putstring("tweetdata", jsonstr);                         editor.apply(); 

querying data:

private boolean seeifthedataisnew() { string datafromsharedpreferences = configdata.getstring("tweetdata", null); type collectiontype2 = new typetoken<arraylist<map<string, object>>>() {     }.gettype();     arraylist<map<string, object>> oldtweets = gson.fromjson(datafromsharedpreferences, collectiontype2);      string jsonstr = gson.tojson(tweetmaparray);     return jsonstr.equalsignorecase(datafromsharedpreferences);      // or       return !(oldtweets.containsall(tweetmaparray) && tweetmaparray.containsall(oldtweets));  

here, both methods in last 2 lines return true. in testing sample should return false.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -