-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from HSLdevcom/feat/passenger_count
feat/passenger count
- Loading branch information
Showing
14 changed files
with
529 additions
and
56 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
10 changes: 10 additions & 0 deletions
10
src/main/java/fi/hsl/suomenlinna_hfp/common/PassengerCountProvider.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,10 @@ | ||
package fi.hsl.suomenlinna_hfp.common; | ||
|
||
import fi.hsl.suomenlinna_hfp.common.model.PassengerCount; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface PassengerCountProvider { | ||
CompletableFuture<PassengerCount> getPassengerCountByStartTimeAndStopCode(LocalDateTime startTime, String stopCode); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/fi/hsl/suomenlinna_hfp/common/model/PassengerCount.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,43 @@ | ||
package fi.hsl.suomenlinna_hfp.common.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class PassengerCount { | ||
public final String vehicleId; | ||
public final int currentPassengers; | ||
public final int maxPassengers; | ||
|
||
public PassengerCount(String vehicleId, int currentPassengers, int maxPassengers) { | ||
this.vehicleId = vehicleId; | ||
this.currentPassengers = currentPassengers; | ||
this.maxPassengers = maxPassengers; | ||
} | ||
|
||
public double getPercentage() { | ||
return currentPassengers / (double)maxPassengers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PassengerCount that = (PassengerCount) o; | ||
return currentPassengers == that.currentPassengers && | ||
maxPassengers == that.maxPassengers && | ||
Objects.equals(vehicleId, that.vehicleId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(vehicleId, currentPassengers, maxPassengers); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PassengerCount{" + | ||
"vehicleId='" + vehicleId + '\'' + | ||
", currentPassengers=" + currentPassengers + | ||
", maxPassengers=" + maxPassengers + | ||
'}'; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/fi/hsl/suomenlinna_hfp/common/utils/MathUtils.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,25 @@ | ||
package fi.hsl.suomenlinna_hfp.common.utils; | ||
|
||
public class MathUtils { | ||
private MathUtils() {} | ||
|
||
/** | ||
* Returns percentage as integer | ||
* @param percentage Percentage 0.0 - 1.0 | ||
* @return Integer, 0-100 | ||
*/ | ||
public static int percentageAsInteger(double percentage) { | ||
return (int)Math.round(percentage * 100); | ||
} | ||
|
||
/** | ||
* Clamps value into range [min, max] | ||
* @param value Value | ||
* @param min Min value | ||
* @param max Max value | ||
* @return Value in range [min, max] | ||
*/ | ||
public static double clamp(double value, double min, double max) { | ||
return Math.max(min, Math.min(max, value)); | ||
} | ||
} |
Oops, something went wrong.