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

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

Introduction

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

Prototype

public static Fraction getFraction(String str) 

Source Link

Document

Creates a Fraction from a String.

The formats accepted are:

  1. double String containing a dot
  2. 'X Y/Z'
  3. 'Y/Z'
  4. 'X' (a simple whole number)
and a .

Usage

From source file:com.castlabs.csf.manifest.ManifestHelper.java

/**
 * Creates a representation and adjusts the AdaptionSet's attributes maxFrameRate, maxWidth, maxHeight.
 * Also creates AudioChannelConfiguration.
 *///from w  w  w .jav a  2  s  .c  o m
public static RepresentationType createRepresentation(AdaptationSetType adaptationSet, IsoFile track) {
    RepresentationType representation = adaptationSet.addNewRepresentation();
    ContentInformationBox contentInformationBox = Path.getPath(track, "/moov[0]/cinf[0]");
    representation.setId(contentInformationBox.getIdEntries().get("urn:dece:asset_id"));

    String handler = ((HandlerBox) Path.getPath(track, "/moov[0]/trak[0]/mdia[0]/hdlr[0]")).getHandlerType();
    if (handler.equals("vide")) {
        VisualSampleEntry vse = Path.getPath(track, "/moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/stsd[0]/....[0]");
        long videoHeight = (long) vse.getHeight();
        long videoWidth = (long) vse.getWidth();

        TrackRunBox trun = Path.getPath(track, "/moof[0]/traf[0]/trun[0]");
        MediaHeaderBox mdhd = Path.getPath(track, "/moov[0]/trak[0]/mdia[0]/mdhd[0]");
        // assuming constant framerate
        long sampleDuration;
        if (trun.isSampleDurationPresent()) {
            sampleDuration = trun.getEntries().get(0).getSampleDuration();
        } else {
            TrackFragmentHeaderBox tfhd = Path.getPath(track, "/moof[0]/traf[0]/tfhd[0]");
            if (tfhd.hasDefaultSampleDuration()) {
                sampleDuration = tfhd.getDefaultSampleDuration();
            } else {
                TrackExtendsBox trex = Path.getPath(track, "/moov[0]/mvex[0]/trex[0]");
                sampleDuration = trex.getDefaultSampleDuration();
            }
        }

        double framesPerSecond = mdhd.getTimescale() / sampleDuration;

        adaptationSet.setMaxFrameRate(convertFramerate(Math.max(adaptationSet.isSetMaxFrameRate()
                ? Fraction.getFraction(adaptationSet.getMaxFrameRate()).doubleValue()
                : 0, framesPerSecond)));

        adaptationSet.setMaxWidth(
                Math.max(adaptationSet.isSetMaxWidth() ? adaptationSet.getMaxWidth() : 0, videoWidth));
        adaptationSet.setMaxHeight(
                Math.max(adaptationSet.isSetMaxHeight() ? adaptationSet.getMaxHeight() : 0, videoHeight));

        adaptationSet.setPar("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

        representation.setCodecs(DashHelper.getRfc6381Codec(vse));
        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 (handler.equals("soun")) {
        AudioSampleEntry ase = Path.getPath(track, "/moov[0]/trak[0]/mdia[0]/minf[0]/stbl[0]/stsd[0]/....[0]");
        representation.setCodecs(DashHelper.getRfc6381Codec(ase));
        representation.setAudioSamplingRate(String.valueOf(ase.getSampleRate()));

        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: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 ww w  .  jav  a2  s  .  c  om*/
        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)
 *///w w  w.  ja va  2  s. c om
@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;
}