@Override public boolean equals(Object o) { if (!(o instanceof GoogleBaseAttributeId)) { return false; } GoogleBaseAttributeId other = (GoogleBaseAttributeId)o; if (!name.equals(other.name)) { return false; } if (type == null) { return other.type == null; } else { return type.equals(other.type); } } }
@Override public boolean equals(Object o) { if (!(o instanceof GoogleBaseAttributeId)) { return false; } GoogleBaseAttributeId other = (GoogleBaseAttributeId)o; if (!name.equals(other.name)) { return false; } if (type == null) { return other.type == null; } else { return type.equals(other.type); } } }
/** * Checks whether the given type is the same as this type or a subtype. * * @param subtype * @return true if <code>subtype</code> is the same type or a subtype * of the current type */ public boolean isSupertypeOf(GoogleBaseAttributeType subtype) { if (this.equals(subtype)) { return true; } GoogleBaseAttributeType otherSupertype = subtype.getSupertype(); if (otherSupertype == null) { return false; } return isSupertypeOf(otherSupertype); } }
/** * Checks whether the given type is the same as this type or a subtype. * * @param subtype * @return true if <code>subtype</code> is the same type or a subtype * of the current type */ public boolean isSupertypeOf(GoogleBaseAttributeType subtype) { if (this.equals(subtype)) { return true; } GoogleBaseAttributeType otherSupertype = subtype.getSupertype(); if (otherSupertype == null) { return false; } return isSupertypeOf(otherSupertype); } }
/** * Creates a {@link GoogleBaseAttribute} of type * {@link GoogleBaseAttributeType#GROUP} and initializes it using the * current state of the object. Sub-attributes of group with type * GROUP or GROUP's derived types are ignored. * * @param name attribute name * @param group attribute value * @return a new {@link com.google.api.gbase.client.GoogleBaseAttribute} */ public static GoogleBaseAttribute createAttribute(String name, Group group) { GoogleBaseAttribute attribute = new GoogleBaseAttribute(name, GoogleBaseAttributeType.GROUP); Multimap<String, GoogleBaseAttribute> subAttributes = group.getAllSubAttributes(); for (GoogleBaseAttribute attr : subAttributes.values()) { GoogleBaseAttributeType type = attr.getType(); if (!GoogleBaseAttributeType.GROUP.equals(type) && !GoogleBaseAttributeType.GROUP.equals(type.getSupertype()) && (attr.hasValue() || attr.hasSubElements())) { attribute.addSubAttribute(attr); } } return attribute; }
/** * Creates a {@link GoogleBaseAttribute} of type * {@link GoogleBaseAttributeType#GROUP} and initializes it using the * current state of the object. Sub-attributes of group with type * GROUP or GROUP's derived types are ignored. * * @param name attribute name * @param group attribute value * @return a new {@link com.google.api.gbase.client.GoogleBaseAttribute} */ public static GoogleBaseAttribute createAttribute(String name, Group group) { GoogleBaseAttribute attribute = new GoogleBaseAttribute(name, GoogleBaseAttributeType.GROUP); Multimap<String, GoogleBaseAttribute> subAttributes = group.getAllSubAttributes(); for (GoogleBaseAttribute attr : subAttributes.values()) { GoogleBaseAttributeType type = attr.getType(); if (!GoogleBaseAttributeType.GROUP.equals(type) && !GoogleBaseAttributeType.GROUP.equals(type.getSupertype()) && (attr.hasValue() || attr.hasSubElements())) { attribute.addSubAttribute(attr); } } return attribute; }
/** * 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()); } }
/** * 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()); } }