org.apache.commons.lang.math.Fraction Java Examples
The following examples show how to use
org.apache.commons.lang.math.Fraction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Team.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * Get the maximum number of players currently allowed on this team without * exceeding any limits. */ public int getMaxBalancedSize() { // Find the minimum fullness among other teams final Fraction minFullness = (Fraction) module().getTeams() .stream() .filter(team -> !equals(team)) .map(team -> team.getFullness(Team::getMaxOverfill)) .min(Comparator.naturalOrder()) .orElse(Fraction.ONE); // Calculate the dynamic limit to maintain balance with other teams (this can be zero) int slots = Numbers.ceil(Comparables.min(Fraction.ONE, minFullness.multiplyBy(MAX_IMBALANCE)) .multiplyBy(Fraction.getFraction(getMaxOverfill(), 1))); // Clamp to the static limit defined for this team (cannot be zero unless the static limit is zero) return Math.min(getMaxOverfill(), Math.max(1, slots)); }
Example #2
Source File: ManifestOptimizer.java From dashencrypt with Mozilla Public License 2.0 | 6 votes |
public static void adjustMinMaxFrameRate(AdaptationSetType adaptationSetType) { List<RepresentationType> representations = adaptationSetType.getRepresentation(); Fraction min = null, max = null; for (RepresentationType representationType : representations) { String frameRate = representationType.getFrameRate(); if (frameRate != null) { Fraction f = Fraction.getFraction(frameRate); min = min == null || f.compareTo(min) < 0 ? f : min; max = max == null || f.compareTo(max) > 0 ? f : max; } } if (max != null && !min.equals(max)) { // min/max doesn't make sense when both values are the same adaptationSetType.setMinFrameRate(min.toString()); adaptationSetType.setMaxFrameRate(max.toString()); } }
Example #3
Source File: TeamMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
/** Do all teams have equal fullness ratios? */ public boolean areTeamsEvenAfterJoin(@Nullable MatchPlayer joining, @Nullable Team newTeam) { Fraction commonFullness = null; for (Team team : getParticipatingTeams()) { Fraction teamFullness = team.getFullnessAfterJoin(joining, newTeam); if (commonFullness == null) { commonFullness = teamFullness; } else if (!commonFullness.equals(teamFullness)) { return false; } } return true; }
Example #4
Source File: ManifestHelper.java From dashencrypt with Mozilla Public License 2.0 | 5 votes |
public static String convertFramerate(double vrate) { Fraction f1 = Fraction.getFraction((int) (vrate * 1001), 1001); Fraction f2 = Fraction.getFraction((int) (vrate * 1000), 1000); double d1 = Math.abs(f1.doubleValue() - vrate); double d2 = Math.abs(f2.doubleValue() - vrate); if (d1 < d2) { return f1.getNumerator() + "/" + f1.getDenominator(); } else { return f2.getNumerator() + "/" + f2.getDenominator(); } }
Example #5
Source File: Team.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public Fraction getFullnessAfterJoin(@Nullable MatchPlayer joining, @Nullable Team newTeam) { return Fraction.getReducedFraction(getSizeAfterJoin(joining, newTeam, false), getMaxOverfill()); }
Example #6
Source File: Team.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
/** * Get the "fullness" of this team, relative to some capacity returned by * the given function. The return value is always in the range 0 to 1. */ public Fraction getFullness(ToIntFunction<? super Team> maxFunction) { final int max = maxFunction.applyAsInt(this); return max == 0 ? Fraction.ONE : Fraction.getReducedFraction(getSize(), max); }