/** Find (all) ways intersecting ways which match the expression. */
    private void init(boolean all) {
      Collection<Way> matchedWays = new HashSet<Way>();
      Set<Node> matchedNodes = new HashSet<Node>();

      // find all ways that match the expression
      Collection<Way> allWays = Main.main.getCurrentDataSet().getWays();
      for (Way way : allWays) {
        if (match.match(way)) matchedWays.add(way);
      }

      // find all nodes that match the expression
      Collection<Node> allNodes = Main.main.getCurrentDataSet().getNodes();
      for (Node node : allNodes) {
        if (match.match(node)) matchedNodes.add(node);
      }

      Set<Way> newWays = new HashSet<Way>();
      if (all) {
        NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
        NodeWayUtils.addWaysConnectedToWaysRecursively(matchedWays, newWays);
      } else {
        NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
        NodeWayUtils.addWaysConnectedToWays(matchedWays, newWays);
      }
      connected = newWays;
    }
    /** Find (all) ways intersecting ways which match the expression. */
    private void init(boolean all) {
      Collection<Way> matchedWays = new HashSet<Way>();

      // find all ways that match the expression
      Collection<Way> allWays = Main.main.getCurrentDataSet().getWays();
      for (Way way : allWays) {
        if (match.match(way)) matchedWays.add(way);
      }

      Set<Way> newWays = new HashSet<Way>();
      if (all) NodeWayUtils.addWaysIntersectingWaysRecursively(allWays, matchedWays, newWays);
      else NodeWayUtils.addWaysIntersectingWays(allWays, matchedWays, newWays);
      intersecting = newWays;
    }
 @Override
 public void actionPerformed(ActionEvent e) {
   final String baseName = OdPlugin.getInstance().getDialog().getDataLayer().getName();
   final DataSet baseDs = getCurrentDataSet();
   for (OsmPrimitive boundary : getBoundaries()) {
     DataSet data = new DataSet();
     for (OsmPrimitive p :
         NodeWayUtils.selectAllInside(Collections.singleton(boundary), baseDs)) {
       if (p instanceof Node) {
         data.addPrimitive(new Node((Node) p));
       } else if (p instanceof Way) {
         data.addPrimitive(new Way((Way) p));
       } else if (p instanceof Relation) {
         data.addPrimitive(new Relation((Relation) p));
       }
     }
     if (!data.allPrimitives().isEmpty()) {
       String name = boundary.get("name");
       if (name == null || name.isEmpty()) {
         name = boundary.get("ref");
       }
       if (name == null || name.isEmpty()) {
         name = boundary.get("description");
       }
       Main.main.addLayer(
           new OdDataLayer(data, baseName + "/" + name, null, ToulouseDataSetHandler.this));
     }
   }
 }
    /** Find all objects inside areas which match the expression */
    private void init() {
      Collection<OsmPrimitive> matchedAreas = new HashSet<OsmPrimitive>();

      // find all ways that match the expression
      Collection<Way> ways = Main.main.getCurrentDataSet().getWays();
      for (Way way : ways) {
        if (match.match(way)) matchedAreas.add(way);
      }

      // find all relations that match the expression
      Collection<Relation> rels = Main.main.getCurrentDataSet().getRelations();
      for (Relation rel : rels) {
        if (match.match(rel)) matchedAreas.add(rel);
      }

      inside = NodeWayUtils.selectAllInside(matchedAreas, Main.main.getCurrentDataSet());
    }