public static Optional<LeisureTag> get(final Taggable taggable) { return Validators.from(LeisureTag.class, taggable); } }
/** * Checks if an {@link AtlasObject} has a tag defining the minimum height of a building. * * @param object * {@link AtlasObject} to check * @return true if {@code object} has a tag defining the minimum height of a building */ private boolean hasMinKey(final AtlasObject object) { return Validators.hasValuesFor(object, BuildingMinLevelTag.class) || Validators.hasValuesFor(object, MinHeightTag.class); }
private static boolean validEdge(final Edge edge) { return Validators.isNotOfType(edge, HighwayTag.class, HighwayTag.NO) && Validators.isOfType(edge, AreaTag.class, AreaTag.YES) && edge.isMasterEdge(); }
/** * Looking for (highway=pedestrian or highway=footway) and (building = * or area=yes) tag * combination. These are pedestrian plazas and can contain valid road intersections. * * @param taggable * The taggable object being test * @return Whether the taggable object is a highway area or not */ public static boolean isHighwayArea(final Taggable taggable) { return Validators.isOfType(taggable, HighwayTag.class, HighwayTag.PEDESTRIAN, HighwayTag.FOOTWAY) && (Validators.isOfType(taggable, AreaTag.class, AreaTag.YES) || Validators.hasValuesFor(taggable, BuildingTag.class)); }
/** * Convenience method for checking and verifying a value without having to chain calls * * @param key * the key we want to verify * @param value * the value we want to verify against the allowed values for key * @return true if the value is valid for key, false otherwise */ public boolean isValidFor(final String key, final String value) { return canValidate(key) && getValidatorFor(key).isValid(value); }
public static boolean isPool(final AtlasEntity atlasEntity) { /* * natural=water water=reflecting_pool. It is safe to exclude private swimming pools * (leisure=swimming_pool) */ return Validators.isOfType(atlasEntity, NaturalTag.class, NaturalTag.WATER) && Validators.isOfType(atlasEntity, WaterTag.class, WaterTag.POOL); }
/** * Checks if an {@link AtlasObject} is a building or building:part that is valid for this check. * * @param object * {@link AtlasObject} to check * @return true if {@code object} has a {@code building:part=yes} tag */ private boolean isBuildingOrPart(final AtlasObject object) { return (BuildingTag.isBuilding(object) // Ignore roofs, as the are often used for items that have supports that are too // small to effectively map (such as a carport) && Validators.isNotOfType(object, BuildingTag.class, BuildingTag.ROOF)) || Validators.isNotOfType(object, BuildingPartTag.class, BuildingPartTag.NO); }
private void completed() { final Map<String, String> temporaryMap = new HashMap<>(); for (final Entry<IsoLanguage, Map<Class<?>, String>> entry : this.localizedResults .entrySet()) { final Optional<IsoLanguage> currentLanguage = Optional.of(entry.getKey()); for (final Entry<Class<?>, String> itemEntry : entry.getValue().entrySet()) { Validators.localizeKeyName(itemEntry.getKey(), currentLanguage) .ifPresent(localizedKeyName -> { temporaryMap.put(localizedKeyName, itemEntry.getValue()); }); } } for (final Entry<Class<?>, String> entry : this.nonLocalizedResults.entrySet()) { Validators.localizeKeyName(entry.getKey(), Optional.empty()) .ifPresent(nonLocalizedKeyName -> { temporaryMap.put(nonLocalizedKeyName, entry.getValue()); }); } this.flattenedMap = new ImmutableMap.Builder<String, String>().putAll(temporaryMap) .build(); }
public Optional<T> getTag(final Taggable taggable) { final Optional<String> possibleTagValue = taggable.getTag(this.tagName); if (possibleTagValue.isPresent()) { final String tagValue = possibleTagValue.get(); try { // Referenced from // https://github.com/google/guava/wiki/CachesExplained#from-a-callable // If tagValue is present in the cache then return the value; otherwise execute // function add the value to cache and return it return this.cache.get(tagValue, () -> Validators.fromAnnotation(Tagger.this.type, taggable)); } // this exception is thrown by the Callable in the get method of the cache. Ideally // we should never hit this exception catch (final ExecutionException e) { throw new CoreException("Error getting tag value from the cache", e); } } return Optional.empty(); } }
@Override protected void fillValidatorTypes( final EnumMap<Validation, Class<? extends TagValidator>> validatorTypes) { super.fillValidatorTypes(validatorTypes); validatorTypes.put(Validation.DOUBLE, IllegalValidator.class); } }
@Test public void testInvalidValue() { Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid(" ")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("mph")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("-60 kph")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("-60")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("60 km/h")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("sixty")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("sixty kph")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("sixty mph")); Assert.assertFalse(validators().getValidatorFor(MaxSpeedTag.KEY).isValid("sixty knots")); }
public static boolean isHarbour(final AtlasEntity entity) { // Excluding industrial landuse, ports and shipyards, as those are often used to tag // non-water geometry. return Validators.isOfType(entity, HarbourTag.class, HarbourTag.YES) && !Validators.isOfType(entity, LandUseTag.class, LandUseTag.INDUSTRIAL, LandUseTag.PORT) && !Validators.isOfType(entity, IndustrialTag.class, IndustrialTag.PORT, IndustrialTag.SHIPYARD); }
@Test public void testInvalidValue() { Assert.assertTrue(validators().canValidate(AddressFlatsTag.KEY)); Assert.assertFalse(validators().getValidatorFor(AddressFlatsTag.KEY).isValid(" ")); }
private static Predicate<Edge> ignoreTags() { return edge -> !(Validators.isOfType(edge, CoveredTag.class, CoveredTag.YES) || Validators.isOfType(edge, TunnelTag.class, TunnelTag.BUILDING_PASSAGE, TunnelTag.YES) || Validators.isOfType(edge, AreaTag.class, AreaTag.YES) || YES_VALUE.equals(edge.tag(INDOOR_KEY)) || HIGHWAY_SERVICE_TAG.test(edge) && Validators.isOfType(edge, ServiceTag.class, ServiceTag.DRIVEWAY) || edge.connectedNodes().stream().anyMatch(node -> Validators.isOfType(node, EntranceTag.class, EntranceTag.YES) || Validators.isOfType(node, AmenityTag.class, AmenityTag.PARKING_ENTRANCE) // Ignore edges with nodes containing Barrier tags || Validators.hasValuesFor(node, BarrierTag.class))); }
/** * Given an object, returns true if that object has a building tag or building part tag * indicating that it is either a building or a building part. * * @param object * any AtlasObject * @return true if object is a building or a building part, false otherwise */ private boolean isBuildingOrPart(final AtlasObject object) { return BuildingTag.isBuilding(object) || Validators.isNotOfType(object, BuildingPartTag.class, BuildingPartTag.NO); }
: EnumSet.noneOf(TagSearchOption.class); final Optional<String> localizedKeyName = Validators.localizeKeyName(key, language, searchOptions); if (localizedKeyName.isPresent()) return getTag(Validators.localizeKeyName(key, Optional.empty()).get());
@Test public void testAnnotationMissingValue() { final TestTaggable testing = new TestTaggable(BuildingTag.KEY, "Nope"); final Optional<EightBall> found = Validators.fromAnnotation(EightBall.class, testing); Assert.assertFalse(found.isPresent()); }
@Override protected void fillValidatorTypes( final EnumMap<Validation, Class<? extends TagValidator>> validatorTypes) { super.fillValidatorTypes(validatorTypes); validatorTypes.remove(Validation.DOUBLE); } }
public static Optional<OneWayTag> tag(final Taggable taggable) { return Validators.from(OneWayTag.class, taggable); } }
public static boolean isYes(final Taggable taggable) { return Validators.isOfType(taggable, IceRoadTag.class, IceRoadTag.YES, IceRoadTag.SNOWMOBILE); } }