12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */ 2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License 42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* 52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller********************************************************************** 62ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Copyright (c) 2004-2013, International Business Machines 72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Corporation and others. All Rights Reserved. 82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller********************************************************************** 92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Author: Alan Liu 102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Created: April 20, 2004 112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller* Since: ICU 3.0 122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller********************************************************************** 132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller*/ 142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.util; 152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/** 182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * An amount of a specified unit, consisting of a Number and a Unit. 192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * For example, a length measure consists of a Number and a length 202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * unit, such as feet or meters. 212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Measure objects are parsed and formatted by subclasses of 232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * MeasureFormat. 242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * <p>Measure objects are immutable. All subclasses must guarantee that. 262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * (However, subclassing is discouraged.) 272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * 282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see java.lang.Number 292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.util.MeasureUnit 302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @see android.icu.text.MeasureFormat 312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @author Alan Liu 322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic class Measure { 34f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private final Number number; 362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private final MeasureUnit unit; 372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Constructs a new object given a number and a unit. 402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param number the number 412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param unit the unit 422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Measure(Number number, MeasureUnit unit) { 442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (number == null || unit == null) { 452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller throw new NullPointerException(); 462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.number = number; 482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller this.unit = unit; 492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 50f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns true if the given object is equal to this object. 532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return true if this object is equal to the given object 542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 55f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public boolean equals(Object obj) { 572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (obj == this) { 582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (!(obj instanceof Measure)) { 612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller Measure m = (Measure) obj; 642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return unit.equals(m.unit) && numbersEqual(number, m.number); 652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 66f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert 672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /* 682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * See if two numbers are identical or have the same double value. 692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param a A number 702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @param b Another number to be compared with 712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return Returns true if two numbers are identical or have the same double value. 722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller // TODO improve this to catch more cases (two different longs that have same double values, BigDecimals, etc) 742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller private static boolean numbersEqual(Number a, Number b) { 752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (a.equals(b)) { 762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller if (a.doubleValue() == b.doubleValue()) { 792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return true; 802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return false; 822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a hashcode for this object. 862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a 32-bit hash 872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 88f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public int hashCode() { 902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return 31 * Double.valueOf(number.doubleValue()).hashCode() + unit.hashCode(); 912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns a string representation of this object. 952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return a string representation consisting of the ISO currency 962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * code together with the numeric amount 972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 98f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert @Override 992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public String toString() { 1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return number.toString() + ' ' + unit.toString(); 1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the numeric value of this object. 1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return this object's Number 1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public Number getNumber() { 1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return number; 1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller 1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller /** 1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Returns the unit of this object. 1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @return this object's Unit 1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */ 1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller public MeasureUnit getUnit() { 1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller return unit; 1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller } 1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller} 119