| 1 | package relcontext.relationfix;
|
|---|
| 2 |
|
|---|
| 3 | import java.util.ArrayList;
|
|---|
| 4 | import java.util.List;
|
|---|
| 5 |
|
|---|
| 6 | import org.openstreetmap.josm.command.Command;
|
|---|
| 7 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 8 |
|
|---|
| 9 | public abstract class RelationFixer {
|
|---|
| 10 |
|
|---|
| 11 | private List<String> applicableTypes;
|
|---|
| 12 |
|
|---|
| 13 | {
|
|---|
| 14 | applicableTypes = new ArrayList<String>();
|
|---|
| 15 | }
|
|---|
| 16 | /**
|
|---|
| 17 | * Construct new RelationFixer by only one applicable relation type
|
|---|
| 18 | * @param type
|
|---|
| 19 | */
|
|---|
| 20 | public RelationFixer(String type) {
|
|---|
| 21 | applicableTypes.add(type);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * Construct new RelationFixer by an array of applicable types
|
|---|
| 26 | * @param types
|
|---|
| 27 | */
|
|---|
| 28 | public RelationFixer(String[] types) {
|
|---|
| 29 | for(String type: types) {
|
|---|
| 30 | applicableTypes.add(type);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * Check if given relation is of needed type. You may override this method to check first type
|
|---|
| 36 | * and then check desired relation properties.
|
|---|
| 37 | * Note that this only verifies if current RelationFixer can be used to check and fix given relation
|
|---|
| 38 | * Deeper relation checking is at {@link isRelationGood}
|
|---|
| 39 | *
|
|---|
| 40 | * @param rel Relation to check
|
|---|
| 41 | * @return true if relation can be verified by current RelationFixer
|
|---|
| 42 | */
|
|---|
| 43 | public boolean isFixerApplicable(Relation rel) {
|
|---|
| 44 | if (rel == null)
|
|---|
| 45 | return false;
|
|---|
| 46 | if (!rel.hasKey("type"))
|
|---|
| 47 | return false;
|
|---|
| 48 |
|
|---|
| 49 | String type = rel.get("type");
|
|---|
| 50 | for(String oktype: applicableTypes)
|
|---|
| 51 | if (oktype.equals(type))
|
|---|
| 52 | return true;
|
|---|
| 53 |
|
|---|
| 54 | return false;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /**
|
|---|
| 58 | * Check if given relation is OK. That means if all roles are given properly, all tags exist as expected etc.
|
|---|
| 59 | * Should be written in children classes.
|
|---|
| 60 | *
|
|---|
| 61 | * @param rel Relation to verify
|
|---|
| 62 | * @return true if given relation is OK
|
|---|
| 63 | */
|
|---|
| 64 | public abstract boolean isRelationGood(Relation rel);
|
|---|
| 65 |
|
|---|
| 66 | /**
|
|---|
| 67 | * Fix relation and return new relation with fixed tags, roles etc.
|
|---|
| 68 | * Note that is not obligatory to return true for isRelationGood for new relation
|
|---|
| 69 | *
|
|---|
| 70 | * @param rel Relation to fix
|
|---|
| 71 | * @return command that fixes the relation {@code null} if it cannot be fixed or is already OK
|
|---|
| 72 | */
|
|---|
| 73 | public abstract Command fixRelation(Relation rel);
|
|---|
| 74 | }
|
|---|