/*
Define a field or a map of field
@key : attribute key
@value : value
163647
function(key, value, options) {
            var attrs, subattrs, scope, changes, newattributes, diffs;

            // Handle both `"key", value` and `{key: value}` -style arguments.
            if (typeof key === 'object') {
                attrs = key;
                options = value;
            } else {
                attrs = {};
                scope = key.split(".");
                subattrs = attrs;
                for (var i in scope) {
                    var key = scope[i];
                    if (i == (scope.length - 1)) {
                        subattrs[key] = value;
                    } else {
                        subattrs[key] = {};
                        subattrs = subattrs[key];
                    }
                }
            }

            // Define options
            options = _.defaults(options || {}, {
                silent: false
            });

            // Calcul new attributes
            newattributes = _.deepExtend({}, this.attributes || {}, attrs);
            if (!options.silent) {
                diffs = jsondiffpatch.diff(this._prevAttributes || {}, newattributes);
            }
            this.attributes = newattributes;
            this._prevAttributes = _.deepClone(this.attributes);

            // New unique id
            var oldId = this.id;
            if (this.idAttribute in this.attributes) {
                this.id = this.attributes[this.idAttribute];
            } else {
                this.id = this.cid;
            }
            if (oldId != this.id) this.trigger("id", this.id, oldId);

            // Calcul diffs
            if (!options.silent) {
                diffs = _.diffkeys(diffs);
                _.each(diffs, function(tag) {
                    this.trigger("change:"+tag, tag);
                }, this);
                if (diffs.length > 0) this.trigger("set", diffs);
            }

            return this;
        }
279440
function attr(key, val) {
  var i, attrs, map = {};
  if(!this.length || key !== undefined && !Boolean(key)) {
    return this;
  }

  if(key === undefined && val === undefined) {
    // no args, get all attributes for first element as object
    attrs = this.dom[0].attributes;
    // convert NamedNodeMap to plain object
    for(i = 0;i < attrs.length;i++) {
      // NOTE: nodeValue is deprecated, check support for `value` in IE9!
      map[attrs[i].name] = attrs[i].value;
    }
    return map;
  }else if(typeof key === 'string' && !val) {
    // delete attribute on all matched elements
    if(val === null) {
      this.each(function(el) {
        el.removeAttribute(key);
      })
      return this;
    }
    // get attribute for first matched elements
    return this.dom[0].getAttribute(key);
  // handle object map of attributes
  }else {
    this.each(function(el) {
      if(typeof key === 'object') {
        for(var z in key) {
          if(key[z] === null) {
            el.removeAttribute(z);
            continue;
          }
          el.setAttribute(z, key[z]);
        }
      }else{
        el.setAttribute(key, val);
      }
    });
  }
  return this;
}
723559
function (field) {
            var schemaDefinition = this.schema[field];
            if (!schemaDefinition) {
                throw "Couldn't find '" + field + "' in schema";
            }
            var collection = this.get(field);
            if (!collection) {
                var context = this.getContextForChild(schemaDefinition.type);
                if (context) {
                    collection = context.createCollection(schemaDefinition.type, null);
                    collection.$parent = this;
                    this.set(field, collection);
                } else {
                    throw "Couldn't determine context for " + field;
                }
            }
            return collection;


        }
427208
function _objectByAttribute(obj, attr, map, action) {
    var subAttrs = attr.split(".");
    var attrValue = obj;
    for (var i = 0; i < subAttrs.length; i++) {
      attrValue = attrValue[subAttrs[i]];
      if (attrValue === undefined) {
        return;
      }
    }

    if ($.isArray(attrValue)) {
      // TODO implement this when we actually need it
    }
    else if ($.isPlainObject(attrValue)) {
      for (var key in attrValue) {
        var val = attrValue[key];
        if (!map[key]) {
          map[key] = {};
        }
        if (action === "DELETED") {
          delete map[key][val];
        }
        else {
          map[key][val] = obj;
        }
      }
    }
    else {
      if (action === "DELETED") {
        delete map[attrValue];
      }
      else {
        map[attrValue] = obj;
      }
    }
  }
293925
@SuppressWarnings({"unchecked", "rawtypes"})
    public void addField(String key, Object value)
    {
        if (this.body == null || Map.class.isAssignableFrom(this.body.getClass()) == false)
        {
            this.body = Maps.newLinkedHashMap();
        }

        ((Map) this.body).put(key, value);
    }
635604
public void setAttribute(Object key, Object value) {
		if (attributes == null) {
			attributes = new HashMap(5);
		}
		attributes.put(key, value);
	}
614212
public Index mapper(String field, Mapper mapper) {
        schema.mapper(field, mapper);
        return this;
    }
1208531
public static SObject of(String key, File file, Map<String, String> attributes) {
        SObject sobj = of(key, $.requireNotNull(file));
        sobj.setAttributes(attributes);
        return sobj;
    }
1171600
function Property( field, value, params ) {

  if( !(this instanceof Property) )
    return new Property( value )

  if( params != null )
    Object.assign( this, params )

  this._field = field
  this._data = value

  Object.defineProperty( this, '_field', { enumerable: false })
  Object.defineProperty( this, '_data', { enumerable: false })

}
1241734
@Override
  public <VALUEBASE, VALUE extends VALUEBASE, KEY extends Key<CoreMap, VALUEBASE>>
    VALUE set(Class<KEY> key, VALUE value) {
    
    if (immutableKeys.contains(key)) {
      throw new HashableCoreMapException("Attempt to change value " +
      		"of immutable field "+key.getSimpleName());
    }
    
    return super.set(key, value);
  }
1050885
public void setAttribute(String key, String value) {
/*		if (!attributes.containsKey(key))
		{
			sortedAttributes.add(key);
		}*/
		if (nodeAttributes == null) {
			nodeAttributes = new Properties();
		}
		nodeAttributes.setProperty(key, value);
	}
