Ignore:
Timestamp:
2011-10-29T09:01:30+02:00 (12 years ago)
Author:
jttt
Message:

Extend name templates with context switch - possibility to use tags of referenced primitive when constructing primitive name

File:
1 edited

Legend:

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

    r4377 r4546  
    6969        protected boolean existsMatch(Collection<? extends OsmPrimitive> primitives) {
    7070            for (OsmPrimitive p : primitives) {
    71                 if (match(p)) {
     71                if (match(p))
    7272                    return true;
    73                 }
    7473            }
    7574            return false;
     
    8180        protected boolean forallMatch(Collection<? extends OsmPrimitive> primitives) {
    8281            for (OsmPrimitive p : primitives) {
    83                 if (!match(p)) {
     82                if (!match(p))
    8483                    return false;
    85                 }
    8684            }
    8785            return true;
     
    110108        }
    111109        @Override public String toString() {return "!"+match;}
     110        public Match getMatch() {
     111            return match;
     112        }
    112113    }
    113114
     
    130131    }
    131132
    132     private static class And extends Match {
    133         private Match lhs;
    134         private Match rhs;
     133    public static class And extends Match {
     134        private final Match lhs;
     135        private final Match rhs;
    135136        public And(Match lhs, Match rhs) {this.lhs = lhs; this.rhs = rhs;}
    136137        @Override public boolean match(OsmPrimitive osm) {
     
    138139        }
    139140        @Override public String toString() {return lhs+" && "+rhs;}
    140     }
    141 
    142     private static class Or extends Match {
    143         private Match lhs;
    144         private Match rhs;
     141        public Match getLhs() {
     142            return lhs;
     143        }
     144        public Match getRhs() {
     145            return rhs;
     146        }
     147    }
     148
     149    public static class Or extends Match {
     150        private final Match lhs;
     151        private final Match rhs;
    145152        public Or(Match lhs, Match rhs) {this.lhs = lhs; this.rhs = rhs;}
    146153        @Override public boolean match(OsmPrimitive osm) {
     
    148155        }
    149156        @Override public String toString() {return lhs+" || "+rhs;}
     157        public Match getLhs() {
     158            return lhs;
     159        }
     160        public Match getRhs() {
     161            return rhs;
     162        }
    150163    }
    151164
     
    552565        public boolean match(OsmPrimitive osm) {
    553566            Integer count = getCount(osm);
    554             if (count == null) {
     567            if (count == null)
    555568                return false;
    556             } else {
     569            else
    557570                return (count >= minCount) && (count <= maxCount);
    558             }
    559571        }
    560572
     
    575587        @Override
    576588        protected Integer getCount(OsmPrimitive osm) {
    577             if (!(osm instanceof Way)) {
     589            if (!(osm instanceof Way))
    578590                return null;
    579             } else {
     591            else
    580592                return ((Way) osm).getNodesCount();
    581             }
    582593        }
    583594
     
    649660    }
    650661
    651     private static class Parent extends Match {
    652         private Match child;
    653         public Parent(Match m) { child = m; }
     662    public static class Parent extends Match {
     663        private final Match child;
     664        public Parent(Match m) {
     665            if (m == null) {
     666                // "parent" (null) should mean the same as "parent()"
     667                // (Always). I.e. match everything
     668                child = new Always();
     669            } else {
     670                child = m;
     671            }
     672        }
    654673        @Override public boolean match(OsmPrimitive osm) {
    655674            boolean isParent = false;
    656 
    657             // "parent" (null) should mean the same as "parent()"
    658             // (Always). I.e. match everything
    659             if (child == null) {
    660                 child = new Always();
    661             }
    662675
    663676            if (osm instanceof Way) {
     
    673686        }
    674687        @Override public String toString() {return "parent(" + child + ")";}
    675     }
    676 
    677     private static class Child extends Match {
     688        public Match getChild() {
     689            return child;
     690        }
     691    }
     692
     693    public static class Child extends Match {
    678694        private final Match parent;
    679695
     
    696712        }
    697713        @Override public String toString() {return "child(" + parent + ")";}
    698     }
    699    
     714
     715        public Match getParent() {
     716            return parent;
     717        }
     718    }
     719
    700720    /**
    701721     * Matches on the area of a closed way.
    702      * 
     722     *
    703723     * @author Ole Jørgen Brønner
    704724     */
     
    711731        @Override
    712732        protected Integer getCount(OsmPrimitive osm) {
    713             if (!(osm instanceof Way && ((Way) osm).isClosed())) {
     733            if (!(osm instanceof Way && ((Way) osm).isClosed()))
    714734                return null;
    715             }
    716735            Way way = (Way) osm;
    717736            return (int) Geometry.closedWayArea(way);
     
    743762        @Override
    744763        public boolean match(OsmPrimitive osm) {
    745             if (!osm.isUsable()) {
     764            if (!osm.isUsable())
    746765                return false;
    747             } else if (osm instanceof Node) {
     766            else if (osm instanceof Node)
    748767                return bounds.contains(((Node) osm).getCoor());
    749             } else if (osm instanceof Way) {
     768            else if (osm instanceof Way) {
    750769                Collection<Node> nodes = ((Way) osm).getNodes();
    751770                return all ? forallMatch(nodes) : existsMatch(nodes);
     
    753772                Collection<OsmPrimitive> primitives = ((Relation) osm).getMemberPrimitives();
    754773                return all ? forallMatch(primitives) : existsMatch(primitives);
    755             } else {
     774            } else
    756775                return false;
    757             }
    758776        }
    759777    }
     
    799817
    800818    public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch)
    801     throws ParseError {
     819            throws ParseError {
    802820        return new SearchCompiler(caseSensitive, regexSearch,
    803821                new PushbackTokenizer(
Note: See TracChangeset for help on using the changeset viewer.