Ticket #3587: josm-null-pointer-quad-1.patch

File josm-null-pointer-quad-1.patch, 2.6 KB (added by hansendc, 16 years ago)

fixes both bugs. compile but not runtime tested

  • src/org/openstreetmap/josm/data/osm/QuadBuckets.java

     
    667667    public void unsupported()
    668668    {
    669669        out("unsupported operation");
    670         Object o = null;
    671         o.hashCode();
    672670        throw new UnsupportedOperationException();
    673671    }
    674672    public boolean retainAll(Collection nodes)
    675673    {
    676         unsupported();
    677         return false;
     674        for (Node n : this) {
     675            if (nodes.contains(n))
     676                continue;
     677            if (!this.remove(n))
     678                return false;
     679        }
     680        return true;
    678681    }
    679682    public boolean removeAll(Collection nodes)
    680683    {
    681         unsupported();
    682         return false;
     684        for (Object o : nodes) {
     685            if (!(o instanceof Node))
     686                return false;
     687            Node n = (Node)o;
     688            if (!this.remove(n))
     689                return false;
     690        }
     691        return true;
    683692    }
    684693    public boolean addAll(Collection nodes)
    685694    {
    686         unsupported();
    687         return false;
     695        for (Object o : nodes) {
     696            if (!(o instanceof Node))
     697                return false;
     698            Node n = (Node)o;
     699            if (!this.add(n))
     700                return false;
     701        }
     702        return true;
    688703    }
    689704    public boolean containsAll(Collection nodes)
    690705    {
    691         unsupported();
    692         return false;
     706        boolean ret = true;
     707        for (Object o : nodes) {
     708            if (!(o instanceof Node))
     709                return false;
     710            Node n = (Node)o;
     711            if (!this.contains(n))
     712                return false;
     713        }
     714        return true;
    693715    }
    694716    private void check_type(Object o)
    695717    {
     
    711733    }
    712734    public boolean contains(Object o)
    713735    {
    714         check_type(o);
     736        if (!(o instanceof Node))
     737            return false;
    715738        QBLevel bucket = root.find_exact((Node)o);
    716739        if (bucket == null)
    717740            return false;
     
    807830        }
    808831        public void remove()
    809832        {
    810             Node object = peek();
    811             current_leaf.content.remove(object);
     833            // two uses
     834            // 1. Back up to the thing we just returned
     835            // 2. move the index back since we removed
     836            //    an element
     837            index_in_leaf--;
     838            current_leaf.content.remove(index_in_leaf);
    812839        }
    813840    }
    814841    public Iterator<Node> iterator()