org.apache.commons.lang.math.Fraction源码实例Demo

类org.apache.commons.lang.math.Fraction源码实例Demo

下面列出了org.apache.commons.lang.math.Fraction 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ProjectAres   文件: Team.java
/**
 * 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));
}
 
源代码2 项目: dashencrypt   文件: ManifestOptimizer.java
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());
    }
}
 
源代码3 项目: PGM   文件: TeamMatchModule.java
/** 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;
}
 
源代码4 项目: dashencrypt   文件: ManifestHelper.java
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();
    }


}
 
源代码5 项目: PGM   文件: Team.java
public Fraction getFullnessAfterJoin(@Nullable MatchPlayer joining, @Nullable Team newTeam) {
  return Fraction.getReducedFraction(getSizeAfterJoin(joining, newTeam, false), getMaxOverfill());
}
 
源代码6 项目: ProjectAres   文件: Team.java
/**
 * 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);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法