781192
function (attributes) {
            var self = this;
            var retVal = {};
            var ctxMappings = {};
             _.each(attributes, function (attribute, k) {
                var isCtxMapping = _.isString(attribute) && !attribute.indexOf('$');
                if (isCtxMapping) {
                    ctxMappings[k] = attribute;
                } else {
                    retVal[k] = attribute;
                }

                return isCtxMapping;
            });

            _.each(ctxMappings, function (val, k) {
                self._resolveCtxVal(retVal, val, k);
            });

            return retVal;
        }
293797
def field_or_param(key)

      key = key.to_s

      h.fields[key] || (h.fields['params'] || {})[key]
    end
628729
private void setAttribute(String key, String value, boolean allowEmptyValue) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value) || (allowEmptyValue && (value != null))) {
            if (m_attributes == null) {
                m_attributes = new HashMap<String, String>();
            }
            m_attributes.put(key, value);
        }
    }
398109
function hsetnx(key, field, value, req) {
  var val = this.getKey(key, req)
    , exists = this.hexists(key, field, req);
  if(!val) {
    val = new HashMap();
    this.setKey(key, val, undefined, undefined, undefined, req);
  }
  if(!exists) {
    // set on the hashmap
    val.setKey(field, value);
  }
  return exists ? 0 : 1;
}
746012
function getField(field) {
  return function map(element) {
    if (element) {
      if (Array.isArray(element)) {
        return element.map(map).join('');
      }
      else if (typeof element === 'string') {
        return element;
      }
      else if (typeof element === 'object') {
        return element[field];
      }
    }
    return '';
  };
}
1334738
function(attr) {
                    var value;
                    // Handles the case of a key having a `.` in its name
                    if (typeof attr === 'string' && !! ~attr.indexOf('.')) {
                        // Attempt to get the value
                        value = this.__get(attr);
                        // For keys with a `.` in them, value will be defined
                        if (value !== undefined) {
                            return value;
                        }
                    }

                    // Otherwise we have to dig deeper into the Map to get the value.
                    // First, break up the attr (`"foo.bar"`) into parts like `["foo","bar"]`.
                    var parts = can.Map.helpers.attrParts(attr),
                        // Then get the value of the first attr name (`"foo"`).
                        current = this.__get(parts.shift());
                    // If there are other attributes to read...
                    return parts.length ?
                    // and current has a value...
                    current ?
                    // then lookup the remaining attrs on current
                    current._get(parts) :
                    // or if there's no current, return undefined.
                    undefined :
                    // If there are no more parts, return current.
                    current;
                }