Example usage for org.apache.commons.lang.math Fraction getNumerator

List of usage examples for org.apache.commons.lang.math Fraction getNumerator

Introduction

In this page you can find the example usage for org.apache.commons.lang.math Fraction getNumerator.

Prototype

public int getNumerator() 

Source Link

Document

Gets the numerator part of the fraction.

This method may return a value greater than the denominator, an improper fraction, such as the seven in 7/4.

Usage

From source file:FractionExampleV1.java

public static void main(String args[]) {
    Fraction twoThirds = Fraction.TWO_THIRDS;
    Fraction fraction_whole = Fraction.getFraction(2, 2, 3);
    Fraction fraction = Fraction.getFraction(27, 98);
    Fraction fraction_double = Fraction.getFraction(4.56);
    Fraction fraction_string = Fraction.getFraction("2 1/3");

    System.err.println(twoThirds.doubleValue());
    System.err.println(fraction_string.getNumerator());
    System.err.println(fraction_whole.divideBy(fraction_double));
    System.err.println(fraction.divideBy(fraction));
}

From source file:com.castlabs.dash.helpers.ManifestHelper.java

/**
 * Creates a representation and AudioChannelConfiguration if appropriate.
 *///w  ww.  j a  v a 2s.  co m
public static RepresentationType createRepresentation(AdaptationSetType adaptationSet, Track track) {
    RepresentationType representation = adaptationSet.addNewRepresentation();
    if (track.getHandler().equals("vide")) {

        long videoHeight = (long) track.getTrackMetaData().getHeight();
        long videoWidth = (long) track.getTrackMetaData().getWidth();
        double framesPerSecond = (double) (track.getSamples().size() * track.getTrackMetaData().getTimescale())
                / track.getDuration();

        Fraction fraction = Fraction.getFraction((int) videoWidth, (int) videoHeight).reduce();
        adaptationSet.setPar("" + fraction.getNumerator() + ":" + fraction.getDenominator());

        //representation.setMimeType("video/mp4");
        representation.setCodecs(DashHelper.getRfc6381Codec(track.getSampleDescriptionBox().getSampleEntry()));
        representation.setWidth(videoWidth);
        representation.setHeight(videoHeight);
        representation.setFrameRate(convertFramerate(framesPerSecond));
        representation.setSar("1:1");
        // too hard to find it out. Ignoring even though it should be set according to DASH-AVC-264-v2.00-hd-mca.pdf
    }

    if (track.getHandler().equals("soun")) {

        AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry();

        //representation.setMimeType("audio/mp4");
        representation.setCodecs(DashHelper.getRfc6381Codec(ase));
        representation.setAudioSamplingRate("" + DashHelper.getAudioSamplingRate(ase));

        DescriptorType audio_channel_conf = representation.addNewAudioChannelConfiguration();
        DashHelper.ChannelConfiguration cc = DashHelper.getChannelConfiguration(ase);
        audio_channel_conf.setSchemeIdUri(cc.schemeIdUri);
        audio_channel_conf.setValue(cc.value);

    }
    return representation;
}

From source file:com.castlabs.dash.helpers.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 {/*w  ww. j a va  2s  . c o  m*/
        return f2.getNumerator() + "/" + f2.getDenominator();
    }

}

From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java

public int getXPAward(CharID id) {
    Map<String, Integer> xpAwardsMap = SettingsHandler.getGame().getXPAwards();

    if (xpAwardsMap.size() > 0) {
        Float cr = getCR(id);/*from  w ww  . j  av  a 2  s . c  o m*/
        if (cr.isNaN() || cr == 0) {
            return 0;
        }
        String crString = "";
        String crAsString = Float.toString(cr);
        String decimalPlaceValue = crAsString.substring(crAsString.length() - 2);

        // If the CR is a fractional CR then we convert to a 1/x format
        if (cr > 0 && cr < 1) {
            Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR);
            int denominator = fraction.getDenominator();
            int numerator = fraction.getNumerator();
            crString = numerator + "/" + denominator;
        } else if (cr >= 1 || cr == 0) {
            int newCr = -99;
            if (decimalPlaceValue.equals(".0")) {
                newCr = (int) cr.floatValue();
            }

            if (newCr > -99) {
                crString = crString + newCr;
            } else {
                crString = crString + cr;
            }
        }
        return xpAwardsMap.get(crString);
    }
    return 0;
}

From source file:plugin.exporttokens.CRToken.java

/**
 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
 *//*from   w w  w .j  a va  2  s.  c  o m*/
@Override
public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) {
    String retString = "";
    Float cr = display.calcCR();

    String crAsString = Float.toString(cr);
    String decimalPlaceValue = crAsString.substring(crAsString.length() - 2);

    if (cr > 0 && cr < 1) {
        // If the CR is a fractional CR then we convert to a 1/x format
        Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR);
        int denominator = fraction.getDenominator();
        int numerator = fraction.getNumerator();
        retString = numerator + "/" + denominator;
    } else if (cr >= 1 || cr == 0) {
        int newCr = -99;
        if (decimalPlaceValue.equals(".0")) {
            newCr = (int) cr.floatValue();
        }

        if (newCr > -99) {
            retString = retString + newCr;
        } else {
            retString = retString + cr;
        }
    } else if (cr.isNaN()) {
        retString = "0";
    }
    return retString;
}