/** * Returns the {@link AttributeValueSet} corresponding to the provided <code>id</code> * or the default {@link AttributeValueSet} (possibly <code>null</code>) if no * {@link AttributeValueSet} corresponds to the <code>id</code>. * * @param id identifier of the {@link AttributeValueSet} to return * @param useDefault if <code>true</code>, the default {@link AttributeValueSet} will * be returned if the {@link AttributeValueSet} with the provided id does * not exist. * @return the {@link AttributeValueSet} corresponding to the provided <code>id</code> * or the default {@link AttributeValueSet} (possibly <code>null</code>) if no * {@link AttributeValueSet} corresponds to the <code>id</code>. */ public AttributeValueSet getAttributeValueSet(String id, boolean useDefault) { if (attributeValueSets.containsKey(id)) { return attributeValueSets.get(id); } else { return (useDefault ? getDefaultAttributeValueSet() : null); } }
/** * Adds an {@link AttributeValueSet} to this collection replacing its label and * description. This method may sometimes be useful because {@link AttributeValueSet}s * are immutable with respect to their label and description. * * @param id unique identifier of the {@link AttributeValueSet} within the collection. * @param attributeValueSet {@link AttributeValueSet} to be added * @param newLabel new label for the {@link AttributeValueSet} * @param newDescription new description for the {@link AttributeValueSet} */ public void addAttributeValueSet(String id, AttributeValueSet attributeValueSet, String newLabel, String newDescription) { final AttributeValueSet newAttributeValueSet = new AttributeValueSet(newLabel, newDescription, attributeValueSet.baseAttributeValueSet); newAttributeValueSet.overridenAttributeValues .putAll(attributeValueSet.overridenAttributeValues); addAttributeValueSet(id, newAttributeValueSet); }
/** * Returns the {@link AttributeValueSet} corresponding to the provided <code>id</code> * or <code>null</code> if no {@link AttributeValueSet} corresponds to the * <code>id</code>. * * @return the {@link AttributeValueSet} corresponding to the provided <code>id</code> * or <code>null</code> if no {@link AttributeValueSet} corresponds to the * <code>id</code>. */ public AttributeValueSet getAttributeValueSet(String id) { return getAttributeValueSet(id, false); }
AttributeValueSets avs = AttributeValueSets.deserialize(attributeXmls[0].open()); AttributeValueSet defaultSet = avs.getDefaultAttributeValueSet(); initAttributes.putAll(defaultSet.getAttributeValues()); } catch (Exception e) {
attributeSets = new AttributeValueSets(); try attributeSets = AttributeValueSets.deserialize(inputStream); attributeSets = new AttributeValueSets();
@Override public String toString() { return "AttributeValueSet [set IDs: " + Arrays.toString(this.getAttributeValueSetIds().toArray()) + "]"; } }
/** * Returns all {@link AttributeValueSet}s from this collection that are based, * directly or indirectly, on the provided <code>baseAttributeValueSet</code>. * * @param baseAttributeValueSet the base attribute value set */ public Set<AttributeValueSet> getAttributeValueSetsBasedOn( AttributeValueSet baseAttributeValueSet) { final Set<AttributeValueSet> result = Sets.newHashSet(); for (final AttributeValueSet set : attributeValueSets.values()) { if (set.baseAttributeValueSet == baseAttributeValueSet) { result.add(set); result.addAll(getAttributeValueSetsBasedOn(set)); } } return result; }
/** * Deserializes a collection of {@link AttributeValueSet}s from an XML stream. * * @param inputStream the {@link InputStream} to deserialize a * {@link AttributeValueSets} from. The stream will <strong>not</strong> be * closed. * @return Deserialized collection of {@link AttributeValueSet}s * @throws Exception is case of any problems with deserialization. */ public static AttributeValueSets deserialize(InputStream inputStream) throws Exception { final AttributeValueSets attributeValueSet = new Persister().read( AttributeValueSets.class, inputStream); checkDefaultAttributeValueSetExists(attributeValueSet); return attributeValueSet; }
final Map<String, Object> initAttributes = Maps.newHashMap(); final AttributeValueSet defaultAttributeValueSet = attributeSets .getDefaultAttributeValueSet(); if (defaultAttributeValueSet != null)
/** * Returns the default {@link AttributeValueSet} of this {@link AttributeValueSets} or * the first available {@link AttributeValueSet} if * {@link #getDefaultAttributeValueSetId()} is <code>null</code>. If this * {@link AttributeValueSets} is empty, <code>null</code> will be returned. */ public AttributeValueSet getDefaultAttributeValueSet() { AttributeValueSet result = null; if (defaultAttributeValueSetId != null) { result = getAttributeValueSet(defaultAttributeValueSetId); } // Try the first attribute set if (result == null) { final Iterator<AttributeValueSet> iterator = attributeValueSets.values() .iterator(); if (iterator.hasNext()) { result = iterator.next(); } } return result; }
private Map<String, Object> getAttributes() { Map<String, Object> result = AttributeValueSet .getAttributeValues(getAttributeSets().getAttributeValueSet(attributeSetId, true)); if (result == null) { result = Maps.newHashMap(); } return result; }