/packages/WallpaperCropper/src/com/android/gallery3d/exif/Rational.java

https://github.com/aizuzi/platform_frameworks_base · Java · 88 lines · 40 code · 10 blank · 38 comment · 8 complexity · 30b64a7b704cb568a6f326bdbffdd6dc MD5 · raw file

  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. package com.android.gallery3d.exif;
  17. /**
  18. * The rational data type of EXIF tag. Contains a pair of longs representing the
  19. * numerator and denominator of a Rational number.
  20. */
  21. public class Rational {
  22. private final long mNumerator;
  23. private final long mDenominator;
  24. /**
  25. * Create a Rational with a given numerator and denominator.
  26. *
  27. * @param nominator
  28. * @param denominator
  29. */
  30. public Rational(long nominator, long denominator) {
  31. mNumerator = nominator;
  32. mDenominator = denominator;
  33. }
  34. /**
  35. * Create a copy of a Rational.
  36. */
  37. public Rational(Rational r) {
  38. mNumerator = r.mNumerator;
  39. mDenominator = r.mDenominator;
  40. }
  41. /**
  42. * Gets the numerator of the rational.
  43. */
  44. public long getNumerator() {
  45. return mNumerator;
  46. }
  47. /**
  48. * Gets the denominator of the rational
  49. */
  50. public long getDenominator() {
  51. return mDenominator;
  52. }
  53. /**
  54. * Gets the rational value as type double. Will cause a divide-by-zero error
  55. * if the denominator is 0.
  56. */
  57. public double toDouble() {
  58. return mNumerator / (double) mDenominator;
  59. }
  60. @Override
  61. public boolean equals(Object obj) {
  62. if (obj == null) {
  63. return false;
  64. }
  65. if (this == obj) {
  66. return true;
  67. }
  68. if (obj instanceof Rational) {
  69. Rational data = (Rational) obj;
  70. return mNumerator == data.mNumerator && mDenominator == data.mDenominator;
  71. }
  72. return false;
  73. }
  74. @Override
  75. public String toString() {
  76. return mNumerator + "/" + mDenominator;
  77. }
  78. }