-
Notifications
You must be signed in to change notification settings - Fork 3
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 #393 from mp-access/dev
Release v0.12.0
- Loading branch information
Showing
49 changed files
with
696 additions
and
328 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
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
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
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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/ch/uzh/ifi/access/course/model/Rounding.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,58 @@ | ||
package ch.uzh.ifi.access.course.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.function.BiFunction; | ||
|
||
@Data | ||
public class Rounding implements Serializable { | ||
|
||
public static final Rounding DEFAULT = new Rounding(Strategy.ROUND, 4); | ||
|
||
private Strategy strategy; | ||
private int steps; | ||
|
||
public Rounding() { | ||
} | ||
|
||
public Rounding(Strategy strategy, int steps) { | ||
this.strategy = strategy; | ||
this.steps = steps; | ||
} | ||
|
||
public double round(double value) { | ||
return strategy.round(value, steps); | ||
} | ||
|
||
public enum Strategy { | ||
|
||
CEILING(Strategy::ceil), | ||
FLOOR(Strategy::floor), | ||
ROUND(Strategy::roundUp); | ||
|
||
private BiFunction<Double, Integer, Double> algorithm; | ||
|
||
Strategy(BiFunction<Double, Integer, Double> algorithm) { | ||
this.algorithm = algorithm; | ||
} | ||
|
||
double round(double unroundedValue, int steps) { | ||
return algorithm.apply(unroundedValue, steps); | ||
} | ||
|
||
static double ceil(Double unroundedValue, Integer steps) { | ||
return Math.ceil( unroundedValue*steps)/steps; | ||
} | ||
|
||
static double floor(Double unroundedValue, Integer steps) { | ||
return Math.floor(unroundedValue * steps)/steps; | ||
} | ||
|
||
static double roundUp(double unroundedValue, Integer steps) { | ||
return (double) Math.round(unroundedValue * steps) / steps; | ||
} | ||
|
||
} | ||
|
||
} |
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.