Ignore:
Timestamp:
2009-10-05T21:36:56+02:00 (15 years ago)
Author:
jttt
Message:

Cache values for hasDirection() and isTagged ()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2216 r2249  
    4141    private static final int FLAG_FILTERED = 1 << 4;
    4242    private static final int FLAG_SELECTED = 1 << 5;
     43    private static final int FLAG_HAS_DIRECTIONS = 1 << 6;
     44    private static final int FLAG_TAGGED = 1 << 7;
    4345
    4446    /**
     
    527529            this.keys = new HashMap<String, String>(keys);
    528530        }
     531        keysChangedImpl();
    529532    }
    530533
     
    550553        }
    551554        mappaintStyle = null;
     555        keysChangedImpl();
    552556    }
    553557    /**
     
    564568        }
    565569        mappaintStyle = null;
     570        keysChangedImpl();
    566571    }
    567572
     
    574579        keys = null;
    575580        mappaintStyle = null;
     581        keysChangedImpl();
    576582    }
    577583
     
    610616    public final boolean hasKeys() {
    611617        return keys != null && !keys.isEmpty();
     618    }
     619
     620    private void keysChangedImpl() {
     621        updateHasDirectionKeys();
     622        updateTagged();
    612623    }
    613624
     
    675686    }
    676687
     688    private void updateTagged() {
     689        getUninterestingKeys();
     690        if (keys != null) {
     691            for (Entry<String,String> e : keys.entrySet()) {
     692                if (!uninteresting.contains(e.getKey())) {
     693                    flags |= FLAG_TAGGED;
     694                    return;
     695                }
     696            }
     697        }
     698        flags &= ~FLAG_TAGGED;
     699    }
     700
    677701    /**
    678702     * true if this object is considered "tagged". To be "tagged", an object
     
    682706     */
    683707    public boolean isTagged() {
    684         // TODO Cache value after keys are made private
    685         getUninterestingKeys();
    686         if (keys != null) {
    687             for (Entry<String,String> e : keys.entrySet()) {
    688                 if (!uninteresting.contains(e.getKey()))
    689                     return true;
    690             }
    691         }
    692         return false;
    693     }
    694     /**
    695      * true if this object has direction dependent tags (e.g. oneway)
    696      */
    697     public boolean hasDirectionKeys() {
    698         // TODO Cache value after keys are made private
     708        return (flags & FLAG_TAGGED) != 0;
     709    }
     710
     711    private void updateHasDirectionKeys() {
    699712        getDirectionKeys();
    700713        if (keys != null) {
    701714            for (Entry<String,String> e : keys.entrySet()) {
    702                 if (directionKeys.contains(e.getKey()))
    703                     return true;
     715                if (directionKeys.contains(e.getKey())) {
     716                    flags |= FLAG_HAS_DIRECTIONS;
     717                    return;
     718                }
    704719            }
    705720        }
    706         return false;
     721        flags &= ~FLAG_HAS_DIRECTIONS;
     722    }
     723    /**
     724     * true if this object has direction dependent tags (e.g. oneway)
     725     */
     726    public boolean hasDirectionKeys() {
     727        return (flags & FLAG_HAS_DIRECTIONS) != 0;
    707728    }
    708729
Note: See TracChangeset for help on using the changeset viewer.