当前位置: 首页>>代码示例>>Java>>正文


Java Length类代码示例

本文整理汇总了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);
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:18,代码来源:DefaultLengthConverter.java

示例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);
  }

}
 
开发者ID:debrief,项目名称:limpet,代码行数:25,代码来源:TestNewStrategy.java

示例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
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:22,代码来源:UnitConverterDemo.java

示例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);
    }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:21,代码来源:CLDRDemo.java

示例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));
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:25,代码来源:HelloUnits.java

示例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));
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:26,代码来源:AirplaneDemo.java

示例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);
	}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:24,代码来源:CLDRDemoSE.java

示例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));
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:26,代码来源:HelloUnits.java

示例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);
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:20,代码来源:BMIDemoSE.java

示例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);
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:19,代码来源:BMIDemo.java

示例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");
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:23,代码来源:OrthodromicDistance.java

示例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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:17,代码来源:OrthodromicDistancePartitioner.java

示例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)");
		}
	});
}
 
开发者ID:bkuker,项目名称:motorsim,代码行数:18,代码来源:SummaryPanel.java

示例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;
}
 
开发者ID:bkuker,项目名称:motorsim,代码行数:21,代码来源:CoredCylindricalGrain.java

示例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();*/
}
 
开发者ID:bkuker,项目名称:motorsim,代码行数:24,代码来源:Chart.java


注:本文中的javax.measure.quantity.Length类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。