All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.osm.wayproperty.WayProperties Maven / Gradle / Ivy

The newest version!
package org.opentripplanner.osm.wayproperty;

import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import org.opentripplanner.street.model.StreetTraversalPermission;

/**
 * Parameters applied to OSM ways, usually based on their tags: - Which modes can traverse it -
 * Dangerousness on a bicycle in both directions (OSM ways can be bidirectional).
 *
 */
public class WayProperties {

  private final StreetTraversalPermission permission;

  @Nullable
  private final SafetyFeatures bicycleSafetyFeatures;

  @Nullable
  private final SafetyFeatures walkSafetyFeatures;

  WayProperties(WayPropertiesBuilder wayPropertiesBuilder) {
    permission = Objects.requireNonNull(wayPropertiesBuilder.getPermission());
    bicycleSafetyFeatures = wayPropertiesBuilder.bicycleSafety();
    walkSafetyFeatures = wayPropertiesBuilder.walkSafety();
  }

  /**
   * The value for the bicycle safety. If none has been set a default value of 1 is returned.
   */
  public SafetyFeatures bicycleSafety() {
    return Objects.requireNonNullElse(bicycleSafetyFeatures, SafetyFeatures.DEFAULT);
  }

  /**
   * The value for the walk safety. If none has been set a default value of 1 is returned.
   */
  public SafetyFeatures walkSafety() {
    return Objects.requireNonNullElse(walkSafetyFeatures, SafetyFeatures.DEFAULT);
  }

  public StreetTraversalPermission getPermission() {
    return permission;
  }

  /**
   * An optional value for the walk safety. If none has been set an empty Optional is returned.
   */
  protected Optional walkSafetyOpt() {
    return Optional.ofNullable(walkSafetyFeatures);
  }

  /**
   * An optional value for the bicycle safety. If none has been set an empty Optional is returned.
   */
  protected Optional bicycleSafetyOpt() {
    return Optional.ofNullable(bicycleSafetyFeatures);
  }

  @Override
  public int hashCode() {
    return Objects.hash(bicycleSafetyFeatures, walkSafetyFeatures, permission);
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof WayProperties other) {
      return (
        Objects.equals(bicycleSafetyFeatures, other.bicycleSafetyFeatures) &&
        Objects.equals(walkSafetyFeatures, other.walkSafetyFeatures) &&
        permission == other.permission
      );
    }
    return false;
  }

  public WayPropertiesBuilder mutate() {
    return new WayPropertiesBuilder(this);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy