1 22 package org.jboss.util; 23 24 30 public final class Primitives 31 { 32 38 public static Boolean valueOf(boolean value) 39 { 40 if (value) 41 return Boolean.TRUE; 42 else 43 return Boolean.FALSE; 44 } 45 46 54 public static boolean equals(final double a, final double b) { 55 return Double.doubleToLongBits(a) == Double.doubleToLongBits(b); 56 } 57 58 66 public static boolean equals(final float a, final float b) { 67 return Float.floatToIntBits(a) == Float.floatToIntBits(b); 68 } 69 70 80 public static boolean equals(final byte a[], final int abegin, 81 final byte b[], final int bbegin, 82 final int length) 83 { 84 try { 85 int i=length; 86 while (--i >= 0) { 87 if (a[abegin + i] != b[bbegin + i]) { 88 return false; 89 } 90 } 91 } 92 catch (ArrayIndexOutOfBoundsException e) { 93 return false; 94 } 95 96 return true; 97 } 98 99 106 public static boolean equals(final byte a[], final byte b[]) { 107 if (a == b) return true; 108 if (a == null || b == null) return false; 109 if (a.length != b.length) return false; 110 111 try { 112 for (int i=0; i<a.length; i++) { 113 if (a[i] != b[i]) { 114 return false; 115 } 116 } 117 } 118 catch (ArrayIndexOutOfBoundsException e) { 119 return false; 120 } 121 122 return true; 123 } 124 125 } 126 | Popular Tags |