Serialise attributes.
@param attributes the attributes
@return the resulting encoded attributes
160340
public static JSONObject toJSON(Attributes attributes) {
        JSONObject res = new JSONObject();
        JSONObject vms = new JSONObject();
        JSONObject nodes = new JSONObject();
        for (Element e : attributes.getDefined()) {
            JSONObject el = new JSONObject();
            for (String k : attributes.getKeys(e)) {
                el.put(k, attributes.get(e, k));
            }
            if (e instanceof VM) {
                vms.put(Integer.toString(e.id()), el);
            } else {
                nodes.put(Integer.toString(e.id()), el);
            }
        }
        res.put("vms", vms);
        res.put("nodes", nodes);
        return res;
    }
1166624
private Attributes toAttributes(Map<String,String> attrs){
        AttributesImpl impl = new AttributesImpl();
        for (Map.Entry<String,String> attr : attrs.entrySet()){
        	impl.addAttribute("", attr.getKey(), "", "CDATA", attr.getValue());
        }
        return impl;
    }
428833
protected function attributes($attributes)
    {
        if (!is_array($attributes)) {
            return $attributes;
        }

        $attr = '';
        foreach ($attributes as $attribute => $value) {
            if (is_int($attribute)) {
                $attribute = $value;
            }
            $attr .= ' ' . $attribute . '="' . $value . '"';
        }

        return $attr;
    }
791543
protected Map<String, List<Object>> buildImmutableAttributeMap(final Map<String, List<Object>> attributes) {
        final Map<String, List<Object>> immutableValuesBuilder = this.createImmutableAttributeMap(attributes.size());
        final Pattern arrayPattern = Pattern.compile("\\{(.*)\\}");
        for (final Map.Entry<String, List<Object>> attrEntry : attributes.entrySet()) {
            final String key = attrEntry.getKey();
            List<Object> value = attrEntry.getValue();

            if (value != null) {
                if (!value.isEmpty()) {
                    final Object result = value.get(0);
                    if (Array.class.isInstance(result)) {
                        if (logger.isTraceEnabled()) {
                            logger.trace("Column {} is classified as a SQL array", key);
                        }
                        final String values = result.toString();
                        if (logger.isTraceEnabled()) {
                            logger.trace("Converting SQL array values {} using pattern {}", values, arrayPattern.pattern());
                        }
                        final Matcher matcher = arrayPattern.matcher(values);
                        if (matcher.matches()) {
                            final String[] groups = matcher.group(1).split(",");
                            value = Arrays.asList(groups);
                            if (logger.isTraceEnabled()) {
                                logger.trace("Converted SQL array values {}", values);
                            }
                        }
                    }
                }
                value = Collections.unmodifiableList(value);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Collecting attribute {} with value(s) {}", key, value);
            }
            immutableValuesBuilder.put(key, value);
        }

        return immutableValuesBuilder;
    }
955081
public LDAPQuery setAttributes(List<String> attributes) {
		if(attributes != null && attributes.size() > 0) {
			this.attributes = new String[attributes.size()];
			int i = 0;
			for(String attribute : attributes) {
				this.attributes[i++] = attribute;
			}
		} else {
			this.attributes = ALL_ATTRIBUTES;
		}
		return this;
	}
486378
public static function attributes(array $attributes = array())
    {
        $text = array();
        foreach ($attributes as $key => $value) {
            //if we have numeric keys (e.g. checked), set the value as
            //the $key (e.g. checked="checked"), but only if it
            //doesn't exist already
            if (is_numeric($key)) {
                $value = htmlspecialchars($value);
                if (!isset($attributes[$value])) {
                    $text[] = $value . '="' . $value . '"';
                }
                continue;
            }
            $text[] = $key . '="' . htmlspecialchars($value) . '"';
        }

        return empty($text) ? '' : ' ' . implode(' ', $text);
    }
