1 9 package org.jscience.physics.units; 10 11 19 public final class AddConverter extends Converter { 20 21 24 private final double _offset; 25 26 31 public AddConverter(double offset) { 32 _offset = offset; 33 } 34 35 40 public double getOffset() { 41 return _offset; 42 } 43 44 public Converter inverse() { 46 return new AddConverter(-_offset); 47 } 48 49 public double convert(double x) { 51 return x + _offset; 52 } 53 54 public double derivative(double x) { 56 return 1.0; 57 } 58 59 public boolean isLinear() { 61 return false; 62 } 63 64 public Converter concatenate(Converter converter) { 66 if (converter instanceof AddConverter) { 67 double offset 69 = _offset + ((AddConverter)converter).getOffset(); 70 return new AddConverter(offset); 71 } else { 72 return super.concatenate(converter); 73 } 74 } 75 76 public boolean equals(Object obj) { 78 return (obj instanceof AddConverter) && 80 (Float.floatToIntBits((float)((AddConverter)obj)._offset) == 81 Float.floatToIntBits((float)_offset)); 82 } 83 84 public int hashCode() { 86 int h = Float.floatToIntBits((float)_offset); 87 h += ~(h << 9); 88 h ^= (h >>> 14); 89 h += (h << 4); 90 return h ^ (h >>> 10); 91 } 92 93 private static final long serialVersionUID = 1L; 94 } | Popular Tags |