/* IBM Confidential OCO Source Materials IBM Cognos Products: rs (C) Copyright IBM Corp. 2018 The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office. */ define([], function() { var U_Object = {}; /** * Determine if the object has any keys. * @param {Object} o An object. * @type Boolean * @returns True if the object is empty. */ U_Object.F_IsEmpty = function( o ) { for ( var s in o ) { return false; } return true; }; /** * Convert the object to an array of the values. * Each value becomes an item in the array. * @param {Object} o An object. * @type Array * @returns The array. */ U_Object.F_ToValueArray = Object.values ? function( o ) { return Object.values( o ); } : function( o ) { var a = []; for ( var s in o ) { a.push( o[s] ); } return a; }; /** * Count the number of keys in the object. * @param {Object} o An object. * @type Integer * @returns The number of keys in the object. */ U_Object.F_GetLength = function( o ) { var i = 0; for ( var s in o ) { i++; } return i; }; /** * Simple copy * @param {Object} o An Object to copy * @type {Object} * @returns The copy. */ U_Object.F_Copy = Object.assign ? function( o ) { return Object.assign( {}, o ); } : function( o ) { var v_oCopy = {}; for ( var s in o ) { v_oCopy[s] = o[s]; } return v_oCopy; }; U_Object.F_TypeOf = function( v ) { var s = typeof v; if ( s == "object" ) { if ( !v ) { return "null"; } if ( Array.isArray(v) ) { return "array"; } } return s; }; /** * Simple clone * @param {Object} o An Object to clone * @type {Object} * @returns The clone. */ U_Object.F_Clone = function( o ) { switch ( this.F_TypeOf( o ) ) { case "number": case "string": case "boolean": case "undefined": return o; case "object": var v_oClone = {}; for ( var s in o ) { if ( o.hasOwnProperty( s ) ) { v_oClone[s] = this.F_Clone( o[s] ); } } return v_oClone; case "array": var v_aClone = []; var v_iLength = o.length; for ( var i = 0; i < v_iLength; i++ ) { v_aClone[i] = this.F_Clone( o[i] ); } return v_aClone; case "function": // Not supported } }; /** * Subtract values (o1 - o2) * @param {Object} o1 An Object * @param {Object} o2 An Object to subtract * @type {Object} * @returns A new object without the subtracted values. */ U_Object.F_Subtract = function( o1, o2 ) { var v_oNew = this.F_Copy( o1 ); for ( var s in o2 ) { delete v_oNew[s]; } return v_oNew; }; U_Object.F_Compare = function( o1, o2 ) { if (this.F_GetLength(o1) != this.F_GetLength(o2)) { return false; } for (var v_sPropName in o1) { if (typeof o2[v_sPropName] === "undefined") { return false; } var v_oVal1 = o1[v_sPropName]; var v_oVal2 = o2[v_sPropName]; var v_bEqual = false; switch (typeof o1[v_sPropName]) { case "object": v_bEqual = this.F_Compare(v_oVal1, v_oVal2); break; case "function": v_bEqual = v_oVal1.toString() === v_oVal2.toString(); break; default: v_bEqual = v_oVal1 === v_oVal2; break; } if (!v_bEqual) { return false; } } return true; }; return U_Object; });