/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull public final Rational getReciprocal() { return new Rational(denominator, numerator); }
/******************************************************************************************************************* * * * @param det * @return * ******************************************************************************************************************/ @Nonnull public final Rational divide (final double det) { return new Rational(numerator, (int)Math.round(denominator * det)); }
@Override @Nonnull public Rational convertReverse (@Nonnull final String string) { final String[] split = string.split("/"); // FIXME: requires a dependency on Metadata-Extractor because there's a Rational constructor using it. // Drop it! if (split.length == 1) { return new Rational(Integer.valueOf(split[0].trim()), 1); } return new Rational(Integer.valueOf(split[0].trim()), Integer.valueOf(split[1].trim())); } }
/*************************************************************************** * * **************************************************************************/ private static Rational[] convertRationalArray (final TagRational[] temp) { final Rational[] r = new Rational[temp.length]; for (int i = 0; i < r.length; i++) { r[i] = new Rational(temp[i].getNumerator(), temp[i].getDenominator()); } return r; } }
/*************************************************************************** * * **************************************************************************/ private static Rational[] convertRationalArray (final com.drew.lang.Rational[] temp) { final Rational[] r = new Rational[temp.length]; for (int i = 0; i < r.length; i++) { r[i] = new Rational((int)temp[i].getNumerator(), (int)temp[i].getDenominator()); } return r; } }
value = new Rational((int)array[0][0], (int)array[0][1]);
/*************************************************************************** * * **************************************************************************/ @Override public Object getObject (final int tag) throws NoSuchElementException { checkIfTagExists(tag); final Object value = directory.getObject(Integer.valueOf(tag)); if (value instanceof TagRational) { final TagRational rational = (TagRational)value; return new Rational(rational.getNumerator(), rational.getDenominator()); } else if (value instanceof TagRational[]) { return convertRationalArray((TagRational[])value); } return value; }
/*************************************************************************** * * **************************************************************************/ @Override public Object getObject (final int tag) throws NoSuchElementException { checkIfTagExists(tag); Object value = directory.getObject(tag); if (value instanceof com.drew.lang.Rational) { final com.drew.lang.Rational drewRational = (com.drew.lang.Rational) value; value = new Rational((int)drewRational.getNumerator(), (int)drewRational.getDenominator()); } else if (value instanceof com.drew.lang.Rational[]) { value = convertRationalArray((com.drew.lang.Rational[])value); } return value; }