Changeset 15987 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-03-01T23:36:04+01:00 (5 years ago)
Author:
simon04
Message:

see #18802 - Selector: merge GeneralSelector/OptimizedGeneralSelector as there is no difference

  • GeneralSelector extended OptimizedGeneralSelector
  • GeneralSelector.optimizedBaseCheck returned OptimizedGeneralSelector === this
Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r15984 r15987  
    5454import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource.MapCSSRuleIndex;
    5555import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
    56 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector;
     56import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
    5757import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
    5858import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
     
    453453        /**
    454454         * Determines the {@code index}-th key/value/tag (depending on {@code type}) of the
    455          * {@link org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector}.
     455         * {@link GeneralSelector}.
    456456         * @param matchingSelector matching selector
    457457         * @param index index
     
    460460         * @return argument value, can be {@code null}
    461461         */
    462         static String determineArgument(OptimizedGeneralSelector matchingSelector, int index, String type, OsmPrimitive p) {
     462        static String determineArgument(GeneralSelector matchingSelector, int index, String type, OsmPrimitive p) {
    463463            try {
    464464                final Condition c = matchingSelector.getConditions().get(index);
     
    492492            if (s != null && matchingSelector instanceof Selector.ChildOrParentSelector) {
    493493                return insertArguments(((Selector.ChildOrParentSelector) matchingSelector).right, s, p);
    494             } else if (s == null || !(matchingSelector instanceof Selector.OptimizedGeneralSelector)) {
     494            } else if (s == null || !(matchingSelector instanceof GeneralSelector)) {
    495495                return s;
    496496            }
     
    498498            final StringBuffer sb = new StringBuffer();
    499499            while (m.find()) {
    500                 final String argument = determineArgument((Selector.OptimizedGeneralSelector) matchingSelector,
     500                final String argument = determineArgument((GeneralSelector) matchingSelector,
    501501                        Integer.parseInt(m.group(1)), m.group(2), p);
    502502                try {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerIndex.java

    r15986 r15987  
    8989                }
    9090
    91                 MapCSSRule optRule = new MapCSSRule(s.optimizedBaseCheck(), c.rule.declaration);
     91                MapCSSRule optRule = new MapCSSRule(s, c.rule.declaration);
    9292
    9393                ruleToCheckMap.put(optRule, c);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r15986 r15987  
    461461            }
    462462            // optimization: filter rules for different primitive types
    463             for (MapCSSRule r: rules) {
    464                 MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration);
    465                 final String base = r.selector.getBase();
     463            for (MapCSSRule optRule: rules) {
     464                final String base = optRule.selector.getBase();
    466465                switch (base) {
    467466                    case Selector.BASE_NODE:
     
    488487                        break;
    489488                    case Selector.BASE_CANVAS:
    490                         canvasRules.add(r);
     489                        canvasRules.add(optRule);
    491490                        break;
    492491                    case Selector.BASE_META:
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r15986 r15987  
    113113
    114114    String getBase();
    115 
    116     /**
    117      * Create an "optimized" copy of this selector that omits the base check.
    118      *
    119      * For the style source, the list of rules is preprocessed, such that
    120      * there is a separate list of rules for nodes, ways, ...
    121      *
    122      * This means that the base check does not have to be performed
    123      * for each rule, but only once for each primitive.
    124      *
    125      * @return a selector that is identical to this object, except the base of the
    126      * "rightmost" selector is not checked
    127      */
    128     Selector optimizedBaseCheck();
    129115
    130116    /**
     
    484470            if (e.osm.getDataSet() == null) {
    485471                // do nothing
    486             } else if (left instanceof OptimizedGeneralSelector) {
    487                 if (withNodes && ((OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.NODE)) {
     472            } else if (left instanceof GeneralSelector) {
     473                if (withNodes && ((GeneralSelector) left).matchesBase(OsmPrimitiveType.NODE)) {
    488474                    finder.visit(e.osm.getDataSet().searchNodes(e.osm.getBBox()));
    489475                }
    490                 if (((OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.WAY)) {
     476                if (((GeneralSelector) left).matchesBase(OsmPrimitiveType.WAY)) {
    491477                    finder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox()));
    492478                }
    493                 if (((OptimizedGeneralSelector) left).matchesBase(OsmPrimitiveType.RELATION)) {
     479                if (((GeneralSelector) left).matchesBase(OsmPrimitiveType.RELATION)) {
    494480                    finder.visit(e.osm.getDataSet().searchRelations(e.osm.getBBox()));
    495481                }
     
    621607
    622608        @Override
    623         public Selector optimizedBaseCheck() {
    624             return new ChildOrParentSelector(left, link, right.optimizedBaseCheck(), type);
    625         }
    626 
    627         @Override
    628609        public String toString() {
    629610            return left.toString() + ' ' + (ChildOrParentSelectorType.PARENT == type ? '<' : '>') + link + ' ' + right;
     
    701682
    702683        @Override
    703         public Selector optimizedBaseCheck() {
    704             throw new UnsupportedOperationException();
    705         }
    706 
    707         @Override
    708684        public String toString() {
    709685            return "LinkSelector{conditions=" + conds + '}';
     
    714690     * General selector. See <a href="https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#Selectors">wiki</a>
    715691     */
    716     class GeneralSelector extends OptimizedGeneralSelector {
    717 
    718         public GeneralSelector(String base, Range zoom, List<Condition> conds, Subpart subpart) {
    719             super(base, zoom, conds, subpart);
    720         }
    721 
    722         public boolean matchesConditions(Environment e) {
    723             return super.matches(e);
    724         }
    725 
    726         @Override
    727         public Selector optimizedBaseCheck() {
    728             return new OptimizedGeneralSelector(this);
    729         }
    730 
    731         @Override
    732         public boolean matches(Environment e) {
    733             return matchesBase(e) && super.matches(e);
    734         }
    735     }
    736 
    737     /**
    738      * Superclass of {@link GeneralSelector}. Used to create an "optimized" copy of this selector that omits the base check.
    739      * @see Selector#optimizedBaseCheck
    740      */
    741     class OptimizedGeneralSelector extends AbstractSelector {
     692    class GeneralSelector extends AbstractSelector {
     693
    742694        public final String base;
    743695        public final Range range;
    744696        public final Subpart subpart;
    745697
    746         public OptimizedGeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) {
     698        public GeneralSelector(String base, Range range, List<Condition> conds, Subpart subpart) {
    747699            super(conds);
    748700            this.base = checkBase(base);
     
    751703        }
    752704
    753         public OptimizedGeneralSelector(GeneralSelector s) {
    754             this(s.base, s.range, s.conds, s.subpart);
    755         }
    756 
    757705        @Override
    758706        public Subpart getSubpart() {
     
    763711        public Range getRange() {
    764712            return range;
     713        }
     714
     715        public boolean matchesConditions(Environment e) {
     716            return super.matches(e);
     717        }
     718
     719        @Override
     720        public boolean matches(Environment e) {
     721            return matchesBase(e) && super.matches(e);
    765722        }
    766723
     
    824781        }
    825782
    826         @Override
    827         public Selector optimizedBaseCheck() {
    828             throw new UnsupportedOperationException();
    829         }
    830 
    831783        public static Range fromLevel(int a, int b) {
    832784            // for input validation in Range constructor below
Note: See TracChangeset for help on using the changeset viewer.