두 개의 ArrayList에서 다른 요소를 모두 보유하고 별도의 배열에 저장하려고합니다. 로컬 및 원격 ArrayList가 있습니다 (로컬은 내 장치에 있으며 로컬 데이터베이스에서 읽음으로써 생성합니다). 리모컨은 내 서버에서 가져온 것 같습니다. 로컬 목록에서 모든 요소를 id로 삭제하기 위해 로컬과 리모트 사이의 모든 차이점을 가져 오지 못하게하고 싶습니다 (리모트 위치에는 가장 최근의 데이터가 들어 있다고 가정). 다른 요소에 포함되지 않은 요소 목록 반환 [Java/ANDROID]
내 원격 목록
는이 하나[
Property{id=174, userID=8, address='4', price='3', lastUpdated='1466437959249'},
Property{id=175, userID=8, address='6 Lamond Place, Aberdeen, AB25 3UT', price='1', lastUpdated='1466437965391'},
Property{id=176, userID=8, address='26 Meadgrey, Edinburgh, EH4', price='4', lastUpdated='1466438561094'}
]
이것은 내가 지금 뭐하는 거지 :
public void retainAllLocalFromRemote(List<Property> remoteProperties) {
ArrayList<Property> localProperties = getAllPropertyItems();
Log.d(TAG, "Local db size: " + localProperties.size());
Log.d(TAG, "Remote db size: " + remoteProperties.size());
ArrayList<Property> differences = new ArrayList<>();
for(int i = 0; i < localProperties.size(); i ++){
if(remoteProperties.contains(localProperties.get(i))){
Log.d(TAG, "remote contains local property with id: " + localProperties.get(i).getId());
}else {
differences.add(localProperties.get(i));
}
}
Log.d(TAG, "differences list size: " + differences.size());
Log.d(TAG, "differences list : " + differences.toString());
}
이가 내 로컬 목록은
[
{
"userID": 8,
"address": "6 Lamond Place, Aberdeen, AB25 3UT",
"price": 1,
"lastUpdated": "1466437965391",
"id": 175
},
{
"userID": 8,
"address": "26 Meadgrey, Edinburgh, EH4",
"price": 4,
"lastUpdated": "1466438561094",
"id": 176
}
]
이 데이터를 포함
내 현재 로그 출력 :Getting all properties from the database...
06-21 09:54:50.965 10585-10585/xdesign.georgi.espc_retrofit D/EspcItemDataSource: Local db size: 3
06-21 09:54:50.965 10585-10585/xdesign.georgi.espc_retrofit D/EspcItemDataSource: Remote db size: 2
06-21 09:54:50.966 10585-10585/xdesign.georgi.espc_retrofit D/EspcItemDataSource: differences list size: 3
06-21 10:00:48.192 10585-10585/xdesign.georgi.espc_retrofit D/EspcItemDataSource: differences list :[
Property{id=174, userID=8, address='4', price='3', lastUpdated='1466437959249'},
Property{id=175, userID=8, address='6 Lamond Place, Aberdeen, AB25 3UT', price='1', lastUpdated='1466437965391'},
Property{id=176, userID=8, address='26 Meadgrey, Edinburgh, EH4', price='4', lastUpdated='1466438561094'}]
차이 목록이 크기 여야하기 때문에 분명히 잘못된 것이 있습니다. 내가 뭘 잘못하고 있니?
Property.equals()는 어떤 모양입니까? –
@TimCastelijns 아니요. 내 Property 클래스에서 구현하지 않았습니다. 그게 내가 잘못 된 결과를 얻는 이유입니까? –