/** * 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)); }
public static void adjustMinMaxFrameRate(AdaptationSetType adaptationSetType) { RepresentationType representationArray[] = adaptationSetType.getRepresentationArray(); Fraction min = null, max = null; for (RepresentationType representationType : representationArray) { Node attr = representationType.getDomNode().getAttributes().getNamedItem("frameRate"); if (attr != null) { Fraction f = Fraction.getFraction(attr.getNodeValue()); 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 Node adaptationSet = adaptationSetType.getDomNode(); Node minAttr = adaptationSet.getOwnerDocument().createAttribute("minFrameRate"); minAttr.setNodeValue(min.toString()); adaptationSet.getAttributes().setNamedItem(minAttr); Node maxAttr = adaptationSet.getOwnerDocument().createAttribute("maxFrameRate"); maxAttr.setNodeValue(max.toString()); adaptationSet.getAttributes().setNamedItem(maxAttr); } }
public List<Transaction> convertRecord(Account account, QifRecord record) throws QuickenException { String securityName = record.getValue(QifField.SECURITY); Date splitDate = record.getDate(QifField.DATE); BigDecimal ratio = record.getBigDecimal(QifField.SHARES).divide(BigDecimal.TEN); Fraction fraction = Fraction.getFraction(ratio.doubleValue()); securityOperations.findOrCreateSplit(securityName, splitDate, new BigDecimal(fraction.getDenominator()), new BigDecimal(fraction.getNumerator())); return Collections.emptyList(); }
@Override public void validate() { List<Course> groupCourses = getCourseGroup().courseListProperty().get(); Stream<Course> fulfilledGroupCourses = semesterPlan.allCourseEnrollments().filter(CourseEnrollment::isFulfilled) .map(CourseEnrollment::getCourse).filter(groupCourses::contains); int creditSum = groupCourses.stream().map(c -> c.getCredits().getCreditValue()).reduce(0, Integer::sum); int fulfilledSum = fulfilledGroupCourses.map(c -> c.getCredits().getCreditValue()).reduce(0, Integer::sum); Fraction gotFraction = Fraction.getFraction(fulfilledSum, creditSum); if (neededFraction.compareTo(gotFraction) > 0) { fireBrokenEvent(generateMessage(gotFraction, neededFraction)); } else { fireFixedEvent(this); } }
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(); } }
/** * 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); }
public ReportStatistic(int count, int size) { fraction = Fraction.getFraction(count, size); }
public void setSize(int size) { fraction = Fraction.getFraction(getCount(), size); }
/** * Default constructor. * * @param courseGroup the referenced course group * @param neededFraction the minimum fraction of fulfilled course credits the student needs to achieve */ public CourseGroupCreditsPercentageConstraint(CourseGroup courseGroup, Fraction neededFraction) { super(courseGroup); this.neededFraction = neededFraction; }
/** * Utility method for converting {@link Fraction}s to percentage points with two decimal places. * To be replaced with Apache's {@code lang3} Fraction. * * @param fraction the fraction to convert * @return the percentage representation in a String */ private static String toPercent(Fraction fraction) { // TODO math3 fraction.percentageValue() return percentageFormat.format(fraction.doubleValue() * 100d) + "%"; }
/** * The fraction of fulfilled course credit sum to the total group credit sum needed to pass this constraint. * * @return the fulfilled course credit sum fraction needed */ @JsonIgnore private Fraction getNeededFraction() { return neededFraction; }
/** * Util method for Jackson, to deserialize the {@link #neededFraction} in a sane way. * * @param neededFractionString the needed fraction in a string representation */ @JsonProperty("neededFraction") private void setNeededFractionString(String neededFractionString) { this.neededFraction = Fraction.getFraction(neededFractionString); }
/** * Generates a message from the given parameters (localized). Used for populating the message of * {@link StringMessageEvent}s (usually upon breaking a constraint). * * @param got the passed course fraction the student achieved * @param needed the fraction of passed courses the student needs to pass * @return the String to use as a message, localized */ private String generateMessage(Fraction got, Fraction needed) { return String.format(messages.getString(message), toPercent(needed), toPercent(got)); }