I've made this function to check a number of error in a field of my app. So I've made this code:
private int getSegnalations(final Location location, DatabaseReference ref, final HashMap<Location,String>mapLocation) {
final List<Segnalation> matches = new LinkedList<>();
final String key = mapLocation.get(location);
Query query = ref.child("segnalation");
segnalationDialog = createProgressDialog(getActivity(),segnalationDialog,getString(R.string.download));
query.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
stopProgressDialog(segnalationDialog);
for(DataSnapshot dS : dataSnapshot.getChildren())
{
Segnalation segnalation = dS.getValue(Segnalation.class);
Log.d("keys:",segnalation.getIdPark()+","+mapLocation.get(location));
if(segnalation.getIdPark().equals(key))
{
matches.add(segnalation);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError)
{
stopProgressDialog(segnalationDialog);
showErrorMessage(getActivity(),getString(R.string.dbProblem));
}
});
return matches.size();
}
the bug is that Log.d show me this lines:
D/keys:: -KTijPwCAd7M7wdZms3S,-KTy7n4WcCx3IUWRsRDX
D/keys:: -KTjJYQGW8_k6Dpi_z7W,-KTy7n4WcCx3IUWRsRDX
D/keys:: -KTjKby31PU7PkJWrb5U,-KTy7n4WcCx3IUWRsRDX
D/keys:: -KTy7n4WcCx3IUWRsRDX,-KTy7n4WcCx3IUWRsRDX
but if is bypass and returns me size 0 and not 1.
Why? What is the error in this code?