private boolean hasNameAndType(GoogleBaseAttribute attr, String name, GoogleBaseAttributeType type) { GoogleBaseAttributeType subtype = attr.getAttributeId().getType(); return name.equals(attr.getAttributeId().getName()) && (type == null || subtype != null && type.isSupertypeOf(subtype)); }
private boolean hasNameAndType(GoogleBaseAttribute attr, String name, GoogleBaseAttributeType type) { GoogleBaseAttributeType subtype = attr.getAttributeId().getType(); return name.equals(attr.getAttributeId().getName()) && (type == null || subtype != null && type.isSupertypeOf(subtype)); }
/** * Returns the XML attributes that should be set to the * element corresponding to the given * {@link com.google.api.gbase.client.GoogleBaseAttribute}. * * This method is meant to be implemented in subclasses that need * so set attributes. By default, it defines no attributes and * simply returns null. * * @param attribute * @return a collection of XML attributes or null */ private Collection<XmlWriter.Attribute> getXmlAttributes( GoogleBaseAttribute attribute) { GoogleBaseAttributeType type = attribute.getAttributeId().getType(); if (type == null) { return null; } List<XmlWriter.Attribute> attributes = new ArrayList<XmlWriter.Attribute>(); attributes.add(new XmlWriter.Attribute("type", type.toString())); if (attribute.isPrivate()) { attributes.add(new XmlWriter.Attribute("access", "private")); } return attributes; }
/** * Returns the XML attributes that should be set to the * element corresponding to the given * {@link com.google.api.gbase.client.GoogleBaseAttribute}. * * This method is meant to be implemented in subclasses that need * so set attributes. By default, it defines no attributes and * simply returns null. * * @param attribute * @return a collection of XML attributes or null */ private Collection<XmlWriter.Attribute> getXmlAttributes( GoogleBaseAttribute attribute) { GoogleBaseAttributeType type = attribute.getAttributeId().getType(); if (type == null) { return null; } List<XmlWriter.Attribute> attributes = new ArrayList<XmlWriter.Attribute>(); attributes.add(new XmlWriter.Attribute("type", type.toString())); if (attribute.isPrivate()) { attributes.add(new XmlWriter.Attribute("access", "private")); } return attributes; }
/** * Extracts a {@link Number} from a {@link GoogleBaseAttribute}. * * @param attr an attribute of type NUMBER, FLOAT or INT, may be null * @return a Number, which might be an Integer or a Float depending * on the type of the attribute, or null if {@code attr} was null */ public static Number extractNumber(GoogleBaseAttribute attr) { if (attr == null) { return null; } /* If the attribute has been declared as being an int, * treat it as such, otherwise create a Float. */ if (GoogleBaseAttributeType.FLOAT.equals(attr.getAttributeId().getType())) { return toFloat(attr.getValueAsString()); } else { return toInteger(attr.getValueAsString()); } }
/** * 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()); } }
/** * 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()); } }
/** * Extracts a {@link Number} from a {@link GoogleBaseAttribute}. * * @param attr an attribute of type NUMBER, FLOAT or INT, may be null * @return a Number, which might be an Integer or a Float depending * on the type of the attribute, or null if {@code attr} was null */ public static Number extractNumber(GoogleBaseAttribute attr) { if (attr == null) { return null; } /* If the attribute has been declared as being an int, * treat it as such, otherwise create a Float. */ if (GoogleBaseAttributeType.FLOAT.equals(attr.getAttributeId().getType())) { return toFloat(attr.getValueAsString()); } else { return toInteger(attr.getValueAsString()); } }
private void generateAttribute(GoogleBaseAttribute attribute, XmlWriter xmlWriter) throws IOException { String elementName = convertToElementName(attribute.getAttributeId().getName()); xmlWriter.startElement(GoogleBaseNamespaces.G, elementName, getXmlAttributes(attribute), null); generateValue(attribute, xmlWriter); generateSubElements(attribute, xmlWriter); generateAdjustments(attribute, xmlWriter); generateSubAttributes(attribute, xmlWriter); xmlWriter.endElement(); }
private void generateAttribute(GoogleBaseAttribute attribute, XmlWriter xmlWriter) throws IOException { String elementName = convertToElementName(attribute.getAttributeId().getName()); xmlWriter.startElement(GoogleBaseNamespaces.G, elementName, getXmlAttributes(attribute), null); generateValue(attribute, xmlWriter); generateSubElements(attribute, xmlWriter); generateAdjustments(attribute, xmlWriter); generateSubAttributes(attribute, xmlWriter); xmlWriter.endElement(); }