001    // License: GPL. For details, see LICENSE file.
002    package org.openstreetmap.josm.data.osm;
003    
004    /**
005     * Convenience class allowing to manage primitives in the dataset. Useful especially for tests
006     *
007     */
008    public class DatasetFactory {
009    
010        private final DataSet ds;
011    
012        public DatasetFactory() {
013            ds = new DataSet();
014        }
015    
016        public DatasetFactory(DataSet ds) {
017            this.ds = ds;
018        }
019    
020        public Node getNode(long id) {
021            return (Node) ds.getPrimitiveById(id, OsmPrimitiveType.NODE);
022        }
023    
024        public Way getWay(long id) {
025            return (Way) ds.getPrimitiveById(id, OsmPrimitiveType.WAY);
026        }
027    
028        public Relation getRelation(long id) {
029            return (Relation) ds.getPrimitiveById(id, OsmPrimitiveType.RELATION);
030        }
031    
032        public Node addNode(long id) {
033            return addNode(id, 0);
034        }
035    
036        public Way addWay(long id) {
037            return addWay(id, 0);
038        }
039    
040        public Relation addRelation(long id) {
041            return addRelation(id, 0);
042        }
043    
044        public Node addNode(long id, int version) {
045            Node n = new Node(id, version);
046            ds.addPrimitive(n);
047            return n;
048        }
049    
050        public Way addWay(long id, int version) {
051            Way w = new Way(id, version);
052            ds.addPrimitive(w);
053            return w;
054        }
055    
056        public Relation addRelation(long id, int version) {
057            Relation e = new Relation(id, version);
058            ds.addPrimitive(e);
059            return e;
060        }
061    
062    }