Changeset 11038 in josm for trunk


Ignore:
Timestamp:
2016-09-21T21:37:13+02:00 (3 years ago)
Author:
simon04
Message:

Use Relation.getMemberPrimitivesList where possible to avoid unnecessary set creation

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r10621 r11038  
    335335            }
    336336        }
    337         ways.removeAll(rel.getMemberPrimitives());
     337        ways.removeAll(rel.getMemberPrimitivesList());
    338338        for (final Way way : ways) {
    339339            rel.addMember(new RelationMember(role, way));
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r10413 r11038  
    4040        Set<OsmPrimitive> members = new HashSet<>();
    4141        for (Relation r: relations) {
    42             members.addAll(r.getMemberPrimitives());
     42            members.addAll(r.getMemberPrimitivesList());
    4343        }
    4444        if (add) {
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r10728 r11038  
    1010import java.util.Map;
    1111import java.util.Set;
     12import java.util.stream.Collectors;
    1213
    1314import org.openstreetmap.josm.Main;
     
    7273    }
    7374
     75    /**
     76     * Returns the relation member at the specified index.
     77     * @param index the index of the relation member
     78     * @return relation member at the specified index
     79     */
    7480    public RelationMember getMember(int index) {
    7581        return members[index];
    7682    }
    7783
     84    /**
     85     * Adds the specified relation member at the last position.
     86     * @param member the member to add
     87     */
    7888    public void addMember(RelationMember member) {
    7989        boolean locked = writeLock();
     
    8898    }
    8999
     100    /**
     101     * Adds the specified relation member at the specified index.
     102     * @param member the member to add
     103     * @param index the index at which the specified element is to be inserted
     104     */
    90105    public void addMember(int index, RelationMember member) {
    91106        boolean locked = writeLock();
     
    383398     * @return the set of  {@link OsmPrimitive}s referred to by at least one
    384399     * member of this relation
     400     * @see #getMemberPrimitivesList()
    385401     */
    386402    public Set<OsmPrimitive> getMemberPrimitives() {
    387         Set<OsmPrimitive> ret = new HashSet<>();
    388         RelationMember[] members = this.members;
    389         for (RelationMember m: members) {
    390             if (m.getMember() != null) {
    391                 ret.add(m.getMember());
    392             }
    393         }
    394         return ret;
    395     }
    396 
     403        return getMembers().stream().map(RelationMember::getMember).collect(Collectors.toSet());
     404    }
     405
     406    /**
     407     * Returns the {@link OsmPrimitive}s of the specified type referred to by at least one member of this relation.
     408     * @param tClass the type of the primitive
     409     * @param <T> the type of the primitive
     410     * @return the primitives
     411     */
    397412    public <T extends OsmPrimitive> Collection<T> getMemberPrimitives(Class<T> tClass) {
    398         return Utils.filteredCollection(getMemberPrimitives(), tClass);
    399     }
    400 
     413        return Utils.filteredCollection(getMemberPrimitivesList(), tClass);
     414    }
     415
     416    /**
     417     * Returns an unmodifiable list of the {@link OsmPrimitive}s referred to by at least one member of this relation.
     418     * @return an unmodifiable list of the primitives
     419     */
    401420    public List<OsmPrimitive> getMemberPrimitivesList() {
    402421        return Utils.transform(getMembers(), RelationMember::getMember);
     
    549568    protected void keysChangedImpl(Map<String, String> originalKeys) {
    550569        super.keysChangedImpl(originalKeys);
    551         for (OsmPrimitive member : getMemberPrimitives()) {
     570        for (OsmPrimitive member : getMemberPrimitivesList()) {
    552571            member.clearCachedStyle();
    553572        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r10345 r11038  
    224224        }
    225225        // Erase style cache for polygon members
    226         for (OsmPrimitive member : r.getMemberPrimitives()) {
     226        for (OsmPrimitive member : r.getMemberPrimitivesList()) {
    227227            member.clearCachedStyle();
    228228        }
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/data/PrimitiveTransferData.java

    r10868 r11038  
    1919import org.openstreetmap.josm.data.osm.Way;
    2020import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     21import org.openstreetmap.josm.tools.CompositeList;
    2122
    2223/**
     
    4041                return ((Way) primitive).getNodes();
    4142            } else if (primitive instanceof Relation) {
    42                 return ((Relation) primitive).getMemberPrimitives();
     43                return ((Relation) primitive).getMemberPrimitivesList();
    4344            } else {
    4445                return Collections.emptyList();
     
    102103     */
    103104    public Collection<PrimitiveData> getAll() {
    104         ArrayList<PrimitiveData> list = new ArrayList<>();
    105         list.addAll(direct);
    106         list.addAll(referenced);
    107         return list;
     105        return new CompositeList<>(direct, referenced);
    108106    }
    109107
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r10882 r11038  
    1010import java.util.function.IntFunction;
    1111import java.util.function.IntSupplier;
     12import java.util.Set;
    1213import java.util.regex.PatternSyntaxException;
    1314
     
    315316                    final Relation multipolygon = multipolygons.iterator().next();
    316317                    if (multipolygon == null) throw new NoSuchElementException();
     318                    final Set<OsmPrimitive> members = multipolygon.getMemberPrimitives();
    317319                    containsFinder = new ContainsFinder(new Environment(multipolygon)) {
    318320                        @Override
    319321                        public boolean isPrimitiveUsable(OsmPrimitive p) {
    320                             return super.isPrimitiveUsable(p) && !multipolygon.getMemberPrimitives().contains(p);
     322                            return super.isPrimitiveUsable(p) && !members.contains(p);
    321323                        }
    322324                    };
  • trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java

    r10446 r11038  
    8888            seenRelations.add(r);
    8989            boolean needRepaint = false;
    90             for (OsmPrimitive m : r.getMemberPrimitives()) {
     90            for (OsmPrimitive m : r.getMemberPrimitivesList()) {
    9191                if (!(m instanceof Relation) || !seenRelations.contains(m)) {
    9292                    needRepaint |= setHighlight(m, flag, seenRelations);
Note: See TracChangeset for help on using the changeset viewer.