/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. */
  18. package com.brightcove.brightaction.utils {
  19. import com.adobe.serialization.json.JSON;
  20. import flash.utils.*;
  21. /**
  22. * A utility object for checking and comparing properties on objects
  23. *
  24. * @author amanning
  25. */
  26. public class ObjectChecker {
  27. /**
  28. * Return the properly on the object if it is defined, null otherwise
  29. *
  30. * @param object object that may contain property
  31. * @param property the property name
  32. * @return the value of the property if it exists, null otherwise
  33. */
  34. public static function ifDefined(object:Object, property:String):Object {
  35. if(object == null) { return null; }
  36. if(property == null || property.length < 1) { return null; }
  37. if(!object.hasOwnProperty(property)){ return null; }
  38. return object[property];
  39. }
  40. }
  41. }