/** * Gets the first value of a specific attribute, as an float, * followed by a unit name. * * This method only takes into account attributes of type * {@link GoogleBaseAttributeType#FLOAT_UNIT}. * * @param name attribute name * @return value of the attribute or null if no attribute * with this name was found on the list * @exception NumberFormatException if some value was * found that could not be converted */ public NumberUnit<Float> getFloatUnitAttribute(String name) { return ConversionUtil.toFloatUnit( getAttributeAsString(name, GoogleBaseAttributeType.FLOAT_UNIT)); }
/** * Gets the first value of a specific attribute, as an float, * followed by a unit name. * * This method only takes into account attributes of type * {@link GoogleBaseAttributeType#FLOAT_UNIT}. * * @param name attribute name * @return value of the attribute or null if no attribute * with this name was found on the list * @exception NumberFormatException if some value was * found that could not be converted */ public NumberUnit<Float> getFloatUnitAttribute(String name) { return ConversionUtil.toFloatUnit( getAttributeAsString(name, GoogleBaseAttributeType.FLOAT_UNIT)); }
String price = attr.getValueAsString(); try { priceUnit = toFloatUnit(price); } catch (NumberFormatException e) { priceUnit = new NumberUnit<Float>(Float.parseFloat(price), null);
String price = attr.getValueAsString(); try { priceUnit = toFloatUnit(price); } catch (NumberFormatException e) { priceUnit = new NumberUnit<Float>(Float.parseFloat(price), null);
/** * Extracts a <code>NumberUnit<Number></code> from a * {@link GoogleBaseAttribute}. * * @param attr an attribute of type NUMBER_UNIT, FLOAT_UNIT or INT_UNIT, * may be null * @return a NumberUnit object whose number might be an Integer * or a Float, depending on the type of the attribute, or null * if {@code attr} was null */ public static NumberUnit<? extends Number> extractNumberUnit( GoogleBaseAttribute attr) { if (attr == null) { return null; } if (GoogleBaseAttributeType.INT_UNIT.equals(attr.getAttributeId().getType())) { return toIntUnit(attr.getValueAsString()); } return toFloatUnit(attr.getValueAsString()); } }
private static Shipping extractShippingFromElements(GoogleBaseAttribute attribute) { String country = attribute.getSubElementValue(ShippingField.Country.getElemName()); Collection<String> regions = attribute.getSubElementValues(ShippingField.Region.getElemName()); String price = attribute.getSubElementValue(ShippingField.Price.getElemName()); String service = attribute.getSubElementValue(ShippingField.Service.getElemName()); if (price == null) { throw new NumberFormatException( "missing 'price' element in shipping attribute: " + attribute); } NumberUnit<Float> priceUnit; try { priceUnit = toFloatUnit(price); } catch (NumberFormatException e) { priceUnit = new NumberUnit<Float>(Float.parseFloat(price), null); } return new Shipping(country, regions, service, priceUnit.getValue(), priceUnit.getUnit()); }
/** * Extracts a <code>NumberUnit<Number></code> from a * {@link GoogleBaseAttribute}. * * @param attr an attribute of type NUMBER_UNIT, FLOAT_UNIT or INT_UNIT, * may be null * @return a NumberUnit object whose number might be an Integer * or a Float, depending on the type of the attribute, or null * if {@code attr} was null */ public static NumberUnit<? extends Number> extractNumberUnit( GoogleBaseAttribute attr) { if (attr == null) { return null; } if (GoogleBaseAttributeType.INT_UNIT.equals(attr.getAttributeId().getType())) { return toIntUnit(attr.getValueAsString()); } return toFloatUnit(attr.getValueAsString()); } }
private static Shipping extractShippingFromElements(GoogleBaseAttribute attribute) { String country = attribute.getSubElementValue(ShippingField.Country.getElemName()); Collection<String> regions = attribute.getSubElementValues(ShippingField.Region.getElemName()); String price = attribute.getSubElementValue(ShippingField.Price.getElemName()); String service = attribute.getSubElementValue(ShippingField.Service.getElemName()); if (price == null) { throw new NumberFormatException( "missing 'price' element in shipping attribute: " + attribute); } NumberUnit<Float> priceUnit; try { priceUnit = toFloatUnit(price); } catch (NumberFormatException e) { priceUnit = new NumberUnit<Float>(Float.parseFloat(price), null); } return new Shipping(country, regions, service, priceUnit.getValue(), priceUnit.getUnit()); }