0

私は特定のエリアのプロパティのリストを提供するWebサービスを持っています私の問題は、リストに2つ以上のプロパティがあり、そのプロパティがgoogleの同じバブルに表示される場合は、すべてのプロパティをマップに表示する必要があることですmap結果を解析しましたが、xmlで同じlatとlongを持つプロパティをフィルタリングできません。arraylistを解析した後のようにしようとしていますreturn:-

 private Vector groupTheList(ArrayList<Applicationdataset> arrayList) 
{
    Vector<ArrayList<Applicationdataset>> mgroupvector = new Vector<ArrayList<Applicationdataset>>();
    ArrayList<Applicationdataset> mfirstList = new ArrayList<Applicationdataset>();
    ArrayList<Applicationdataset> mylist=null;
    int sizeoflist = arrayList.size();
    for(int index =0;index<arrayList.size();index++)
    {
         //ArrayList<Applicationdataset> mylist= mgroupvector.get(index);
         if(mylist==null)
         {
             mylist = new ArrayList<Applicationdataset>(); 
         }
         mfirstList.add(arrayList.get(index));

        for(int mindex=1;mindex<arrayList.size();mindex++)
        {
         if(arrayList.get(index).getLatitude().equalsIgnoreCase(arrayList.get(mindex).getLatitude()) &&
                 arrayList.get(index).getLongitude().equalsIgnoreCase(arrayList.get(mindex).getLongitude()))
         {
             mfirstList.add(arrayList.get(mindex));
             arrayList.remove(mindex);
         }
        }
        mylist.addAll(mfirstList);
        mgroupvector.add(mylist);
        mfirstList.clear();
        arrayList.remove(index);
        index-=1;
    }
    mgroupvector.add(arrayList);
    return mgroupvector;

}   

しかし、さらに私は誰もすることができません私を助けてください。誰か助けてください。

4

1 に答える 1

1

このようなもの:

.......
private Collection<List<Applicationdataset>> groupTheList(ArrayList<Applicationdataset> arrayList) {
    Map<Key, List<Applicationdataset>> map = new HashMap<Key, List<Applicationdataset>>();
    for(Applicationdataset appSet: arrayList){
        Key<String, String> key = new Key(appSet.getLatitude(), appSet.getLongtitude());
        List<Applicationdataset> list = map.get(key);
        if(list == null){
            list = new ArrayList<Applicationdataset>();
            map.put(key, list);
        }
        list.add(appset);
    }
    return map.values();
}
........

class Key {
    String _lat;
    String _lon;

    Key(String lat, String lon) {
        _lat = lat;
        _lon = lon;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Key key = (Key) o;

        if (!_lat.equals(key._lat)) return false;
        if (!_lon.equals(key._lon)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = _lat.hashCode();
        result = 31 * result + _lon.hashCode();
        return result;
    }
}
于 2012-06-26T14:02:23.527 に答える