~ubuntu-branches/ubuntu/oneiric/mkgmap/oneiric

« back to all changes in this revision

Viewing changes to src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine, Andreas Putzo, Francesco Paolo Lovergine
  • Date: 2009-07-16 11:10:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716111016-yycxqya1f26xmti7
Tags: 0.0.0+svn1067-1
[ Andreas Putzo ]
* New upstream snapshot.
* Added ${misc:Depends} among dependencies to fix a lintian warning.
* Bumped debhelper compatibility level to 7.
* Updated long description.
* Updated Homepage in debian/control, debian/copyright, debian/watch.
* Added numerous files from /doc to debian/docs.
* Mentioned Bernhard Heibler in debian/copyright and updated copyright
  year of software and packaging.
* Bumped policy to 3.8.2, without changes.
* Added DM-Upload-Allowed to debian/control.

[ Francesco Paolo Lovergine ]
* Added me as Uploader to avoid possible inappropriate NMU notices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Steve Ratcliffe
 
3
 * 
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License version 2 as
 
6
 *  published by the Free Software Foundation.
 
7
 * 
 
8
 *  This program is distributed in the hope that it will be useful,
 
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *  GNU General Public License for more details.
 
12
 * 
 
13
 * 
 
14
 * Author: Steve Ratcliffe
 
15
 * Create date: 15-Nov-2008
 
16
 */
 
17
package uk.me.parabola.mkgmap.osmstyle;
 
18
 
 
19
import java.util.List;
 
20
 
 
21
import uk.me.parabola.mkgmap.osmstyle.actions.Action;
 
22
import uk.me.parabola.mkgmap.osmstyle.eval.Op;
 
23
import uk.me.parabola.mkgmap.reader.osm.Element;
 
24
import uk.me.parabola.mkgmap.reader.osm.GType;
 
25
import uk.me.parabola.mkgmap.reader.osm.Rule;
 
26
 
 
27
/**
 
28
 * An action rule modifies the tags on the incoming element.
 
29
 *
 
30
 * It can also have an expression, and does not need to have a Type.  If
 
31
 * there is no type then the resolve method always returns false.  The tags
 
32
 * on the element may have been modified however.
 
33
 *
 
34
 * @author Steve Ratcliffe
 
35
 */
 
36
public class ActionRule implements Rule {
 
37
        private final Op expression;
 
38
        private final List<Action> actions;
 
39
        private final GType type;
 
40
 
 
41
        public ActionRule(Op expression, List<Action> actions, GType type) {
 
42
                assert actions != null;
 
43
                this.expression = expression;
 
44
                this.actions = actions;
 
45
                this.type = type;
 
46
        }
 
47
 
 
48
        public ActionRule(Op expression, List<Action> actions) {
 
49
                assert actions != null;
 
50
                this.expression = expression;
 
51
                this.actions = actions;
 
52
                this.type = null;
 
53
        }
 
54
 
 
55
        public GType resolveType(Element el) {
 
56
                if (expression == null || expression.eval(el)) {
 
57
                        for (Action a : actions)
 
58
                                a.perform(el);
 
59
 
 
60
                        return type;
 
61
                }
 
62
                return null;
 
63
        }
 
64
 
 
65
        public String toString() {
 
66
                StringBuilder fmt = new StringBuilder();
 
67
                if (expression != null)
 
68
                        fmt.append(expression);
 
69
 
 
70
                fmt.append("\n\t{");
 
71
                for (Action a : actions)
 
72
                        fmt.append(a);
 
73
                fmt.append("}\n");
 
74
 
 
75
                if (type != null) {
 
76
                        fmt.append('\t');
 
77
                        fmt.append(type);
 
78
                }
 
79
 
 
80
                return fmt.toString();
 
81
        }
 
82
}