📄 googlebaseattributesextension.java
字号:
} /** * 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 a Number, * followed by a unit name. * * This method only takes into account attributes of type * {@link GoogleBaseAttributeType#NUMBER_UNIT}, * {@link GoogleBaseAttributeType#INT_UNIT} or * {@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<? extends Number> getNumberUnitAttribute(String name) { return ConversionUtil.extractNumberUnit( getAttribute(name, GoogleBaseAttributeType.NUMBER_UNIT)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#TEXT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addTextAttribute(String name, String value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.TEXT, value)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#REFERENCE}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addReferenceAttribute(String name, String value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.REFERENCE, value)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#INT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addIntAttribute(String name, int value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.INT, Integer.toString(value))); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#FLOAT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addFloatAttribute(String name, float value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.FLOAT, Float.toString(value))); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#NUMBER}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addNumberAttribute(String name, Number value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.NUMBER, value.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#INT_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value * @param unit * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addIntUnitAttribute(String name, int value, String unit) { return addIntUnitAttribute(name, new NumberUnit<Integer>(value, unit)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#INT_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addIntUnitAttribute(String name, NumberUnit<Integer> value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.INT_UNIT, value.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#FLOAT_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value * @param unit * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addFloatUnitAttribute(String name, float value, String unit) { return addFloatUnitAttribute(name, new NumberUnit<Float>(value, unit)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#FLOAT_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addFloatUnitAttribute(String name, NumberUnit<Float> value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.FLOAT_UNIT, value.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#NUMBER_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value * @param unit * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addNumberUnitAttribute(String name, Number value, String unit) { return addNumberUnitAttribute(name, new NumberUnit<Number>(value, unit)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#NUMBER_UNIT}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addNumberUnitAttribute(String name, NumberUnit<Number> value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.NUMBER_UNIT, value.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#DATE}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param date attribute value * @return the attribute object that has been created and added to the item * @exception IllegalArgumentException if the attribute value is * not only a date, but a date and a time (see * {@link com.google.gdata.data.DateTime#isDateOnly()}) */ public GoogleBaseAttribute addDateAttribute(String name, DateTime date) { if (!date.isDateOnly()) { throw new IllegalArgumentException("DateTime should be only a date, " + "NOT a date and a time. Call addDateTimeAttribute() instead."); } return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.DATE, date.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#DATE_TIME}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param dateTime attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addDateTimeAttribute(String name, DateTime dateTime) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.DATE_TIME, dateTime.toString())); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#URL}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addUrlAttribute(String name, String value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.URL, value)); } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#BOOLEAN}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param value attribute value * @return the attribute object that has been created and added to the item */ public GoogleBaseAttribute addBooleanAttribute(String name, boolean value) { return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.BOOLEAN, Boolean.toString(value))); } /** * Gets the first value of a specific attribute, as a * {@link com.google.api.gbase.client.Shipping}. * * This method does not check the type of the attribute * that's being queried, it just gets the value and try * and convert it. * * @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 Shipping getShippingAttribute(String name) { GoogleBaseAttribute value = getAttribute(name); if (value == null) { return null; } return ConversionUtil.extractShipping(value); } /** * Gets all the values of a specific attribute, as a list of * {@link com.google.api.gbase.client.Shipping}s. * * This method does not check the type of the attribute * that's being queried, it just gets the values and try * and convert them. * * @param name attribute name * @return a list of Shipping, which might be empty but not null * @exception NumberFormatException if some value was * found that could not be converted */ public List<? extends Shipping> getShippingAttributes(String name) { List<Shipping> retval = new ArrayList<Shipping>(); for (GoogleBaseAttribute attr: attributes) { if (hasNameAndType(attr, name, GoogleBaseAttributeType.SHIPPING)) { retval.add(ConversionUtil.extractShipping(attr)); } } return retval; } /** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#SHIPPING}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param shipping attribute value */ public void addShippingAttribute(String name, Shipping shipping) { addAttribute(ConversionUtil.createAttribute(name, shipping)); } /** * Gets the first value of a specific location attribute, as an * address. * * If you would like to get latitude and longitude and not * just the address, use {@link #getLocationAttributeAsObject(String)} * instead. * * @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 String getLocationAttribute(String name) { return getAttributeAsString(name, GoogleBaseAttributeType.LOCATION); } /** * Gets the first value of a specific location attribute, as a * location object. * * @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 Location getLocationAttributeAsObject(String name) { GoogleBaseAttribute attribute = getAttribute(name); if (attribute == null) { return null; } return ConversionUtil.extractLocation(attribute); } /** * Gets all the values of a specific location attribute, as a list of * strings. * * @param name attribute name * @return a list of locations, which might be empty but not null * @exception NumberFormatException if some value was * found that could not be converted */ public List<? extends String> getLocationAttributes(String name) { return getAttributeValuesAsString(name, GoogleBaseAttributeType.LOCATION); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -