⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 googlebaseattributesextension.java

📁 google的gdata api包
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  /** Sets delivery radius. */  public void setDeliveryRadius(NumberUnit<Float> value) {    removeAttributes(DELIVERY_RADIUS_ATTRIBUTE);    addFloatUnitAttribute(DELIVERY_RADIUS_ATTRIBUTE, value);  }  /** Gets delivery radius. */  public NumberUnit<Float> getDeliveryRadius() {    return getFloatUnitAttribute(DELIVERY_RADIUS_ATTRIBUTE);  }  /** Sets pickup attribute. */  public void setPickup(boolean pickup) {    removeAttributes(PICKUP_ATTRIBUTE, GoogleBaseAttributeType.BOOLEAN);    addBooleanAttribute(PICKUP_ATTRIBUTE, pickup);  }  /** Gets pickup attribute, or null. */  public Boolean getPickup() {    return getBooleanAttribute(PICKUP_ATTRIBUTE);  }  /** Sets delivery notes attribute. */  public void setDeliveryNotes(String notes) {    removeAttributes(DELIVERY_NOTES_ATTRIBUTE, GoogleBaseAttributeType.TEXT);    addTextAttribute(DELIVERY_NOTES_ATTRIBUTE, notes);  }  /** Gets delivery notes attribute */  public String getDeliveryNotes() {    return getTextAttribute(DELIVERY_NOTES_ATTRIBUTE);  }  /** Sets payment notes attribute. */  public void setPaymentNotes(String notes) {    removeAttributes(PAYMENT_NOTES_ATTRIBUTE, GoogleBaseAttributeType.TEXT);    addTextAttribute(PAYMENT_NOTES_ATTRIBUTE, notes);  }  /** Gets payment notes attribute */  public String getPaymentNotes() {    return getTextAttribute(PAYMENT_NOTES_ATTRIBUTE);  }  public Integer getCustomerId() {    return getIntAttribute(CUSTOMER_ID);  }  /**   * Gets a list of all the attributes available in the extension   * namespace at the current {@link com.google.gdata.data.ExtensionPoint}.   *   * Attributes might be repeated.   *   * @return a list of {@link com.google.api.gbase.client.GoogleBaseAttribute},   *   which might be empty but not null   */  public List<? extends GoogleBaseAttribute> getAttributes() {    return attributes;  }  /**   * Gets the first attribute with a certain name.   *   * In most cases, there might be more than one attribute   * with the same name. This method will ignore extra   * attributes. Use {@link #getAttributes(String)} to make sure   * you get all of them.   *   * @param name attribute name   * @return one {@link com.google.api.gbase.client.GoogleBaseAttribute}   *   or null if no attribute was found with this name   */  public GoogleBaseAttribute getAttribute(String name) {    return getAttribute(name, null);  }  /**   * Gets the first attribute with a certain name and type.   *   * In most cases, there might be more than one attribute   * with the same name and type. This method will ignore extra   * attributes. Use {@link #getAttributes(String)} to make sure   * you get all of them.   *   * @param name attribute name   * @param type attribute type (null to ignore the type)   * @return one {@link com.google.api.gbase.client.GoogleBaseAttribute}   *   or null if no attribute was found with this name   */  public GoogleBaseAttribute getAttribute(String name, GoogleBaseAttributeType type) {    for (GoogleBaseAttribute attr : attributes) {      if (hasNameAndType(attr, name, type)) {        return attr;      }    }    return null;  }  private boolean hasNameAndType(GoogleBaseAttribute attr, String name,                                 GoogleBaseAttributeType type) {    return name.equals(attr.getAttributeId().getName()) &&        (type == null || type.isSupertypeOf(attr.getAttributeId().getType()));  }  /**   * Gets all the attributes with a certain name and type.   *   * @param name attribute name   * @param type attribute type, null to ignore the type   * @return a list of {@link com.google.api.gbase.client.GoogleBaseAttribute},   *   which might be empty but not null   */  public List<? extends GoogleBaseAttribute> getAttributes(String name,                                                           GoogleBaseAttributeType type) {    List<GoogleBaseAttribute> retval = new ArrayList<GoogleBaseAttribute>();     for (GoogleBaseAttribute attr : attributes) {        if (hasNameAndType(attr, name, type)) {          retval.add(attr);        }    }    return retval;  }  /**   * Gets all the attributes with a certain name and type.   *   * @param name attribute name   * @return a list of {@link com.google.api.gbase.client.GoogleBaseAttribute},   *   which might be empty but not null   */  public List<? extends GoogleBaseAttribute> getAttributes(String name) {    return getAttributes(name, null);  }  /**   * Adds an attribute to the list.   *   * 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 attribute   * @return the attribute passed as parameter   */  public GoogleBaseAttribute addAttribute(GoogleBaseAttribute attribute) {    attributes.add(attribute);    return attribute;  }  /**   * Removes an attribute from the list.   *   * @param value   */  public void removeAttribute(GoogleBaseAttribute value) {    attributes.remove(value);  }  /**   * Removes all attributes with a certain name from the list.   *   * @param name name of the attributes that should be removed   */  public void removeAttributes(String name) {    removeAttributes(name, null);  }  /**   * Removes all attributes with a certain name and   * type from the list.   *   * @param name name of the attributes that should be removed   * @param type attribute type, null to ignore the type   */  public void removeAttributes(String name, GoogleBaseAttributeType type) {    Iterator<GoogleBaseAttribute> iter = attributes.iterator();    while (iter.hasNext()) {      GoogleBaseAttribute attribute = iter.next();      if (hasNameAndType(attribute, name, type)) {        iter.remove();      }    }  }  /**   * Removes all attributes from the list.   */  public void clearAttributes() {    attributes.clear();  }  /**   * Gets the first value of a specific attribute, as a string.   *   * If it makes sense for the attribute to appear more   * than once, you might consider calling   * {@link #getTextAttributeValues(String)} instead.   *   * This method checks the type of the attribute   * that is being queried. Use   * {@link #getAttributeAsString(String, GoogleBaseAttributeType)}   * if you would like to get the value of non-string attributes.   *   * @param name attribute name   * @return value of the attribute or null if no attribute   *   with this name was found on the list   */  public String getTextAttribute(String name) {    return getAttributeAsString(name, GoogleBaseAttributeType.TEXT);  }  /**   * Gets the first value of a specific reference attribute.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#REFERENCE}.   *   * @param name attribute name   * @return value of the attribute or null if no reference attribute   *   with this name was found on the list   */  public String getReferenceAttribute(String name) {    return getAttributeAsString(name, GoogleBaseAttributeType.REFERENCE);  }    /**   * Gets the string representation of the first   * attribute with matching name and type.   *   * This method does not check the type of the attributes   * that are being queried. It just returns what it finds.   *   * @param name attribute name   * @param type attribute type, null to ignore the type   * @return the string representation of the first matching   *   attribute or null if none was found   */  private String getAttributeAsString(String name,                                      GoogleBaseAttributeType type) {    GoogleBaseAttribute attribute = getAttribute(name, type);    if (attribute == null) {      return null;    }    return attribute.getValueAsString();  }  /**   * Gets all the values of a specific attribute, as a list   * of strings.   *   * This method checks the type of the attribute   * that are being queried. Use   * {@link #getAttributeAsString(String, GoogleBaseAttributeType)}   * if you would like to get the value non-string attributes.   *   * @param attributeName   * @return a list of strings, which might be empty but   *   not null   */  public List<String> getTextAttributeValues(String attributeName) {    return getAttributeValuesAsString(attributeName,                                      GoogleBaseAttributeType.TEXT);  }  /**   * Gets the string representation of all attributes with matching   * names and types.   *   * @param name attribute name   * @param type attribute type, null to ignore the type   * @return a list of strings, which might be empty but not null   */  private List<String> getAttributeValuesAsString(      String name, GoogleBaseAttributeType type) {    List<? extends GoogleBaseAttribute> labels =        getAttributes(name, type);    List<String> retval = new ArrayList<String>(labels.size());    for (GoogleBaseAttribute label : labels) {      retval.add(label.getValueAsString());    }    return retval;  }  /**   * Gets the first value of a specific attribute, as a Float.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#FLOAT}.   *   * @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 Float getFloatAttribute(String name) {    return ConversionUtil.toFloat(        getAttributeAsString(name, GoogleBaseAttributeType.FLOAT));  }  /**   * Gets the first value of a specific attribute, as an Integer.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#INT}.   *   * @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 Integer getIntAttribute(String name) {    return ConversionUtil.toInteger(        getAttributeAsString(name,GoogleBaseAttributeType.INT));  }  /**   * Gets the first value of a specific attribute, as a Number.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#NUMBER}.   *   * @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 Number getNumberAttribute(String name) {    GoogleBaseAttribute attr =        getAttribute(name, GoogleBaseAttributeType.NUMBER);    return ConversionUtil.extractNumber(attr);  }  /**   * Gets the first value of a specific attribute, as an Boolean.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#BOOLEAN}.   *   *   * @param name attribute name   * @return value of the attribute or null if no attribute   *   with this name was found on the list   */  public Boolean getBooleanAttribute(String name) {    return ConversionUtil.toBoolean(        getAttributeAsString(name, GoogleBaseAttributeType.BOOLEAN));  }  /**   * Gets the first value of a specific attribute, as a date and a time.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#DATE_TIME}.   *   *   * @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 DateTime getDateTimeAttribute(String name) {    return ConversionUtil.toDateOrDateTime(        getAttributeAsString(name, GoogleBaseAttributeType.DATE_TIME));  }  /**   * Gets the first value of a specific attribute, as a date.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#DATE_TIME} and   * {@link GoogleBaseAttributeType#DATE}.   *   *   * @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 DateTime getDateAttribute(String name) {    return ConversionUtil.toDateOrDateTime(        getAttributeAsString(name, GoogleBaseAttributeType.DATE));  }  /**   * Gets the first value of a specific attribute, as a date/dateTime   * range.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#DATE_TIME},   * {@link GoogleBaseAttributeType#DATE} and   * {@link GoogleBaseAttributeType#DATE_TIME_RANGE}.   *   *   * @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 DateTimeRange getDateRangeAttribute(String name) {    GoogleBaseAttribute attribute =        getAttribute(name, GoogleBaseAttributeType.DATE_TIME_RANGE);    return ConversionUtil.extractDateTimeRange(attribute);  }  /**   * Gets the first value of a specific attribute, as an url.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#URL}.   *   * @param name attribute name   * @return value of the attribute or null if no attribute   *   with this name was found on the list   */  public String getUrlAttribute(String name) {    return getAttributeAsString(name, GoogleBaseAttributeType.URL);  }  /**   * Gets the first value of a specific attribute, as an integer,   * followed by a unit name.   *   * This method only takes into account attributes of type   * {@link GoogleBaseAttributeType#INT_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<Integer> getIntUnitAttribute(String name) {    return ConversionUtil.toIntUnit(        getAttributeAsString(name, GoogleBaseAttributeType.INT_UNIT));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -