/**
   * Checks that all the attributes have a unique Name/NameFormat pair.
   *
   * @param query the attribute query to validate
   * @throws ValidationException thrown if more than on Name/NameFormat pair is found in the list of
   *     attributes in this query
   */
  protected void validateUniqueAttributeIdentifiers(AttributeQuery query)
      throws ValidationException {
    List<Attribute> attributes = query.getAttributes();

    HashSet<Pair<String, String>> encounteredNames = new HashSet<Pair<String, String>>();
    String attributeName;
    String attributeNameFormat;
    for (Attribute attribute : attributes) {
      attributeName = attribute.getName();
      attributeNameFormat = attribute.getNameFormat();
      if (DatatypeHelper.isEmpty(attributeNameFormat)) {
        // SAML 2 core, sec. 2.7.3.1, if no format is specified,
        // unspecified is in effect. This avoids bug in processing null value.
        attributeNameFormat = Attribute.UNSPECIFIED;
      }

      Pair<String, String> pair = new Pair<String, String>(attributeName, attributeNameFormat);
      if (encounteredNames.contains(pair)) {
        throw new ValidationException(
            "Attribute query contains more than one attribute with the same Name and NameFormat");
      } else {
        encounteredNames.add(pair);
      }
    }
  }