Here you can find the source of arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int len)
Parameter | Description |
---|---|
len | the length to compare. The start indices and start+len must be valid. |
public final static boolean arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int len)
//package com.java2s; // License & terms of use: http://www.unicode.org/copyright.html#License public class Main { /**//from ww w . ja va2 s.c o m * Convenience utility to compare two Object[]s * Ought to be in System. * @param len the length to compare. * The start indices and start+len must be valid. */ public final static boolean arrayRegionMatches(Object[] source, int sourceStart, Object[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (!arrayEquals(source[i], target[i + delta])) return false; } return true; } /** * Convenience utility to compare two Object[]s * Ought to be in System. * @param len the length to compare. * The start indices and start+len must be valid. */ public final static boolean arrayRegionMatches(char[] source, int sourceStart, char[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (source[i] != target[i + delta]) return false; } return true; } /** * Convenience utility to compare two int[]s. * @param len the length to compare. * The start indices and start+len must be valid. * Ought to be in System */ public final static boolean arrayRegionMatches(int[] source, int sourceStart, int[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (source[i] != target[i + delta]) return false; } return true; } /** * Convenience utility to compare two arrays of doubles. * @param len the length to compare. * The start indices and start+len must be valid. * Ought to be in System */ public final static boolean arrayRegionMatches(double[] source, int sourceStart, double[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (source[i] != target[i + delta]) return false; } return true; } public final static boolean arrayRegionMatches(byte[] source, int sourceStart, byte[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (source[i] != target[i + delta]) return false; } return true; } /** * Convenience utility to compare two Object[]s. * Ought to be in System */ public final static boolean arrayEquals(Object[] source, Object target) { if (source == null) return (target == null); if (!(target instanceof Object[])) return false; Object[] targ = (Object[]) target; return (source.length == targ.length && arrayRegionMatches(source, 0, targ, 0, source.length)); } /** * Convenience utility to compare two int[]s * Ought to be in System */ public final static boolean arrayEquals(int[] source, Object target) { if (source == null) return (target == null); if (!(target instanceof int[])) return false; int[] targ = (int[]) target; return (source.length == targ.length && arrayRegionMatches(source, 0, targ, 0, source.length)); } /** * Convenience utility to compare two double[]s * Ought to be in System */ public final static boolean arrayEquals(double[] source, Object target) { if (source == null) return (target == null); if (!(target instanceof double[])) return false; double[] targ = (double[]) target; return (source.length == targ.length && arrayRegionMatches(source, 0, targ, 0, source.length)); } public final static boolean arrayEquals(byte[] source, Object target) { if (source == null) return (target == null); if (!(target instanceof byte[])) return false; byte[] targ = (byte[]) target; return (source.length == targ.length && arrayRegionMatches(source, 0, targ, 0, source.length)); } /** * Convenience utility to compare two Object[]s * Ought to be in System */ public final static boolean arrayEquals(Object source, Object target) { if (source == null) return (target == null); // for some reason, the correct arrayEquals is not being called // so do it by hand for now. if (source instanceof Object[]) return (arrayEquals((Object[]) source, target)); if (source instanceof int[]) return (arrayEquals((int[]) source, target)); if (source instanceof double[]) return (arrayEquals((double[]) source, target)); if (source instanceof byte[]) return (arrayEquals((byte[]) source, target)); return source.equals(target); } }