Мое пользовательское сравнение:
Код: Выделить всё
@Override
public int compareTo(Lead other) {
// Compare by ID first
int idComparison = this._id.compareTo(other._id);
if (idComparison != 0) {
return idComparison;
}
int emailComparison = this.email.compareTo(other.email);
if (emailComparison != 0) {
return emailComparison;
}
// If IDs are the same, compare by date (latest first)
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date1 = dateFormat.parse( this.entryDate);
Date date2 = dateFormat.parse( other.entryDate);
return date1.compareTo(date2);
} catch (ParseException e) {
return 0; // Handle parsing errors appropriately
}
Код: Выделить всё
// convert the JSON data to a Java object
LeadsData leads = gson.fromJson(reader, LeadsData.class);
// Remove duplicates using TreeSet
TreeSet uniqueRecords = new TreeSet(leads.leads);
Подробнее здесь: https://stackoverflow.com/questions/791 ... -compareto
Мобильная версия