本文整理汇总了Java中javax.measure.quantity.Length类的典型用法代码示例。如果您正苦于以下问题:Java Length类的具体用法?Java Length怎么用?Java Length使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Length类属于javax.measure.quantity包,在下文中一共展示了Length类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import javax.measure.quantity.Length; //导入依赖的package包/类
@Override
public Double convert(Double value, LengthUnit from, LengthUnit to) {
if (value == null)
return null;
if (from.equals(UNSUPPORTED) || to.equals(UNSUPPORTED))
return null;
Unit fUnit = get(from);
Unit tUnit = get(to);
if (fUnit == null || tUnit == null)
return null;
Amount<Length> m = Amount.valueOf(value, fUnit);
return m.doubleValue(tUnit);
}
示例2: testGeneral
import javax.measure.quantity.Length; //导入依赖的package包/类
public void testGeneral()
{
double[] items = new double[]
{12d, 13d, 14d, 15d};
DoubleDataset ds = (DoubleDataset) DatasetFactory.createFromObject(items);
ds.setName(D_NAME);
assertNotNull("failed to create", ds);
NumberDocument nd =
new NumberDocument(ds, null, METRE.asType(Length.class));
assertEquals("correct name", D_NAME, nd.getName());
assertEquals("correct units", "m", nd.getUnits().toString());
assertEquals("correct dimension", "[L]", nd.getUnits().getDimension()
.toString());
Iterator<Double> iter = nd.getIterator();
while (iter.hasNext())
{
Double double1 = (Double) iter.next();
System.out.println("value:" + double1);
}
}
示例3: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
Unit<Length> sourceUnit = METRE;
Unit<Length> targetUnit = CENTI(METRE);
UnitConverter converter = sourceUnit.getConverterTo(targetUnit);
double length1 = 4.0;
double length2 = 6.0;
double result1 = converter.convert(length1);
double result2 = converter.convert(length2);
System.out.println(result1);
System.out.println(result2);
Quantity<Length> quantLength1 = Quantities.getQuantity(4.0, sourceUnit);
Quantity<Length> quantLength2 = Quantities.getQuantity(6.0, targetUnit);
Quantity<Length> quantResult1 = quantLength1.to(targetUnit);
System.out.println(quantResult1);
double mass1 = 5.0;
double result3 = converter.convert(mass1); // does compile
System.out.println(result3);
Quantity<Mass> quantMass1 = Quantities.getQuantity(5.0, KILOGRAM);
//quantMass1.to(targetUnit); // won't compile
}
示例4: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
Quantity<Mass> carat = Quantities.getQuantity(100, CARAT);
System.out.println(carat);
Quantity<Mass> caratsInKg = carat.to(Units.KILOGRAM);
System.out.println(caratsInKg);
Quantity<Information> bit = Quantities.getQuantity(20, BIT);
System.out.println(bit);
Quantity<Information> bytes = bit.to(BYTE);
System.out.println(bytes);
Unit pressure = Units.PASCAL;
System.out.println(pressure);
// Quantity<InformationRate> bps = Quantities.getQuantity(10, BIT_PER_SECOND);
// System.out.println(bps);
Quantity<Length> len = Quantities.getQuantity(10, PARSEC);
System.out.println(len);
}
示例5: main
import javax.measure.quantity.Length; //导入依赖的package包/类
/**
* @param args
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
Quantity<Length> length = Quantities.getQuantity(10, SI.METRE);
// LengthAmount length = new LengthAmount(10, SI.KILOGRAM);
// this won't work ;-)
System.out.println(length);
Unit<Length> lenUnit = length.getUnit();
System.out.println(lenUnit);
System.out.println(((AbstractQuantity) length).doubleValue(USCustomary.FOOT));
// System.out.println(length.doubleValue(USCustomary.POUND));
// this won't work either.
// UnitConverter footConv = lenUnit.getConverterTo(USCustomary.INCH);
System.out.print(((AbstractQuantity<Length>) length).doubleValue(USCustomary.INCH));
System.out.println(" " + USCustomary.FOOT);
Quantity<Mass> mass = Quantities.getQuantity(1000, SI.GRAM);
Quantity<Mass> mass2 = NumberQuantity.of(1, SI.KILOGRAM);
System.out.println(mass.equals(mass2));
}
示例6: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
final String model;
final double dist;
if (args != null && args.length > 0) {
dist = Double.parseDouble(args[0]);
if (args.length > 1) {
model = args[1];
} else {
model = "A380";
}
} else {
dist = 6089d;
model = "A380";
}
// Quantity<Length> distance = Quantities.getQuantity(dist, KILO(METRE));
Quantity<Length> distance = Quantities.getQuantity(dist, USCustomary.MILE);
Airplane airplane = new Airplane(model);
System.out.println(airplane + " flying " + distance);
Quantity<Speed> airplaneSpeed = airplane.getSpeed();
System.out.println(airplane + " flying at " + airplaneSpeed);
System.out.println(airplane + " flying at " + airplaneSpeed.to(USCustomary.MILE_PER_HOUR));
Quantity<Time> timeToDest = distance.divide(airplaneSpeed).asType(Time.class);
System.out.println("TTD: " + timeToDest.to(HOUR));
}
示例7: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
Unit<Mass> atomicMassUnit = CARAT;
System.out.println(atomicMassUnit.getSymbol());
Quantity<Mass> mass = (Quantity<Mass>) Quantities.getQuantity(10, atomicMassUnit);
System.out.println(mass);
Quantity<Mass> massInKg = mass.to(KILOGRAM);
System.out.println(massInKg);
// UnitFormat format = UCUMFormat.getInstance(Variant.CASE_SENSITIVE);
// Unit<?> unit = format.parse("m/s");
// System.out.println(unit);
// unit = format.parse("m^1*s^-1");
// System.out.println(unit);
Quantity<Length> cm = Quantities.getQuantity(10, CENTIMETER);
System.out.println(cm);
Quantity<Length> ft = cm.to(FOOT);
System.out.println(ft);
}
示例8: main
import javax.measure.quantity.Length; //导入依赖的package包/类
/**
* @param args
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
@SuppressWarnings("rawtypes")
Measure length = Measure.valueOf(10, SI.METRE);
// LengthAmount length = new LengthAmount(10, SI.KILOGRAM);
// this won't work ;-)
System.out.println(length);
Unit<Length> lenUnit = length.getUnit();
System.out.println(lenUnit);
System.out.println(length.doubleValue(NonSI.FOOT));
// System.out.println(length.doubleValue(USCustomary.POUND));
// this won't work either.
// UnitConverter footConv = lenUnit.getConverterTo(NonSI.INCH);
System.out.print(((Measurable<Length>) length).doubleValue(NonSI.INCH));
System.out.println(" " + NonSI.FOOT);
Measurable<Mass> mass = Measure.valueOf(1000, SI.GRAM);
Measurable<Mass> mass2 = Measure.valueOf(1, SI.KILOGRAM);
System.out.println(mass.equals(mass2));
}
示例9: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
Double dHeight;
Double dWeight;
if(args.length > 0) {
dHeight = Double.parseDouble(args[0]);
dWeight = Double.parseDouble(args[1]);
} else {
dHeight = 1.85d;
dWeight = 85d;
}
Quantity<Length> height = Quantities.getQuantity(dHeight, METRE);
Quantity<Mass> mass = Quantities.getQuantity(dWeight, KILOGRAM);
Quantity<Area> squareHeight = height.multiply(height).asType(Area.class);
Quantity<?> bmi = mass.divide(squareHeight);
System.out.println(bmi);
printCategory(bmi);
}
示例10: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String[] args) {
Double dHeight;
Double dWeight;
if (args.length > 0) {
dHeight = Double.parseDouble(args[0]);
dWeight = Double.parseDouble(args[1]);
} else {
dHeight = 1.85d;
dWeight = 85d;
}
Quantity<Length> height = Quantities.getQuantity(dHeight, METRE);
// Quantity<Length> heightUS = Quantities.getQuantity(dHeight, FOOT); //
// for US measure units, just add a single line, see below:-)
// Quantity<Length> height = heightUS.to(METRE);
Quantity<Mass> mass = Quantities.getQuantity(dWeight, KILOGRAM);
calculateBMI(height, mass);
}
示例11: calculateDistance
import javax.measure.quantity.Length; //导入依赖的package包/类
private void calculateDistance(
CoordinateReferenceSystem crs, Point[] points) {
if (crs == null) {
crs = default_crs;
}
double distance = 0.0;
try {
distance = JTS.orthodromicDistance(
points[0].getCoordinate(),
points[1].getCoordinate(), crs);
} catch (TransformException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Measure<Double, Length> dist = Measure.valueOf(
distance, SI.METER);
System.out.println(dist.doubleValue(SI.KILOMETER)
+ " Km");
System.out.println(dist.doubleValue(NonSI.MILE)
+ " miles");
}
示例12: OrthodromicDistancePartitioner
import javax.measure.quantity.Length; //导入依赖的package包/类
public OrthodromicDistancePartitioner(
final CoordinateReferenceSystem crs,
final CommonIndexModel indexModel,
final DimensionExtractor<T> dimensionExtractor,
final double[] distancePerDimension,
final Unit<Length> geometricDistanceUnit ) {
super(
distancePerDimension);
this.crs = crs;
this.crsName = crs.getIdentifiers().iterator().next().toString();
this.geometricDistanceUnit = geometricDistanceUnit;
this.dimensionExtractor = dimensionExtractor;
initIndex(
indexModel,
distancePerDimension);
}
示例13: setProgress
import javax.measure.quantity.Length; //导入依赖的package包/类
@Override
public void setProgress(final float p) {
SwingUtilities.invokeLater(new Thread() {
public void run() {
int pct = (int) (p * 100);
bar.setValue(pct);
Amount<Length> web = burn.getMotor().getGrain().webThickness();
Amount<Length> remaining = web.times(1.0 - p);
if (remaining.isLessThan(Amount.valueOf(0, SI.MILLIMETER))) {
remaining = Amount.valueOf(0, remaining.getUnit());
}
bar.setString("Burn Progress: " + pct + "% ("
+ RocketScience.ammountToRoundedString(remaining)
+ " web thickness remaining)");
}
});
}
示例14: getCrossSection
import javax.measure.quantity.Length; //导入依赖的package包/类
public java.awt.geom.Area getCrossSection(Amount<Length> regression){
Amount<Length> zero = Amount.valueOf(0, SI.MILLIMETER);
if ( regression.isLessThan(zero) )
regression = zero;
double rmm = regression.doubleValue(SI.MILLIMETER);
double oDmm = oD.doubleValue(SI.MILLIMETER);
double iDmm = iD.doubleValue(SI.MILLIMETER);
if ( !outerSurfaceInhibited )
oDmm -= 2.0 * rmm;
if ( !innerSurfaceInhibited )
iDmm += 2.0 * rmm;
Shape oDs = new Ellipse2D.Double(-oDmm/2.0, -oDmm/2.0, oDmm, oDmm);
Shape iDs = new Ellipse2D.Double(-iDmm/2.0, -iDmm/2.0, iDmm, iDmm);
java.awt.geom.Area a = new java.awt.geom.Area(oDs);
a.subtract(new java.awt.geom.Area(iDs));
return a;
}
示例15: main
import javax.measure.quantity.Length; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
CoredCylindricalGrain g = new CoredCylindricalGrain();
g.setLength(Amount.valueOf(70, SI.MILLIMETER));
g.setOD(Amount.valueOf(30, SI.MILLIMETER));
g.setID(Amount.valueOf(10, SI.MILLIMETER));
Chart<Length, Area> c = new Chart<Length, Area>(SI.MILLIMETER,
SI.MILLIMETER.pow(2).asType(Area.class), g, "surfaceArea", "Regression", "Area");
c.setDomain(c.new IntervalDomain(Amount.valueOf(0, SI.CENTIMETER), g
.webThickness()));
c.show();
/*
Chart<Length, Volume> v = new Chart<Length, Volume>(SI.MILLIMETER,
SI.MILLIMETER.pow(3).asType(Volume.class), g, "volume");
v.setDomain(c.new IntervalDomain(Amount.valueOf(0, SI.CENTIMETER), g
.webThickness()));
v.show();*/
}