Coverage Report - com.sun.javafx.runtime.Checks
 
Classes in this File Line Coverage Branch Coverage Complexity
Checks
42%
13/31
30%
16/54
3.75
 
 1  
 /*
 2  
  * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package com.sun.javafx.runtime;
 27  
 
 28  
 import com.sun.javafx.runtime.sequence.Sequence;
 29  
 import com.sun.javafx.runtime.sequence.Sequences;
 30  
 
 31  
 /**
 32  
  * Various runtime checks too messy to do inline
 33  
  * @author Robert Field
 34  
  */
 35  0
 public class Checks {
 36  
     
 37  
     /**
 38  
      * Do an equals() compare that is safe 
 39  
      * @param a
 40  
      * @param b
 41  
      * @return true if they are equal
 42  
      */
 43  
     public static boolean equals(Object a, Object b) {
 44  56
         if (a == null) {
 45  1
             return b == null;
 46  
         } else {
 47  55
             return a.equals(b);
 48  
         }
 49  
     }
 50  
 
 51  
     /**
 52  
      * Do an equals() compare on sequences that is safe 
 53  
      * @param a
 54  
      * @param b
 55  
      * @return true if they are equal
 56  
      */
 57  
     public static boolean equals(Sequence a, Sequence b) {
 58  1184
         return Sequences.isEqual(a, b);
 59  
     }
 60  
 
 61  
     /**
 62  
      * Do an equals() compare on Strings that is safe 
 63  
      * @param a
 64  
      * @param b
 65  
      * @return true if they are equal
 66  
      */
 67  
     public static boolean equals(String a, String b) {
 68  87
         if (a == null) {
 69  0
             return b == null || b.length() == 0;
 70  87
         } else if (b == null) {
 71  0
             return a.length() == 0;
 72  
         } else {
 73  87
             return a.equals(b);
 74  
         }
 75  
     }
 76  
 
 77  
     /**
 78  
      * Compare an Object with an int
 79  
      * @param a Object
 80  
      * @param b int
 81  
      * @return true if they are equal
 82  
      */
 83  
     public static boolean equals(Object obj, int i) {
 84  2
         if (obj == null) {
 85  2
             return i == 0;  // compare to default value
 86  0
         } else if (obj instanceof Integer) {
 87  0
             return ((Integer)obj).intValue() == i;
 88  0
         } else if (obj instanceof Double) {
 89  0
             return ((Double)obj).doubleValue() == i;
 90  
         } else {
 91  0
             return false;
 92  
         }
 93  
     }
 94  
 
 95  
     /**
 96  
      * Compare an Object with a double
 97  
      * @param a Object
 98  
      * @param b double
 99  
      * @return true if they are equal
 100  
      */
 101  
     public static boolean equals(Object obj, double x) {
 102  2
         if (obj == null) {
 103  2
             return x == 0.0;  // compare to default value
 104  0
         } else if (obj instanceof Integer) {
 105  0
             return ((Integer)obj).intValue() == x;
 106  0
         } else if (obj instanceof Double) {
 107  0
             return ((Double)obj).doubleValue() == x;
 108  
         } else {
 109  0
             return false;
 110  
         }
 111  
     }
 112  
 
 113  
     /**
 114  
      * Compare an Object with an int
 115  
      * @param a Object
 116  
      * @param b int
 117  
      * @return true if they are equal
 118  
      */
 119  
     public static boolean equals(Object obj, boolean bool) {
 120  0
         if (obj == null) {
 121  0
             return bool == false;  // compare to default value
 122  0
         } else if (obj instanceof Boolean) {
 123  0
             return ((Boolean)obj).booleanValue() == bool;
 124  
         } else {
 125  0
             return false;
 126  
         }
 127  
     }
 128  
 
 129  
     /**
 130  
      * Check if the sequence parameter is null, or equivalent to null
 131  
      * @param a Sequence
 132  
      * @return true if a is null or null equivalent
 133  
      */
 134  
     public static boolean isNull(Sequence a) {
 135  137
         return (a == null) ||  a.size() == 0;
 136  
     }
 137  
 
 138  
     /**
 139  
      * Check if the String parameter is null, or equivalent to null
 140  
      * @param a String
 141  
      * @return true if a is null or null equivalent
 142  
      */
 143  
     public static boolean isNull(String a) {
 144  451
         return (a == null) ||  a.length() == 0;
 145  
     }
 146  
 }