-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
put escalator preferences in a sub object in walk preferences
- Loading branch information
Showing
14 changed files
with
228 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...rc/main/java/org/opentripplanner/routing/api/request/preference/EscalatorPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.opentripplanner.routing.api.request.preference; | ||
|
||
import static org.opentripplanner.utils.lang.DoubleUtils.doubleEquals; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import org.opentripplanner.utils.tostring.ToStringBuilder; | ||
|
||
public class EscalatorPreferences implements Serializable { | ||
|
||
public static final EscalatorPreferences DEFAULT = new EscalatorPreferences(); | ||
|
||
private final double reluctance; | ||
private final double speed; | ||
|
||
private EscalatorPreferences() { | ||
this.reluctance = 1.5; | ||
this.speed = 0.45; | ||
} | ||
|
||
private EscalatorPreferences(Builder builder) { | ||
reluctance = builder.reluctance; | ||
speed = builder.speed; | ||
} | ||
|
||
public static Builder of() { | ||
return new Builder(DEFAULT); | ||
} | ||
|
||
public Builder copyOf() { | ||
return new Builder(this); | ||
} | ||
|
||
public double reluctance() { | ||
return reluctance; | ||
} | ||
|
||
public double speed() { | ||
return speed; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
EscalatorPreferences that = (EscalatorPreferences) o; | ||
return (doubleEquals(that.reluctance, reluctance) && doubleEquals(that.speed, speed)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(speed, reluctance); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder | ||
.of(EscalatorPreferences.class) | ||
.addNum("speed", speed, DEFAULT.speed) | ||
.addNum("reluctance", reluctance, DEFAULT.reluctance) | ||
.toString(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private final EscalatorPreferences original; | ||
private double reluctance; | ||
private double speed; | ||
|
||
public Builder(EscalatorPreferences original) { | ||
this.original = original; | ||
this.reluctance = original.reluctance; | ||
this.speed = original.speed; | ||
} | ||
|
||
public EscalatorPreferences original() { | ||
return original; | ||
} | ||
|
||
public double speed() { | ||
return speed; | ||
} | ||
|
||
public Builder withSpeed(double speed) { | ||
this.speed = speed; | ||
return this; | ||
} | ||
|
||
public double reluctance() { | ||
return reluctance; | ||
} | ||
|
||
public Builder withReluctance(double reluctance) { | ||
this.reluctance = reluctance; | ||
return this; | ||
} | ||
|
||
public Builder apply(Consumer<Builder> body) { | ||
body.accept(this); | ||
return this; | ||
} | ||
|
||
public EscalatorPreferences build() { | ||
var newObj = new EscalatorPreferences(this); | ||
return original.equals(newObj) ? original : newObj; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.