Skip to content

Commit

Permalink
ignore single character switch (osmlab#283)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel B <[email protected]>
  • Loading branch information
Bentleysb and Daniel B authored May 1, 2020
1 parent a530c42 commit 153932d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@
},
"StreetNameIntegersOnlyCheck": {
"name.keys.filter":["name","name:left","name:right"],
"character.single.ignore": true,
"challenge": {
"description": "Tasks containing name tags with only integers",
"blurb": "Street Names Integers Only",
Expand Down
5 changes: 4 additions & 1 deletion docs/checks/streetNameIntegersOnlyCheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
This check flags roads that have only integers in their name.

An example of an improper name tag in this case is something like: `name=42`
Items like `name=1st Ave` are allowed, and not flagged.
Items like `name=1st Ave` are allowed, and not flagged.

To avoid overlap with [ShortNameCheck](../../src/main/java/org/openstreetmap/atlas/checks/validation/tag/ShortNameCheck.java),
this check can be configured to not flag any name tag with only a single character (i.e. `name=1` would not be flagged).

#### Live Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

/**
* This check flags {@link Edge}s that are car navigable highways and have a name tag that contains
* only integers.
* only integers. Name tags with a single character are optionally ignored, as they will be flagged
* by {@link ShortNameCheck}.
*
* @author bbreithaupt
*/
public class StreetNameIntegersOnlyCheck extends BaseCheck
public class StreetNameIntegersOnlyCheck extends BaseCheck<Long>
{

private static final long serialVersionUID = 3439708862406928654L;

private static final List<String> FALLBACK_INSTRUCTIONS = Arrays
Expand All @@ -35,6 +35,7 @@ public class StreetNameIntegersOnlyCheck extends BaseCheck
NameLeftTag.KEY, NameRightTag.KEY);

private final List<String> nameKeys;
private final boolean ignoreSingleCharacter;

/**
* The default constructor that must be supplied. The Atlas Checks framework will generate the
Expand All @@ -47,8 +48,9 @@ public class StreetNameIntegersOnlyCheck extends BaseCheck
public StreetNameIntegersOnlyCheck(final Configuration configuration)
{
super(configuration);
this.nameKeys = (List<String>) configurationValue(configuration, "name.keys.filter",
NAME_KEYS_DEFAULT);
this.nameKeys = configurationValue(configuration, "name.keys.filter", NAME_KEYS_DEFAULT);
this.ignoreSingleCharacter = configurationValue(configuration, "character.single.ignore",
false);
}

/**
Expand Down Expand Up @@ -81,7 +83,9 @@ protected Optional<CheckFlag> flag(final AtlasObject object)
for (final String nameKey : this.nameKeys)
{
final Optional<String> nameValue = object.getTag(nameKey);
if (nameValue.isPresent())
// Only test present name tags, and optionally ignore single character name values
if (nameValue.isPresent()
&& (!this.ignoreSingleCharacter || nameValue.get().length() > 1))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public void motorwayWithIntegerNameTagTest()
this.verifier.globallyVerify(flags -> Assert.assertEquals(1, flags.size()));
}

@Test
public void motorwayWithMixedNameTagIntegerNameLeftTagIgnoreSingleTest()
{
this.verifier.actual(this.setup.motorwayWithMixedNameTagIntegerNameLeftTagAtlas(),
new StreetNameIntegersOnlyCheck(ConfigurationResolver
.inlineConfiguration("{\"StreetNameIntegersOnlyCheck\": {\n"
+ " \"character.single.ignore\":true}}")));
this.verifier.globallyVerify(flags -> Assert.assertEquals(0, flags.size()));
}

@Test
public void motorwayWithMixedNameTagIntegerNameLeftTagOnlyCheckNameTest()
{
Expand Down

0 comments on commit 153932d

Please sign in to comment.