1 6 21 22 package de.schlichtherle.util; 23 24 27 public class Arrays { 28 29 36 public static boolean equals( 37 final byte[] b1, 38 final int b1off, 39 final byte[] b2, 40 final int b2off, 41 int max) { 42 if (b1 == null) 43 throw new NullPointerException ("b1"); 44 if (b2 == null) 45 throw new NullPointerException ("b2"); 46 if (0 > b1off || b1off > b1.length) 47 throw new IndexOutOfBoundsException ("b1off = " + b1off + ": Not in [0, " + b1.length + "[!"); 48 if (0 > b2off || b2off > b2.length) 49 throw new IndexOutOfBoundsException ("b2off = " + b2off + ": Not in [0, " + b2.length + "[!"); 50 if (max < 1) 51 throw new IllegalArgumentException ("len = " + max + ": Too small!"); 52 53 final int b1rem = b1.length - b1off; 54 final int b2rem = b2.length - b2off; 55 if (max > b1rem) { 56 max = b1rem; 57 if (max != b2rem) 58 return false; 59 } else if (max > b2rem) { 60 max = b2rem; 61 if (max != b1rem) 62 return false; 63 } 64 65 while (--max >= 0) 66 if (b1[b1off + max] != b2[b2off + max]) 67 return false; 68 69 return true; 70 } 71 72 protected Arrays() { 73 } 74 } | Popular Tags |