This is the first time that I have considered using LinkedHashSet in my Android code and I am not sure if it can be used and how to use it.
I have a class (Class_1) where it is extracted from a JSONObject, using the loopj library for the connection and transference of json, an array which has an indeterminate number of objects inside each of them composed of 4 elements:
Id (unique)
Temperature
Moisture
Inserted (this is timestamp)
This data comes from my server, where in PHP and through a JOIN of tables prepares a json. It is for this reason that duplicate objects exist in said received element.
{"result":[{"Id":"621","temperatura":"35","humedad":"45","Insertado":"2016-08-30 12:53:36"},{......},{.....}...]}
These are stored in an Object "parametrosdht11" and then it is used through an interface in a second class (Class_2) where they will be processed to create a graph.
for (int i=0; i<cast.length(); i++) {
JSONObject parametrosdht11 = cast.getJSONObject(i);
loopjListener.onLoopjTaskCompletedBarometro(parametrosdht11, i);
}
loopjListener.onLoopCompleteBarometro();
So far everything works well, for this reason I do not put all the code, now, I see the need to delete duplicate objects (leaving only one of them) within the Json Array that I send to class_2. For this reason I consider using LinkedHashSet.
I would appreciate if you could help me, because I'm not sure I can use this interface and secondly I do not know how to implement it, so I would appreciate an example in code, as the subject says, I'm in Java but in Android. Thanks.
Update:
Example of the Json, as the repetitions are observed ....
{"result":[{"Id_temp":"1","temperatura":"20","Insertado_temp":"2016-08-16 12:30:29","Id_press":"1","presion":"34","Insertado_press":"2016-08-16 16:18:36","Id_alt":"1","altitud":"11","Insertado_alt":"2016-08-16 16:37:57"},
{"Id_temp": "1", "temperature": "20", "Insert_temp": "2016-08-16 12:30:29", "Id_press": "3", "pressure": " 55 "," Insert_press ":" 2016-08-16 16:22:14 "," Id_alt ":" 1 "," altitude ":" 11 "," Insert_alt ":" 2016-08-16 16:37: 57 "}, {" Id_temp ":" 1 "," temperature ":" 20 "," Insert_temp ":" 2016-08-16 12:30:29 "," Id_press ":" 4 "," pressure ": "55.45", "Insert_press": "2016-08-16 16:22:42", "Id_alt": "1", "altitude": "11", "Insert_alt": "2016-08-16 16:37 : 57 "}, {" Id_temp ":" 1 "," temperature ":" 20 "," Insert_temp ":" 2016-08-16 12:30:29 "," Id_press ":" 6 "," pressure " : "50", "Insert_press": "2016-08-16 18:26:27", "Id_alt": "1", "altitude": "11", "Insert_alt": "2016-08-16 16: 37:57 "}, {" Id_temp ":" 1 "," temperature ":" 20 "," Insert_temp ":" 2016-08-16 12:30:29 "," Id_press ":" 7 "," pressure ":" 50 "," Insert_press ":" 2016-08-16 18:28:13 "," Id_alt ":" 1 "," altitude ":" 11 "," Insert_alt ":" 2016-08-16 16 : 37: 57 "}, {" Id_temp ":" 1 "," temperature ":" 20 "," Insert_temp ":" 2016-08-16 12:30:29 "," Id_press ":" 8 "," pressure ":" 50 "," Insert_press ":" 2016-08-16 18:28:45 "," Id_alt ":" 1 "," altitude ":" 11 "," Insert_alt ":" 2016-08-16 16:37:57 "}, {" Id_temp ":" 1 "," temperature ":" 20 "," Insert_temp ":" 2016-08-16 12:30:29 "," Id_press ":" 1 "," pressure ":" 34 "," Insert_press ":" 2016-08-16 .blabla .....