1 9 package org.jscience.physics.models; 10 11 import javax.measure.converters.UnitConverter; 12 import javax.measure.units.BaseUnit; 13 import javax.measure.units.Dimension; 14 15 import javolution.context.LocalContext; 16 17 35 public abstract class PhysicalModel implements Dimension.Model { 36 37 40 private static LocalContext.Reference<PhysicalModel> Current 41 = new LocalContext.Reference<PhysicalModel>(); 42 43 46 private static final Dimension.Model DIMENSIONAL_MODEL 47 = new Dimension.Model() { 48 49 public Dimension getDimension(BaseUnit unit) { 50 return PhysicalModel.Current.get().getDimension(unit); 51 } 52 53 public UnitConverter getTransform(BaseUnit unit) { 54 return PhysicalModel.Current.get().getTransform(unit); 55 }}; 56 57 60 protected PhysicalModel() { 61 } 62 63 69 public static final PhysicalModel current() { 70 PhysicalModel physicalModel = PhysicalModel.Current.get(); 71 return (physicalModel == null) ? StandardModel.INSTANCE : physicalModel; 72 } 73 74 81 protected static final void setCurrent(PhysicalModel model) { 82 PhysicalModel.Current.set(model); 83 Dimension.setModel(DIMENSIONAL_MODEL); 84 } 85 86 } | Popular Tags |