Rational.java revision 1792070857f96943ae110869d66f092001ad526e
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.gallery3d.exif; 18 19/** 20 * The rational data type of EXIF tag. 21 */ 22public class Rational { 23 24 private final long mNominator; 25 private final long mDenominator; 26 27 public Rational(long nominator, long denominator) { 28 mNominator = nominator; 29 mDenominator = denominator; 30 } 31 32 /* 33 * Gets the nominator of the rational. 34 */ 35 public long getNominator() { 36 return mNominator; 37 } 38 39 /* 40 * Gets the denominator of the rational 41 */ 42 public long getDenominator() { 43 return mDenominator; 44 } 45 46 @Override 47 public boolean equals(Object obj) { 48 if (obj instanceof Rational) { 49 Rational data = (Rational) obj; 50 return mNominator == data.mNominator && mDenominator == data.mDenominator; 51 } 52 return false; 53 } 54 55 @Override 56 public String toString() { 57 return mNominator + "/" + mDenominator; 58 } 59 60 /* 61 * Gets the rational value as type double. 62 */ 63 public double toDouble() { 64 return mNominator / (double) mDenominator; 65 } 66}