277233
public static function arrayToAttributes(array $attributes)
	{
		//Build a list of single attributes first
		$attributeList = array();

		foreach ( $attributes as $key => $value )
		{
			// If the value is not false add the attribute. This allows attributes to not be shown.
			if ( $value !== false )
			{
				if ( is_string($key) )
				{
					$attributeList[] = htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
				}
				else
				{
					$attributeList[] = $value;
				}
			}
		}

		return implode(' ', $attributeList);
	}
1233651
public void setAttributes(java.util.Collection<Value> attributes) {
        if (attributes == null) {
            this.attributes = null;
            return;
        }

        this.attributes = new java.util.ArrayList<Value>(attributes);
    }
897165
public function attributes(array $attributes)
    {
        foreach ($attributes as $attribute => &$data) {
            $data = implode(' ', (array) $data);
            $data = $attribute . '="' . htmlspecialchars($data, ENT_QUOTES, 'UTF-8') . '"';
        }

        return empty($attributes) ? '' : ' ' . implode(' ', $attributes);
    }
1034278
public OTAUpdateFile withAttributes(java.util.Map<String, String> attributes) {
        setAttributes(attributes);
        return this;
    }
812301
private function putAttributes($attributes)
	{
		$output = '';

		foreach($attributes as $attribute => $value)
		{
			$output.= ' '.$attribute. '="'.$value.'"';
		}

		return $output;
	}
529233
public void putAttributes(Attributes attributes){
        int attrCount = attributes.getLength();
        if(attrCount>0){
            temp();
            for(int i=0; i<attrCount; i++){
                QName qname = new QName(attributes.getURI(i), attributes.getLocalName(i));
                temp.put(qname, attributes.getValue(i));
            }
        }
    }
429928
public ThingGroupDocument withAttributes(java.util.Map<String, String> attributes) {
        setAttributes(attributes);
        return this;
    }
591057
public Scope setAttributes(Iterable<Pair> attributes)
    {
        if (attributes == null)
        {
            this.attributes = null;

            return this;
        }

        List<Pair> list = new ArrayList<Pair>();

        for (Pair attribute : attributes)
        {
            if (attribute == null || attribute.getKey() == null)
            {
                continue;
            }

            list.add(attribute);
        }

        int size = list.size();

        if (size == 0)
        {
            this.attributes = null;

            return this;
        }

        Pair[] array = new Pair[size];
        this.attributes = list.toArray(array);

        return this;
    }
795443
public void setAttributes( final Collection<String> attributes )
    {
        this.attributes = attributes == null ? null : Collections.unmodifiableSet( new HashSet<String>( attributes ) );
    }
511328
public final void setAttributes(final Map<String, Attribute> attributes) {
        for (Map.Entry<String, Attribute> entry: attributes.entrySet()) {
            Object attribute = entry.getValue();
            if (!(attribute instanceof Attribute)) {
                final String msg =
                        "Attribute: '" + entry.getKey() + "' is not an attribute. It is a: " + attribute;
                LOGGER.error("Error setting the Attributes: {}", msg);
                throw new IllegalArgumentException(msg);
            } else {
                ((Attribute) attribute).setConfigName(entry.getKey());
            }
        }
        this.attributes = attributes;
    }
843348
static JSONObject processAttributesForCovering(Map<String, Object> attributes) {
    HashMap<String, Object> attributeMap = new HashMap<String, Object>();
    if (attributes.containsKey(Conversation.NAME)) {
      attributeMap.put(Conversation.NAME,
              attributes.get(Conversation.NAME));
    }
    Map<String, Object> innerAttribute = new HashMap<String, Object>();
    for (Map.Entry<String, Object> entry : attributes.entrySet()) {
      String k = entry.getKey();
      if (!Arrays.asList(Conversation.CONVERSATION_COLUMNS).contains(k)) {
        innerAttribute.put(k, entry.getValue());
      }
    }
    if (!innerAttribute.isEmpty()) {
      attributeMap.put(Conversation.ATTRIBUTE, innerAttribute);
    }
    if (attributeMap.isEmpty()) {
      return null;
    }
    return new JSONObject(attributeMap);
  }