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


Java ConversionException类代码示例

本文整理汇总了Java中javax.measure.converter.ConversionException的典型用法代码示例。如果您正苦于以下问题:Java ConversionException类的具体用法?Java ConversionException怎么用?Java ConversionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConversionException类属于javax.measure.converter包,在下文中一共展示了ConversionException类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: plus

import javax.measure.converter.ConversionException; //导入依赖的package包/类
/**
 * Returns the sum of this measure with the one specified.
 *
 * @param  that the measure to be added.
 * @return <code>this + that</code>.
 * @throws ConversionException if the current model does not allows for
 *         these quantities to be added.
 */
@SuppressWarnings("unchecked")
public Amount<Q> plus(Amount that) throws ConversionException {
    final Amount thatToUnit = that.to(_unit);
    Amount<Q> m = Amount.newInstance(_unit);
    if (this._isExact && thatToUnit._isExact) {
        long sumLong = this._exactValue + thatToUnit._exactValue;
        double sumDouble = ((double) this._exactValue)
                + ((double) thatToUnit._exactValue);
        if (sumLong == sumDouble)
            return m.setExact(sumLong);
    }
    double min = this._minimum + thatToUnit._minimum;
    double max = this._maximum + thatToUnit._maximum;
    m._isExact = false;
    m._minimum = (min < 0) ? min * INCREMENT : min * DECREMENT;
    m._maximum = (max < 0) ? max * DECREMENT : max * INCREMENT;
    return m;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:Amount.java

示例2: minus

import javax.measure.converter.ConversionException; //导入依赖的package包/类
/**
 * Returns the difference of this measure with the one specified.
 *
 * @param  that the measure to be subtracted.
 * @return <code>this - that</code>.
 * @throws ConversionException if the current model does not allows for
 *         these quantities to be subtracted.
 */
@SuppressWarnings("unchecked")
public Amount<Q> minus(Amount that) throws ConversionException {
    final Amount thatToUnit = that.to(_unit);
    Amount<Q> m = Amount.newInstance(_unit);
    if (this._isExact && thatToUnit._isExact) {
        long diffLong = this._exactValue - thatToUnit._exactValue;
        double diffDouble = ((double) this._exactValue)
                - ((double) thatToUnit._exactValue);
        if (diffLong == diffDouble)
            return m.setExact(diffLong);
    }
    double min = this._minimum - thatToUnit._maximum;
    double max = this._maximum - thatToUnit._minimum;
    m._isExact = false;
    m._minimum = (min < 0) ? min * INCREMENT : min * DECREMENT;
    m._maximum = (max < 0) ? max * DECREMENT : max * INCREMENT;
    return m;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:Amount.java

示例3: toStandardUnit

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Override
public UnitConverter toStandardUnit() {
    if (hasOnlyStandardUnit())
        return UnitConverter.IDENTITY;
    UnitConverter converter = UnitConverter.IDENTITY;
    for (int i = 0; i < _elements.length; i++) {
        UnitConverter cvtr = _elements[i]._unit.toStandardUnit();
        if (!cvtr.isLinear())
            throw new ConversionException(_elements[i]._unit
                    + " is non-linear, cannot convert");
        if (_elements[i]._root != 1)
            throw new ConversionException(_elements[i]._unit
                    + " holds a base unit with fractional exponent");
        int pow = _elements[i]._pow;
        if (pow < 0) { // Negative power.
            pow = -pow;
            cvtr = cvtr.inverse();
        }
        for (int j = 0; j < pow; j++) {
            converter = converter.concatenate(cvtr);
        }
    }
    return converter;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:25,代码来源:ProductUnit.java

示例4: getConverterTo

import javax.measure.converter.ConversionException; //导入依赖的package包/类
/**
 * Returns a converter of numeric values from this unit to another unit.
 *
 * @param  that the unit to which to convert the numeric values.
 * @return the converter from this unit to <code>that</code> unit.
 * @throws ConversionException if the conveter cannot be constructed
 *         (e.g. <code>!this.isCompatible(that)</code>).
 */
public final UnitConverter getConverterTo(Unit<?> that)
        throws ConversionException {
    if (this.equals(that))
        return UnitConverter.IDENTITY;
    Unit<?> thisSystemUnit = this.getStandardUnit();
    Unit<?> thatSystemUnit = that.getStandardUnit();
    if (thisSystemUnit.equals(thatSystemUnit))
        return that.toStandardUnit().inverse().concatenate(
                this.toStandardUnit());
    // Use dimensional transforms.
    if (!thisSystemUnit.getDimension()
            .equals(thatSystemUnit.getDimension()))
        throw new ConversionException(this + " is not compatible with "
                + that);
    // Transform between SystemUnit and BaseUnits is Identity. 
    UnitConverter thisTransform = this.toStandardUnit().concatenate(
            transformOf(this.getBaseUnits()));
    UnitConverter thatTransform = that.toStandardUnit().concatenate(
            transformOf(that.getBaseUnits()));
    return thatTransform.inverse().concatenate(thisTransform);
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:30,代码来源:Unit.java

示例5: transformOf

import javax.measure.converter.ConversionException; //导入依赖的package包/类
private static UnitConverter transformOf(Unit<?> baseUnits) {
    if (baseUnits instanceof BaseUnit)
        return Dimension.getModel().getTransform((BaseUnit<?>) baseUnits);
    // Product of units.
    ProductUnit<?> productUnit = (ProductUnit<?>) baseUnits;
    UnitConverter converter = UnitConverter.IDENTITY;
    for (int i = 0; i < productUnit.getUnitCount(); i++) {
        Unit<?> unit = productUnit.getUnit(i);
        UnitConverter cvtr = transformOf(unit);
        if (!cvtr.isLinear())
            throw new ConversionException(baseUnits
                    + " is non-linear, cannot convert");
        if (productUnit.getUnitRoot(i) != 1)
            throw new ConversionException(productUnit
                    + " holds a base unit with fractional exponent");
        int pow = productUnit.getUnitPow(i);
        if (pow < 0) { // Negative power.
            pow = -pow;
            cvtr = cvtr.inverse();
        }
        for (int j = 0; j < pow; j++) {
            converter = converter.concatenate(cvtr);
        }
    }
    return converter;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:Unit.java

示例6: getExtent

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Override
protected AmountExtent<?> getExtent() {
	final Plot plot = getModel();
	AmountExtent<?> extent = super.getExtent();
	if (extent == null) {
		extent = plot.getExtent();
	}
	if (extent != null) {
		Unit nominalUnits = getModel().getProfile().getUnits();
		try {
			extent = extent.to(nominalUnits);
		} catch (ConversionException e) {
			// silence
		}
	}
	return extent;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:18,代码来源:PlotDataEditPart.java

示例7: convert

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Override
public double convert(double x) throws ConversionException {
    Double refAmount = TO_REFERENCE.get(_code);
    if (refAmount == null) 
          throw new ConversionException("Exchange rate not set for " + _code);
    return _invert ? x / refAmount.doubleValue() : x * refAmount.doubleValue();
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:8,代码来源:Currency.java

示例8: testMisc

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Test(expected = ConversionException.class)
public void testMisc() {
    Amount<Length> position = Amount.valueOf(1, 0.02, SI.METER);
    Amount<Length> position2 = Amount.valueOf(1, 0.02, SI.METER);

    Amount<?> positionResult = position.times(position2);
    System.out.println(positionResult);
    System.out.println(positionResult.getAbsoluteError());
    System.out.println(positionResult.getRelativeError());

    position.divide(position2).to(SI.METER);
}
 
开发者ID:tensorics,项目名称:tensorics-core,代码行数:13,代码来源:JScienceMiscTest.java

示例9: converteTo

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Override
public double converteTo(JEVisUnit unit, double number) {
    //TODo check if unit is compatible
    try {
        Unit targetUnit = UnitManager.getInstance().getUnitWithPrefix(((JEVisUnitImp) unit).getUnit(), unit.getPrefix());
        Unit sourceUnit = UnitManager.getInstance().getUnitWithPrefix(_unit, getPrefix());

        UnitConverter uc = sourceUnit.getConverterTo(targetUnit);
        return uc.convert(number);
    } catch (Exception ex) {
        throw new ConversionException("Unit error: " + ex.getMessage());
    }

}
 
开发者ID:OpenJEVis,项目名称:JECommons,代码行数:15,代码来源:JEVisUnitImp.java

示例10: testConvertStructureError

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Test(expected=ConversionException.class)
public void testConvertStructureError() throws Exception {
    unitConverter.setReaderUnits(ImmutableMap.of("global", ImmutableMap.of("standard", ImmutableMap.of("length", "nm"))));
    unitConverter.setWriterUnits(ImmutableMap.of("global", ImmutableMap.of("standard", ImmutableMap.of("length", "ps"))));
    unitConverter.convertStructure(this.struct, FileType.STRUCTURE);
}
 
开发者ID:ccaleman,项目名称:MDConverter,代码行数:7,代码来源:UnitConverterImplTest.java

示例11: incompatibleUnitsThrow

import javax.measure.converter.ConversionException; //导入依赖的package包/类
@Test(expected = ConversionException.class)
public void incompatibleUnitsThrow() {
    convert(valueOf(1.0, METER)).to(VOLT);
}
 
开发者ID:tensorics,项目名称:tensorics-core,代码行数:5,代码来源:QuantityDoubleSupportTest.java

示例12: buildSurroundingGeometries

import javax.measure.converter.ConversionException; //导入依赖的package包/类
/**
 * Build geometries with the provided coordinate at the center. The width of
 * the geometry is twice the distance provided. More than one geometry is
 * return when passing the date line.
 * 
 * @param distances
 *            [x,y] = [longitude, latitude]
 * @param unit
 * @param coordinate
 * @return
 */
public List<Geometry> buildSurroundingGeometries(
		final double[] distances,
		final Unit<Length> unit,
		Coordinate coordinate ) {
	List<Geometry> geos = new LinkedList<Geometry>();
	GeodeticCalculator geoCalc = new GeodeticCalculator();
	geoCalc.setStartingGeographicPoint(
			coordinate.x,
			coordinate.y);
	try {
		geoCalc.setDirection(
				0,
				unit.getConverterTo(
						SI.METER).convert(
						distances[1]));
		DirectPosition north = geoCalc.getDestinationPosition();
		geoCalc.setDirection(
				90,
				unit.getConverterTo(
						SI.METER).convert(
						distances[0]));
		DirectPosition east = geoCalc.getDestinationPosition();
		geoCalc.setStartingGeographicPoint(
				coordinate.x,
				coordinate.y);
		geoCalc.setDirection(
				-90,
				unit.getConverterTo(
						SI.METER).convert(
						distances[0]));
		DirectPosition west = geoCalc.getDestinationPosition();
		geoCalc.setDirection(
				180,
				unit.getConverterTo(
						SI.METER).convert(
						distances[1]));
		DirectPosition south = geoCalc.getDestinationPosition();

		double x1 = west.getOrdinate(0);
		double x2 = east.getOrdinate(0);
		double y1 = north.getOrdinate(1);
		double y2 = south.getOrdinate(1);

		handleBoundaries(
				geos,
				coordinate,
				x1,
				x2,
				y1,
				y2);
		return geos;
	}
	catch (IllegalArgumentException | IndexOutOfBoundsException | TransformException | ConversionException ex) {
		LOGGER.error(
				"Unable to build geometry",
				ex);
	}

	return null;
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:72,代码来源:GeometryCalculations.java

示例13: generateUnitConversionAlgorithm

import javax.measure.converter.ConversionException; //导入依赖的package包/类
String generateUnitConversionAlgorithm(Attribute targetAttribute, EntityType targetEntityType,
		Attribute sourceAttribute, EntityType sourceEntityType)
{
	String algorithm = null;

	Unit<? extends Quantity> targetUnit = unitResolver.resolveUnit(targetAttribute, targetEntityType);

	Unit<? extends Quantity> sourceUnit = unitResolver.resolveUnit(sourceAttribute, sourceEntityType);

	if (sourceUnit != null)
	{
		if (targetUnit != null && !sourceUnit.equals(targetUnit))
		{
			// if units are convertible, create convert algorithm
			UnitConverter unitConverter;
			try
			{
				unitConverter = sourceUnit.getConverterTo(targetUnit);
			}
			catch (ConversionException e)
			{
				unitConverter = null;
				// algorithm sets source unit and assigns source value to target
				algorithm = String.format("$('%s').unit('%s').value();", sourceAttribute.getName(),
						sourceUnit.toString());
			}

			if (unitConverter != null)
			{
				// algorithm sets source unit and assigns value converted to target unit to target
				algorithm = String.format("$('%s').unit('%s').toUnit('%s').value();", sourceAttribute.getName(),
						sourceUnit.toString(), targetUnit.toString());
			}
		}
		else
		{
			// algorithm sets source unit and assigns source value to target
			algorithm = String.format("$('%s').unit('%s').value();", sourceAttribute.getName(),
					sourceUnit.toString());
		}
	}

	if (algorithm == null)
	{
		// algorithm assigns source value to target
		algorithm = String.format("$('%s').value();", sourceAttribute.getName());
	}

	return algorithm;
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:51,代码来源:NumericAlgorithmGenerator.java

示例14: getExchangeRate

import javax.measure.converter.ConversionException; //导入依赖的package包/类
/**
 * Returns the exchange rate for this {@link Currency}.
 *
 * @return the amount stated in the {@link #getReferenceCurrency}
 *         equals to one unit of this {@link Currency}.
 * @throws ConversionException if the exchange rate has not be set for
 *         this {@link Currency}.
 */
public double getExchangeRate() {
    Double refAmount = TO_REFERENCE.get(this.getCode());
    if (refAmount == null) 
          throw new ConversionException("Exchange rate not set for " + this.getCode());
    return refAmount.doubleValue();
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:15,代码来源:Currency.java


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