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

« back to all changes in this revision

Viewing changes to src/uk/me/parabola/mkgmap/osmstyle/actions/NameAction.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: 02-Dec-2008
 
16
 */
 
17
package uk.me.parabola.mkgmap.osmstyle.actions;
 
18
 
 
19
import java.util.ArrayList;
 
20
import java.util.List;
 
21
 
 
22
import uk.me.parabola.mkgmap.reader.osm.Element;
 
23
 
 
24
/**
 
25
 * Set the name on the given element.  The tags of the element may be
 
26
 * used in setting the name.
 
27
 *
 
28
 * We have a list of possible substitutions.
 
29
 *
 
30
 * @author Steve Ratcliffe
 
31
 */
 
32
public class NameAction implements Action {
 
33
 
 
34
        private final List<ValueBuilder> names = new ArrayList<ValueBuilder>();
 
35
 
 
36
        /**
 
37
         * search for the first matching name pattern and set the element name
 
38
         * to it.
 
39
         *
 
40
         * If the element name is already set, then nothing is done.
 
41
         *
 
42
         * @param el The element on which the name may be set.
 
43
         */
 
44
        public void perform(Element el) {
 
45
                if (el.getName() != null)
 
46
                        return;
 
47
                
 
48
                for (ValueBuilder vb : names) {
 
49
                        String s = vb.build(el);
 
50
                        if (s != null) {
 
51
                                el.setName(s);
 
52
                                break;
 
53
                        }
 
54
                }
 
55
        }
 
56
 
 
57
        public void add(String val) {
 
58
                ValueBuilder vb = new ValueBuilder(val);
 
59
                names.add(vb);
 
60
        }
 
61
 
 
62
        public String toString() {
 
63
                StringBuilder sb = new  StringBuilder();
 
64
                sb.append("name ");
 
65
                for (ValueBuilder vb : names) {
 
66
                        sb.append(vb);
 
67
                        sb.append("|");
 
68
                }
 
69
                sb.setLength(sb.length() - 1);
 
70
                return sb.toString();
 
71
        }
 
72
}