/*
Clones variables to avoid pass by reference issues

@param {any} orig
@param {optional|string} dataType
@returns {clone.newArray|Array|clone.orig}
160147
function clone(orig, dataType){
	if(!dataType)
		dataType = getDataType(orig);

	if(dataType == 'Array'){
		var newArray = [];
		for(var i = 0; i < orig.length; i++)
			newArray.push(orig[i]);

		return newArray;

	} else if(dataType == 'Object') {
		var newObject = {};
		for(var key in orig)
			newObject[key] = clone(orig[key]);

		return newObject;

	} else
		return orig;
}
1310730
public void copyStructure( DMatrixSparseCSC orig ) {
        reshape(orig.numRows, orig.numCols, orig.nz_length);
        this.nz_length = orig.nz_length;
        System.arraycopy(orig.col_idx,0,col_idx,0,orig.numCols+1);
        System.arraycopy(orig.nz_rows,0,nz_rows,0,orig.nz_length);
    }
320772
function() {
    var options, name, src, copy, copyIsArray, clone,
      target = arguments[0] || {},
      i = 1,
      length = arguments.length,
      deep = false;

    // Handle a deep copy situation
    if ( typeof target === 'boolean' ) {
      deep = target;
      target = arguments[1] || {};
      // skip the boolean and the target
      i = 2;
    }

    // Handle case when target is a string or something (possible in deep copy)
    if ( typeof target !== 'object' && !is.fn(target) ) {
      target = {};
    }

    // extend jQuery itself if only one argument is passed
    if ( length === i ) {
      target = this;
      --i;
    }

    for ( ; i < length; i++ ) {
      // Only deal with non-null/undefined values
      if ( (options = arguments[ i ]) != null ) {
        // Extend the base object
        for ( name in options ) {
          src = target[ name ];
          copy = options[ name ];

          // Prevent never-ending loop
          if ( target === copy ) {
            continue;
          }

          // Recurse if we're merging plain objects or arrays
          if ( deep && copy && ( is.plainObject(copy) || (copyIsArray = is.array(copy)) ) ) {
            if ( copyIsArray ) {
              copyIsArray = false;
              clone = src && is.array(src) ? src : [];

            } else {
              clone = src && is.plainObject(src) ? src : {};
            }

            // Never move original objects, clone them
            target[ name ] = util.extend( deep, clone, copy );

          // Don't bring in undefined values
          } else if ( copy !== undefined ) {
            target[ name ] = copy;
          }
        }
      }
    }

    // Return the modified object
    return target;
  }
365849
public static Map<String, IDLProxyObject> create(String data, boolean debug, boolean isUniName) {
        return create(data, debug, null, isUniName);
    }
835550
function (typeName, _noCast) {
        !_.isNil(typeName) && (typeName = typeName.toString().toLowerCase()); // sanitize
        if (!Variable.types[typeName]) {
            return this.type || ANY; // @todo: throw new Error('Invalid variable type.');
        }

        // set type if it is valid
        this.type = typeName;

        // 1. get the current value
        // 2. set the new type if it is valid and cast the stored value
        // 3. then set the interstitial value
        var interstitialCastValue;

        // do not touch value functions
        if (!(_noCast || _.isFunction(this.value))) {
            interstitialCastValue = this.get();
            this.set(interstitialCastValue);
            interstitialCastValue = null; // just a precaution
        }

        return this.type;
    }
772810
function(type, data) {
            var handlers,
                i,
                len,
                event = buildEventObject(type, data);

            // if there are handlers for the event, call them in order
            handlers = this._handlers[event.type];
            if (handlers instanceof Array) {
                // @NOTE: do a concat() here to create a copy of the handlers array,
                // so that if another handler is removed of the same type, it doesn't
                // interfere with the handlers array
                handlers = handlers.concat();
                for (i = 0, len = handlers.length; i < len; i++) {
                    if (handlers[i]) {
                        handlers[i].call(this, event);
                    }
                }
            }

            // call handlers for `all` event type
            handlers = this._handlers.all;
            if (handlers instanceof Array) {
                // @NOTE: do a concat() here to create a copy of the handlers array,
                // so that if another handler is removed of the same type, it doesn't
                // interfere with the handlers array
                handlers = handlers.concat();
                for (i = 0, len = handlers.length; i < len; i++) {
                    if (handlers[i]) {
                        handlers[i].call(this, event);
                    }
                }
            }

            return event;
        }
791505
private static boolean isOriginalTsType(TsType type) {
        if (type instanceof TsType.BasicType) {
            TsType.BasicType basicType = (TsType.BasicType)type;
            return !(basicType.name.equals("null") || basicType.name.equals("undefined"));
        }
        return true;
    }
1149632
public static IDLProxyObject createSingle(String data, boolean debug) {
        return createSingle(data, debug, null, true);
    }
1085670
public static function parseLabels(&$data, $orig = null)
    {
        $str = '';
        while (mb_orig_strlen($data) > 0) {
            $l = ord($data[0]);

            if ($l >= 192) {
                $pos = Binary::bytes2int(chr($l - 192) . mb_orig_substr($data, 1, 1));
                $data = mb_orig_substr($data, 2);
                $ref = mb_orig_substr($orig, $pos);
                return $str . Binary::parseLabels($ref, $orig);
            }

            $p = mb_orig_substr($data, 1, $l);
            $str .= $p . (($l !== 0) ? '.' : '');
            $data = mb_orig_substr($data, $l + 1);
            if ($l === 0) {
                break;
            }
        }
        return $str;
    }
1021991
@SuppressWarnings({"SuspiciousSystemArraycopy"})
	@Override
	public void setTo(T orig) {
		if (orig.width != width || orig.height != height || orig.numBands != numBands )
			reshape(orig.width,orig.height,orig.numBands);

		if (!orig.isSubimage() && !isSubimage()) {
			System.arraycopy(orig._getData(), orig.startIndex, _getData(), startIndex, stride * height);
		} else {
			int indexSrc = orig.startIndex;
			int indexDst = startIndex;
			for (int y = 0; y < height; y++) {
				System.arraycopy(orig._getData(), indexSrc, _getData(), indexDst, width * numBands);
				indexSrc += orig.stride;
				indexDst += stride;
			}
		}
	}
20074
function cloneDataView$1(dataView, isDeep) {
  var buffer = isDeep ? cloneArrayBuffer$2(dataView.buffer) : dataView.buffer;
  return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
}
373191
function clone(obj) {
  if (Array.isArray(obj)) {
    return obj.map((val) => clone(val))
  }
  if (isPlainObj(obj)) {
    return Object.keys(obj).reduce((copy, key) => {
      copy[key] = clone(obj[key])
      return copy
    }, {})
  }
  return obj
}
276786
function cloneDataView(dataView, isDeep) {
  var buffer = isDeep ? _cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
}
1374294
function polymorphic() {
	var registry = [];

	/**
	 *  Determine if somewhere in the prototype chains the variable extends an Object with given name
	 *  @name    isExtendOf
	 *  @access  internal
	 *  @param   string  name
	 *  @param   object  variable
	 *  @return  bool    extends
	 */
	function isExtendOf(name, variable) {
		var offset = typeof variable === 'object' && variable ? Object.getPrototypeOf(variable) : null,
			pattern = offset ? new RegExp('^' + name + '$') : null;

		//  It is not quite feasible to compare the inheritance using `instanceof` (all constructors would have to
		//  be registered somehow then) we simply compare the constructor function names.
		//  As a side effect, this enables polymorphic to compare against the exact type (unless a developer has
		//  altered the constructor name, which is not protected from overwriting)
		while (offset && offset.constructor) {
			if (pattern.test(offset.constructor.name)) {
				return true;
			}

			offset = Object.getPrototypeOf(offset);
		}

		return false;
	}

	/**
	 *  Map the param property of given candidate to contain only the values and resolve any references to other arguments
	 *  @name    parameterize
	 *  @access  internal
	 *  @param   Object candidate
	 *  @return  Object candidate (with resolved params)
	 */
	function parameterize(candidate) {
		candidate.param = candidate.param.map(function(param) {
			var value;

			if ('value' in param) {
				value = param.value;
			}
			else if ('reference' in param) {
				value = candidate.param.reduce(function(p, c) {
					return c !== param && !p && param.reference === c.name && 'value' in c ? c.value : p;
				}, null);
			}

			return value;
		});

		return candidate;
	}

	/**
	 *  Filter given list so only matching signatures are kept
	 *  @name    matchSignature
	 *  @access  internal
	 *  @param   array  candidates
	 *  @param   array  arguments
	 *  @return  array  filtered candidates
	 */
	function matchSignature(list, arg) {
		var types = arg.map(function(variable) {
				return new RegExp('^(' + type(variable) + ')');
			});

		return list.filter(function(config) {
			var variadic = false,
				result;

			//  result is true if no more arguments are provided than the signature allows OR the last
			//  argument in the signature is variadic
			result = arg.length <= config.arguments.length || (config.arguments[config.arguments.length - 1] && config.arguments[config.arguments.length - 1].type === '...');

			//  test each given argument agains the configured signatures
			if (result) {
				arg.forEach(function(value, index) {
					var expect = config.arguments[index] ? config.arguments[index].type : null;

					//  look at ourself and ahead - if there is a following item, and it is variadic, it may be
					//  left out entirely (zero or more)
					if (isTypeAtIndex('...', config.arguments, index)) {
						variadic = true;
					}

					//  the result remains valid as long as the values match the given signature
					//  (type matches or it is variadic)
					result = result && (variadic || types[index].test(expect) || (expect[expect.length - 1] !== '!' && isExtendOf(expect, value)));
				});
			}

			return result;
		});
	}

	/**
	 *  Map the registered values to a new object containing the specifics we use to determine the best
	 *  @name    prepare
	 *  @access  internal
	 *  @param   array  candidates
	 *  @param   array  arguments
	 *  @return  array  mapped candidates
	 */
	function prepare(list, arg) {
		return list.map(function(config) {
			var item = {
					//  the function to call
					call: config.call,

					//  all configured arguments
					arguments: config.arguments,

					//  the calculated specificity
					specificity: config.arguments.map(function(argument, index) {
						var value = 'value' in argument,
							specificity = 0;

						//  if a argument not a variadic one and the value is specified
						if (argument.type !== '...' && index < arg.length) {
							++specificity;

							//  bonus points if the exact type matches (explicit by type)
							//  OR there is no default value (explicitly provided)
							if (Number(argument.type === type(arg[index], true) || isExtendOf(argument.type, arg[index]) || !value)) {
								++specificity;
							}

							//  extra bonus points if the type is explicity the same (in case of inheritance)
							if (new RegExp('^' + type(arg[index], true) + '!$').test(argument.type)){ 
								++specificity;
							}
						}

						return specificity;
					}).join(''),

					//  the parameters with which the `call` may be executed
					param: config.arguments.map(function(argument, index) {
						var result = {};

						result.name = argument.name;

						//  if a variadic type is encountered, the remainder of the given arguments becomes the value
						if (argument.type === '...') {
							result.value = arg.slice(index);
						}
						else if (index < arg.length && typeof arg[index] !== 'undefined' && arg[index] !== null) {
							result.value = arg[index];
						}
						else if ('value' in argument) {
							result.value = argument.value;
						}
						else if ('reference' in argument) {
							result.reference = argument.reference;
						}

						return result;
					})
				};

			return item;
		});
	}

	/**
	 *  Prioritize the items in the list
	 *  @name    prepare
	 *  @access  internal
	 *  @param   array  candidates
	 *  @param   array  arguments
	 *  @return  array  prioritized candidates
	 *  @note    the list should contain pre-mapped items (as it works on specificity mostly)
	 */
	function prioritize(list, arg) {
		return list.sort(function(a, b) {
			var typing = function(item, index) {
					return +(item.type === type(arg[index], true));
				};

			//  if the calculated specificity is not equal it has precedence
			if (a.specificity !== b.specificity) {
				//  the shortest specificity OR ELSE the highest specificity wins
				return a.specificity.length - b.specificity.length || b.specificity - a.specificity;
			}

			//  if the specificity is equal, we want to prioritize on the more explicit types
			return b.arguments.map(typing).join('') - a.arguments.map(typing).join('');
		});
	}

	/**
	 *  Compare the type of the argument at a specific position within a collection
	 *  @name    isTypeAtIndex
	 *  @access  internal
	 *  @param   string type
	 *  @param   array  arguments
	 *  @param   int    index
	 *  @return  boolean type at index
	 */
	function isTypeAtIndex(type, list, index) {
		return list.length > index && 'type' in list[index] ? list[index].type === type : false;
	}

	/**
	 *  Determine the proper delegate handler for given arguments
	 *  @name    delegate
	 *  @access  internal
	 *  @param   array  arguments
	 *  @return  mixed  handler result
	 */
	function delegate(arg) {
		//  create a list of possible candidates based on the given arguments
		var candidate = matchSignature(registry, arg);

		//  prepare the configured signatures/arguments based on the arguments actually recieved
		candidate = prepare(candidate, arg);

		//  prioritize the candidates
		candidate = prioritize(candidate, arg);

		//  and finally, filter any candidate which does not fully comply with the signature based on the - now - parameters
		candidate = candidate.filter(function(item) {
			var variadic = false,
				min = item.arguments.map(function(argument, index) {
					variadic = isTypeAtIndex('...', item.arguments, index) || isTypeAtIndex('...', item.arguments, index + 1);

					return +(!(variadic || 'value'  in argument || 'reference' in argument));
				}).join('').match(/^1+/);

			return arg.length >= (min ? min[0].length : 0);
		});

		return candidate.length ? parameterize(candidate[0]) : false;
	}

	/**
	 *  Cast variable to given type
	 *  @name    cast
	 *  @access  internal
	 *  @param   string type
	 *  @param   string value
	 *  @return  mixed  value
	 */
	function cast(type, variable) {
		var result = variable;

		switch (type) {
			case 'number':
				result = +result;
				break;

			case 'int':
				result = parseInt(result, 10);
				break;

			case 'float':
				result = parseFloat(result);
				break;

			case 'bool':
			case 'boolean':
				result = ['true', '1', 1].indexOf(result) >= 0;
				break;
		}

		return result;
	}

	/**
	 *  Create a string matching various number types depending on given variable
	 *  @name    numberType
	 *  @access  internal
	 *  @param   string  type
	 *  @param   number  variable
	 *  @param   bool    explicit typing
	 *  @return  string  types
	 */
	function numberType(type, variable, explicit) {
		//  if the integer value is identical to the float value, it is an integer
		return (parseInt(variable, 10) === parseFloat(variable) ? 'int' : 'float') + (explicit ? '' : '|' + type);
	}

	/**
	 *  Create a string matching various object types (object constructor name if explicit)
	 *  @name    objectType
	 *  @access  internal
	 *  @param   string  type
	 *  @param   object  variable
	 *  @param   bool    explicit typing
	 *  @return  string  types
	 */
	function objectType(type, variable, explicit) {
		//  array get some special treatment by indicating it is not an object but instead an array
		//  this also goes for inherited types
		if (variable instanceof Array) {
			type = 'array';
		}

		return variable ? variable.constructor.name + (explicit ? '' : '|' + type) : 'null';
	}

	/**
	 *  Create a string matching 'boolean' type and - if not explicit - its shorthand version 'bool'
	 *  @name    booleanType
	 *  @access  internal
	 *  @param   string  type
	 *  @param   bool    explicit typing
	 *  @return  string  types
	 */
	function booleanType(type, explicit) {
		return type + (explicit ? '' : '|bool');
	}

	/**
	 *  Create a string matching undefined (and any string having one or more alphatical characters if not explicit)
	 *  @name    undefinedType
	 *  @access  internal
	 *  @param   string     type
	 *  @param   bool       explicit typing
	 *  @return  string  types
	 */
	function undefinedType(type, explicit) {
		return type + (explicit ? '' : '|[a-z]+');
	}

	/**
	 *  Determine the type and create a string ready for use in regular expressions
	 *  @name    type
	 *  @access  internal
	 *  @param   mixed   variable
	 *  @param   bool    explicit
	 *  @return  string  type
	 */
	function type(variable, explicit) {
		var result = typeof variable;

		switch (result) {
			case 'number':
				result = numberType(result, variable, explicit);
				break;

			case 'object':
				result = objectType(result, variable, explicit);
				break;

			case 'boolean':
				result = booleanType(result, explicit);
				break;

			case 'undefined':
				result = undefinedType(result, explicit);
				break;
		}

		return result;
	}

	/**
	 *  Process the expression match result and prepare the argument object
	 *  @name    prepareArgument
	 *  @access  internal
	 *  @param   RegExpMatch match
	 *  @param   string defaultname
	 *  @result  Object argument
	 */
	function prepareArgument(match, name) {
		var result = {
				type:  match ? match[1] : false,
				name:  match ? match[2] : name
			};

		if (match) {
			if (match[4] === '@') {
				result.reference = match[5];
			}
			else if (match[3] === '=') {
				result.value = cast(result.type, match[5]);
			}
		}

		return result;
	}

	/**
	 *  Parse given signature string and create an array containing all argument options for the signature
	 *  @name    parse
	 *  @access  internal
	 *  @param   string  signature
	 *  @return  array   options
	 */
	function parse(signature) {
		var pattern = /^(?:void|([a-zA-Z]+!?|\.{3})(?:[:\s]+([a-zA-Z]+)(?:(=)(@)?(.*))?)?)?$/;

		return signature.split(/\s*,\s*/).map(function(argument, index, all) {
			var result = prepareArgument(argument.match(pattern), 'var' + (index + 1));

			if (result.type === false) {
				throw new Error('polymorphic: invalid argument "' + argument + '" in signature "' + signature + '"');
			}
			else if (result.type === '...' && index < all.length - 1) {
				throw new Error('polymorphic: variadic argument must be at end of signature "' + signature + '"');
			}

			return result;
		}).filter(function(argument) {
			//  a type is undefined if it was declared as 'void' or '' (an empty string)
			return argument.type !== undefined;
		});
	}

	/**
	 *  The main result function, this is the function actually being returned by `polymorphic`
	 *  @name    result
	 *  @access  internal
	 *  @param   * [one or more arguments]
	 *  @return  mixed  handler result
	 *  @throws  polymorph: signature not found "<resolved pattern>"
	 */
	function polymorph() {
		var arg = Array.prototype.slice.call(arguments),
			candidate = delegate(arg);

		if (!candidate) {
			throw new Error('polymorph: signature not found "' + arg.map(function(variable) {
				return type(variable);
			}).join(', ') + '"');
		}

		return candidate.call.apply(this, candidate.param);
	}

	/**
	 *  Add one or more signatures and a handler for those signatures
	 *  @name    signature
	 *  @access  public
	 *  @param   string signature1
	 *  @param   string signatureN [optional - any number of signature can be provided for a handler]
	 *  @param   function handler
	 *  @return  void
	 *  @throws  polymorphic.signature: expected one or more signatures
	 *           polymorphic.signature: expected final argument to be a callback
	 */
	polymorph.signature = function() {
		var arg = Array.prototype.slice.call(arguments),
			call = arg.length && typeof arg[arg.length - 1] === 'function' ? arg.pop() : null;

		if (!arg.length) {
			throw new Error('polymorphic.signature: expected one or more signatures');
		}
		else if (!call) {
			throw new Error('polymorphic.signature: expected final argument to be a callback');
		}

		arg.forEach(function(signature) {
			registry.push({
				signature: signature,
				arguments: parse(signature),
				call: call
			});
		});
	};

	return polymorph;
}
312496
function clone() {
    var cloned = new this.constructor(this.client);
    cloned._method = this._method;
    cloned._single = assign({}, this._single);
    cloned._options = assign({}, this._options);
    cloned._statements = this._statements.slice();
    return cloned;
  }
737238
function cloneTypedArray(typedArray, isDeep) {
  var buffer = isDeep ? _cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
}
378933
protected Term convert(Term orig) {
        Term t = new Term(orig.getFunctionEnum());
        for (BELObject o : orig.getFunctionArguments()) {
            t.addFunctionArgument(convert(o));
        }
        return t;
    }