Skip to main content



      Home
Home » Eclipse Projects » UOMo » Generic Elements containing BaseAmount
Generic Elements containing BaseAmount [message #1691352] Mon, 06 April 2015 09:03
Eclipse UserFriend
Hi I want to create a java object which can be defined for multiple Dimensions and let the user choose the one he desires. As so I have created a new class which extends the BaseAmount class so the user can define an element of MassAmount or another of Temperature and then it can retrieve the values in an homogenised way.
My problem comes at compilation time, because the compiler is not raising any problem if for a MassAmount I use AMPERE units. Can someone shed a light on this? I am guessing I am doing something wrong
I put my code
import org.unitsofmeasurement.quantity.Quantity;
import  org.eclipse.uomo.units.impl.BaseAmount;
import org.unitsofmeasurement.unit.Unit;

@SuppressWarnings("rawtypes")
public class MeasurableElement<T extends BaseAmount> {

	 T  value;
		 
	public  MeasurableElement( T  typeAmount){
		 value = (T) typeAmount;
	 }
	
 
	@SuppressWarnings("unchecked")
	public <U extends Unit> void forceValue(double newVal, U  unit ) {
			value = (T) BaseAmount.valueOf(newVal, unit);
		}
}


and my testing code
MeasurableElement<MassAmount> me = new MeasurableElement(new MassAmount(1000, org.eclipse.uomo.units.SI.KILOGRAM));
me.forceValue(5.2, org.eclipse.uomo.units.SI.AMPERE);


Thanks in advance
Previous Topic:Which version of UOMo to use with Eclipse Luna
Next Topic:Wrong Prefixes in Unit Calculation
Goto Forum:
  


Current Time: Mon Jul 07 06:47:40 EDT 2025

Powered by FUDForum. Page generated in 0.03851 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top