⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arraymgr.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        i++;
                    }
                }
                return -1;
            }
        }
    }

    /**
     * Returns the index within source array of the first occurrence of the
     * target array, starting at the specified index. The source is the int
     * array being searched, and the target is the int array being searched for.
     * 
     * @param source
     *            the array being searched.
     * @param target
     *            the array being searched for.
     * @param fromIndex
     *            the index to begin searching from.
     * @return the index within source array of the first occurrence of the
     *         target array, starting at the specified index.
     */
    public static int indexOf(int[] source, int[] target, int fromIndex) {
        int sourceLen = source.length;
        int targetLen = target.length;
        if ((fromIndex > sourceLen) || (fromIndex < 0)) {
            throw new IllegalArgumentException(fromIndex
                    + " is not between 0 and " + sourceLen);
        } else {
            if (targetLen == 0) {
                return fromIndex;
            } else {
                int i = fromIndex;
                int max = sourceLen - targetLen;
                int j;
                while (i <= max) {
                    j = 0;
                    while ((j < targetLen) && (source[i + j] == target[j])) {
                        j++;
                    }
                    if (j == targetLen) {
                        return i;
                    } else {
                        i++;
                    }
                }
                return -1;
            }
        }
    }

    /**
     * Returns the index within source array of the first occurrence of the
     * target array, starting at the specified index. The source is the array of
     * long being searched, and the target is the array of long being searched
     * for.
     * 
     * @param source
     *            the array being searched.
     * @param target
     *            the array being searched for.
     * @param fromIndex
     *            the index to begin searching from.
     * @return the index within source array of the first occurrence of the
     *         target array, starting at the specified index.
     */
    public static int indexOf(long[] source, long[] target, int fromIndex) {
        int sourceLen = source.length;
        int targetLen = target.length;
        if ((fromIndex > sourceLen) || (fromIndex < 0)) {
            throw new IllegalArgumentException(fromIndex
                    + " is not between 0 and " + sourceLen);
        } else {
            if (targetLen == 0) {
                return fromIndex;
            } else {
                int i = fromIndex;
                int max = sourceLen - targetLen;
                int j;
                while (i <= max) {
                    j = 0;
                    while ((j < targetLen) && (source[i + j] == target[j])) {
                        j++;
                    }
                    if (j == targetLen) {
                        return i;
                    } else {
                        i++;
                    }
                }
                return -1;
            }
        }
    }

    /**
     * Returns the index within source array of the first occurrence of the
     * target array, starting at the specified index. The source is the double
     * array being searched, and the target is the double array being searched
     * for.
     * 
     * @param source
     *            the array being searched.
     * @param target
     *            the array being searched for.
     * @param fromIndex
     *            the index to begin searching from.
     * @return the index within source array of the first occurrence of the
     *         target array, starting at the specified index.
     */
    public static int indexOf(double[] source, double[] target, int fromIndex) {
        int sourceLen = source.length;
        int targetLen = target.length;
        if ((fromIndex > sourceLen) || (fromIndex < 0)) {
            throw new IllegalArgumentException(fromIndex
                    + " is not between 0 and " + sourceLen);
        } else {
            if (targetLen == 0) {
                return fromIndex;
            } else {
                int i = fromIndex;
                int max = sourceLen - targetLen;
                int j;
                while (i <= max) {
                    j = 0;
                    while ((j < targetLen) && (source[i + j] == target[j])) {
                        j++;
                    }
                    if (j == targetLen) {
                        return i;
                    } else {
                        i++;
                    }
                }
                return -1;
            }
        }
    }

    /**
     * Returns the index within source array of the first occurrence of the
     * target array, starting at the specified index. The source is the double
     * array being searched, and the target is the double array being searched
     * for.
     * 
     * @param source
     *            the array being searched.
     * @param target
     *            the array being searched for.
     * @param fromIndex
     *            the index to begin searching from.
     * @return the index within source array of the first occurrence of the
     *         target array, starting at the specified index.
     */
    public static int indexOf(float[] source, float[] target, int fromIndex) {
        int sourceLen = source.length;
        int targetLen = target.length;
        if ((fromIndex > sourceLen) || (fromIndex < 0)) {
            throw new IllegalArgumentException(fromIndex
                    + " is not between 0 and " + sourceLen);
        } else {
            if (targetLen == 0) {
                return fromIndex;
            } else {
                int i = fromIndex;
                int max = sourceLen - targetLen;
                int j;
                while (i <= max) {
                    j = 0;
                    while ((j < targetLen) && (source[i + j] == target[j])) {
                        j++;
                    }
                    if (j == targetLen) {
                        return i;
                    } else {
                        i++;
                    }
                }
                return -1;
            }
        }
    }

    /**
     * Returns the index within source array of the first occurrence of the
     * target array, starting at the specified index. The source is the array of
     * Object being searched, and the target is the array of Object being
     * searched for. Two objects <tt>e1</tt> and <tt>e2</tt> are considered
     * <i>equal </i> if <tt>(e1==null ? e2==null
     * : e1.equals(e2))</tt>.
     * 
     * @param source
     *            the array being searched.
     * @param target
     *            the array being searched for.
     * @param fromIndex
     *            the index to begin searching from.
     * @return the index within source array of the first occurrence of the
     *         target array, starting at the specified index.
     */
    public static int indexOf(Object[] source, Object[] target, int fromIndex) {
        int sourceLen = source.length;
        int targetLen = target.length;
        if ((fromIndex > sourceLen) || (fromIndex < 0)) {
            throw new IllegalArgumentException(fromIndex
                    + " is not between 0 and " + sourceLen);
        } else {
            if (targetLen == 0) {
                return fromIndex;
            } else {
                int i = fromIndex;
                int max = sourceLen - targetLen;
                int j;
                while (i <= max) {
                    j = 0;
                    while ((j < targetLen)
                            && (source[i + j] == null ? target[j] == null
                                    : source[i + j].equals(target[j]))) {
                        j++;
                    }
                    if (j == targetLen) {
                        return i;
                    } else {
                        i++;
                    }
                }
                return -1;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -