Esempio n. 1
0
  /**
   * determine type by first type attribute present in object, then add attribute according to
   * attribute order in template.
   */
  public RpslObjectBuilder addAttributeSorted(final RpslAttribute newAttribute) {
    final ObjectType objectType = getType();
    final ObjectTemplate objectTemplate = ObjectTemplate.getTemplate(objectType);
    final EnumSet<AttributeType> attributesAfter =
        getAttributeTypesAfter(objectTemplate, newAttribute.getType());

    for (int i = 0; i < attributes.size(); i++) {
      if (attributesAfter.contains(attributes.get(i).getType())) {
        attributes.add(i, newAttribute);
        return this;
      }
    }

    attributes.add(newAttribute);
    return this;
  }
Esempio n. 2
0
 /**
  * determine type by first type attribute present in object, then sort attributes according to
  * attribute order in template. This sort is guaranteed to be <i>stable</i>: equal elements will
  * not be reordered as a result of the sort.
  */
 public RpslObjectBuilder sort() {
   final ObjectType objectType = getType();
   Collections.sort(
       attributes, ObjectTemplate.getTemplate(objectType).getAttributeTypeComparator());
   return this;
 }