PageRenderTime 10ms CodeModel.GetById 7ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/brightaction/src/com/brightcove/brightaction/utils/ObjectChecker.as

http://github.com/BrightcoveOS/BrightAction
ActionScript | 50 lines | 12 code | 9 blank | 29 comment | 6 complexity | 59eb1db4aaa92cba24005f5de580bedb MD5 | raw file
 1/**
 2 * GNU General Public License v3
 3 *
 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
 5 * of this software and associated documentation files (the "Software"), to deal
 6 * in the Software without restriction, including without limitation the rights
 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 8 * copies of the Software, and to permit persons to whom the Software is
 9 * furnished to do so, subject to the following conditions:
10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16 * THE SOFTWARE.
17 */
18package com.brightcove.brightaction.utils {
19    
20    import com.adobe.serialization.json.JSON;
21    
22    import flash.utils.*;
23    
24    /**
25     * A utility object for checking and comparing properties on objects
26     *
27     * @author amanning
28     */
29    public class ObjectChecker {
30
31        /**
32         * Return the properly on the object if it is defined, null otherwise
33         * 
34         * @param object    object that may contain property
35         * @param property  the property name
36         * @return          the value of the property if it exists, null otherwise
37         */
38        public static function ifDefined(object:Object, property:String):Object {
39            
40            if(object == null) { return null; }
41            if(property == null || property.length < 1) { return null; }
42            if(!object.hasOwnProperty(property)){ return null; }
43            
44            return object[property];
45            
46        }
47
48    }
49
50}