1 11 package com.ibm.icu.util; 12 13 import java.lang.Number ; 14 15 32 public abstract class Measure { 33 34 private Number number; 35 36 private MeasureUnit unit; 37 38 44 protected Measure(Number number, MeasureUnit unit) { 45 if (number == null || unit == null) { 46 throw new NullPointerException (); 47 } 48 this.number = number; 49 this.unit = unit; 50 } 51 52 57 public boolean equals(Object obj) { 58 if (obj == null) return false; 59 if (obj == this) return true; 60 try { 61 Measure m = (Measure) obj; 62 return number.equals(m.number) && unit.equals(m.unit); 63 } catch (ClassCastException e) { 64 return false; 65 } 66 } 67 68 73 public int hashCode() { 74 return number.hashCode() ^ unit.hashCode(); 75 } 76 77 83 public String toString() { 84 return number.toString() + ' ' + unit.toString(); 85 } 86 87 92 public Number getNumber() { 93 return number; 94 } 95 96 101 public MeasureUnit getUnit() { 102 return unit; 103 } 104 } 105 | Popular Tags |