Return-Path: X-Original-To: apmail-commons-notifications-archive@minotaur.apache.org Delivered-To: apmail-commons-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D62551754F for ; Fri, 1 May 2015 20:56:02 +0000 (UTC) Received: (qmail 31150 invoked by uid 500); 1 May 2015 20:56:02 -0000 Delivered-To: apmail-commons-notifications-archive@commons.apache.org Received: (qmail 31113 invoked by uid 500); 1 May 2015 20:56:02 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 30271 invoked by uid 99); 1 May 2015 20:56:01 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 May 2015 20:56:01 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 3EE9BAC2CA7 for ; Fri, 1 May 2015 20:56:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r949864 [41/48] - in /websites/production/commons/content/proper/commons-lang: ./ apidocs/ apidocs/org/apache/commons/lang3/ apidocs/org/apache/commons/lang3/builder/ apidocs/org/apache/commons/lang3/time/ apidocs/src-html/org/apache/common... Date: Fri, 01 May 2015 20:55:53 -0000 To: notifications@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150501205601.3EE9BAC2CA7@hades.apache.org> Modified: websites/production/commons/content/proper/commons-lang/xref/org/apache/commons/lang3/ArrayUtils.html ============================================================================== --- websites/production/commons/content/proper/commons-lang/xref/org/apache/commons/lang3/ArrayUtils.html (original) +++ websites/production/commons/content/proper/commons-lang/xref/org/apache/commons/lang3/ArrayUtils.html Fri May 1 20:55:51 2015 @@ -1855,4750 +1855,5919 @@ 1847 } 1848 } 1849 -1850 // IndexOf search -1851 // ---------------------------------------------------------------------- -1852 -1853 // Object IndexOf -1854 //----------------------------------------------------------------------- -1855 /** -1856 * <p>Finds the index of the given object in the array.</p> -1857 * -1858 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -1859 * -1860 * @param array the array to search through for the object, may be {@code null} -1861 * @param objectToFind the object to find, may be {@code null} -1862 * @return the index of the object within the array, -1863 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -1864 */ -1865 public static int indexOf(final Object[] array, final Object objectToFind) { -1866 return indexOf(array, objectToFind, 0); -1867 } -1868 -1869 /** -1870 * <p>Finds the index of the given object in the array starting at the given index.</p> -1871 * -1872 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -1873 * -1874 * <p>A negative startIndex is treated as zero. A startIndex larger than the array -1875 * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p> -1876 * -1877 * @param array the array to search through for the object, may be {@code null} -1878 * @param objectToFind the object to find, may be {@code null} -1879 * @param startIndex the index to start searching at -1880 * @return the index of the object within the array starting at the index, -1881 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -1882 */ -1883 public static int indexOf(final Object[] array, final Object objectToFind, int startIndex) { -1884 if (array == null) { -1885 return INDEX_NOT_FOUND; -1886 } -1887 if (startIndex < 0) { -1888 startIndex = 0; -1889 } -1890 if (objectToFind == null) { -1891 for (int i = startIndex; i < array.length; i++) { -1892 if (array[i] == null) { -1893 return i; -1894 } -1895 } -1896 } else if (array.getClass().getComponentType().isInstance(objectToFind)) { -1897 for (int i = startIndex; i < array.length; i++) { -1898 if (objectToFind.equals(array[i])) { -1899 return i; -1900 } -1901 } +1850 // Swap +1851 //----------------------------------------------------------------------- +1852 /** +1853 * <p>Swaps two elements in the given array.</p> +1854 * +1855 * <p>There is no special handling for multi-dimensional arrays.</p> +1856 * +1857 * <p>This method does nothing for a {@code null} input array.</p> +1858 * +1859 * <p>Examples: +1860 * <ul> +1861 * <li>ArrayUtils.swap(["1", "2", "3"], 0, 2) -> ["3", "2", "1"]</li> +1862 * <li>ArrayUtils.swap(["1", "2", "3"], 0, 0) -> ["1", "2", "3"]</li> +1863 * <li>ArrayUtils.swap(["1", "2", "3"], 1, 0) -> ["2", "1", "3"]</li> +1864 * <li>ArrayUtils.swap(["1", "2", "3"], 0, 5) -> ArrayOutOfBoundsException</li> +1865 * </ul> +1866 * </p> +1867 * +1868 * @param array the array to swap, may be {@code null} +1869 * @param offset1 the index of the first element to swap +1870 * @param offset2 the index of the second element to swap +1871 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +1872 */ +1873 public static void swap(final Object[] array, int offset1, int offset2) { +1874 if (array == null) { +1875 return; +1876 } +1877 swap(array, offset1, offset2, 1); +1878 } +1879 +1880 /** +1881 * <p>Swaps two elements in the given array.</p> +1882 * +1883 * <p>This method does nothing for a {@code null} input array.</p> +1884 * +1885 * <p>Examples: +1886 * <ul> +1887 * <li>ArrayUtils.swap([true, false, true], 0, 2) -> [true, false, true]</li> +1888 * <li>ArrayUtils.swap([true, false, true], 0, 0) -> [true, false, true]</li> +1889 * <li>ArrayUtils.swap([true, false, true], 1, 0) -> [false, true, true]</li> +1890 * <li>ArrayUtils.swap([true, false, true], 0, 5) -> ArrayOutOfBoundsException</li> +1891 * </ul> +1892 * </p> +1893 * +1894 * @param array the array to swap, may be {@code null} +1895 * @param offset1 the index of the first element to swap +1896 * @param offset2 the index of the second element to swap +1897 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +1898 */ +1899 public static void swap(final long[] array, int offset1, int offset2) { +1900 if (array == null) { +1901 return; 1902 } -1903 return INDEX_NOT_FOUND; +1903 swap(array, offset1, offset2, 1); 1904 } 1905 1906 /** -1907 * <p>Finds the last index of the given object within the array.</p> +1907 * <p>Swaps two elements in the given array.</p> 1908 * -1909 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> +1909 * <p>This method does nothing for a {@code null} input array.</p> 1910 * -1911 * @param array the array to travers backwords looking for the object, may be {@code null} -1912 * @param objectToFind the object to find, may be {@code null} -1913 * @return the last index of the object within the array, -1914 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -1915 */ -1916 public static int lastIndexOf(final Object[] array, final Object objectToFind) { -1917 return lastIndexOf(array, objectToFind, Integer.MAX_VALUE); -1918 } -1919 -1920 /** -1921 * <p>Finds the last index of the given object in the array starting at the given index.</p> -1922 * -1923 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -1924 * -1925 * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than -1926 * the array length will search from the end of the array.</p> -1927 * -1928 * @param array the array to traverse for looking for the object, may be {@code null} -1929 * @param objectToFind the object to find, may be {@code null} -1930 * @param startIndex the start index to travers backwards from -1931 * @return the last index of the object within the array, -1932 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -1933 */ -1934 public static int lastIndexOf(final Object[] array, final Object objectToFind, int startIndex) { -1935 if (array == null) { -1936 return INDEX_NOT_FOUND; -1937 } -1938 if (startIndex < 0) { -1939 return INDEX_NOT_FOUND; -1940 } else if (startIndex >= array.length) { -1941 startIndex = array.length - 1; -1942 } -1943 if (objectToFind == null) { -1944 for (int i = startIndex; i >= 0; i--) { -1945 if (array[i] == null) { -1946 return i; -1947 } -1948 } -1949 } else if (array.getClass().getComponentType().isInstance(objectToFind)) { -1950 for (int i = startIndex; i >= 0; i--) { -1951 if (objectToFind.equals(array[i])) { -1952 return i; -1953 } -1954 } -1955 } -1956 return INDEX_NOT_FOUND; -1957 } -1958 -1959 /** -1960 * <p>Checks if the object is in the given array.</p> -1961 * -1962 * <p>The method returns {@code false} if a {@code null} array is passed in.</p> -1963 * -1964 * @param array the array to search through -1965 * @param objectToFind the object to find -1966 * @return {@code true} if the array contains the object -1967 */ -1968 public static boolean contains(final Object[] array, final Object objectToFind) { -1969 return indexOf(array, objectToFind) != INDEX_NOT_FOUND; -1970 } -1971 -1972 // long IndexOf -1973 //----------------------------------------------------------------------- -1974 /** -1975 * <p>Finds the index of the given value in the array.</p> -1976 * -1977 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -1978 * -1979 * @param array the array to search through for the object, may be {@code null} -1980 * @param valueToFind the value to find -1981 * @return the index of the value within the array, -1982 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -1983 */ -1984 public static int indexOf(final long[] array, final long valueToFind) { -1985 return indexOf(array, valueToFind, 0); -1986 } -1987 -1988 /** -1989 * <p>Finds the index of the given value in the array starting at the given index.</p> -1990 * -1991 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -1992 * -1993 * <p>A negative startIndex is treated as zero. A startIndex larger than the array -1994 * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p> -1995 * -1996 * @param array the array to search through for the object, may be {@code null} -1997 * @param valueToFind the value to find -1998 * @param startIndex the index to start searching at -1999 * @return the index of the value within the array, -2000 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2001 */ -2002 public static int indexOf(final long[] array, final long valueToFind, int startIndex) { -2003 if (array == null) { -2004 return INDEX_NOT_FOUND; -2005 } -2006 if (startIndex < 0) { -2007 startIndex = 0; -2008 } -2009 for (int i = startIndex; i < array.length; i++) { -2010 if (valueToFind == array[i]) { -2011 return i; -2012 } -2013 } -2014 return INDEX_NOT_FOUND; -2015 } -2016 -2017 /** -2018 * <p>Finds the last index of the given value within the array.</p> -2019 * -2020 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2021 * -2022 * @param array the array to travers backwords looking for the object, may be {@code null} -2023 * @param valueToFind the object to find -2024 * @return the last index of the value within the array, -2025 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2026 */ -2027 public static int lastIndexOf(final long[] array, final long valueToFind) { -2028 return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); -2029 } -2030 -2031 /** -2032 * <p>Finds the last index of the given value in the array starting at the given index.</p> -2033 * -2034 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2035 * -2036 * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the -2037 * array length will search from the end of the array.</p> +1911 * <p>Examples: +1912 * <ul> +1913 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +1914 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +1915 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +1916 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +1917 * </ul> +1918 * </p> +1919 * +1920 * @param array the array to swap, may be {@code null} +1921 * @param offset1 the index of the first element to swap +1922 * @param offset2 the index of the second element to swap +1923 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +1924 */ +1925 public static void swap(final int[] array, int offset1, int offset2) { +1926 if (array == null) { +1927 return; +1928 } +1929 swap(array, offset1, offset2, 1); +1930 } +1931 +1932 /** +1933 * <p>Swaps two elements in the given array.</p> +1934 * +1935 * <p>This method does nothing for a {@code null} input array.</p> +1936 * +1937 * <p>Examples: +1938 * <ul> +1939 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +1940 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +1941 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +1942 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +1943 * </ul> +1944 * </p> +1945 * +1946 * @param array the array to swap, may be {@code null} +1947 * @param offset1 the index of the first element to swap +1948 * @param offset2 the index of the second element to swap +1949 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +1950 */ +1951 public static void swap(final short[] array, int offset1, int offset2) { +1952 if (array == null) { +1953 return; +1954 } +1955 swap(array, offset1, offset2, 1); +1956 } +1957 +1958 /** +1959 * <p>Swaps two elements in the given array.</p> +1960 * +1961 * <p>This method does nothing for a {@code null} input array.</p> +1962 * +1963 * <p>Examples: +1964 * <ul> +1965 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +1966 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +1967 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +1968 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +1969 * </ul> +1970 * </p> +1971 * +1972 * @param array the array to swap, may be {@code null} +1973 * @param offset1 the index of the first element to swap +1974 * @param offset2 the index of the second element to swap +1975 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +1976 */ +1977 public static void swap(final char[] array, int offset1, int offset2) { +1978 if (array == null) { +1979 return; +1980 } +1981 swap(array, offset1, offset2, 1); +1982 } +1983 +1984 /** +1985 * <p>Swaps two elements in the given array.</p> +1986 * +1987 * <p>This method does nothing for a {@code null} input array.</p> +1988 * +1989 * <p>Examples: +1990 * <ul> +1991 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +1992 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +1993 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +1994 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +1995 * </ul> +1996 * </p> +1997 * +1998 * @param array the array to swap, may be {@code null} +1999 * @param offset1 the index of the first element to swap +2000 * @param offset2 the index of the second element to swap +2001 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +2002 */ +2003 public static void swap(final byte[] array, int offset1, int offset2) { +2004 if (array == null) { +2005 return; +2006 } +2007 swap(array, offset1, offset2, 1); +2008 } +2009 +2010 /** +2011 * <p>Swaps two elements in the given array.</p> +2012 * +2013 * <p>This method does nothing for a {@code null} input array.</p> +2014 * +2015 * <p>Examples: +2016 * <ul> +2017 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +2018 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +2019 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +2020 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +2021 * </ul> +2022 * </p> +2023 * +2024 * @param array the array to swap, may be {@code null} +2025 * @param offset1 the index of the first element to swap +2026 * @param offset2 the index of the second element to swap +2027 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +2028 */ +2029 public static void swap(final double[] array, int offset1, int offset2) { +2030 if (array == null) { +2031 return; +2032 } +2033 swap(array, offset1, offset2, 1); +2034 } +2035 +2036 /** +2037 * <p>Swaps two elements in the given array.</p> 2038 * -2039 * @param array the array to traverse for looking for the object, may be {@code null} -2040 * @param valueToFind the value to find -2041 * @param startIndex the start index to travers backwards from -2042 * @return the last index of the value within the array, -2043 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2044 */ -2045 public static int lastIndexOf(final long[] array, final long valueToFind, int startIndex) { -2046 if (array == null) { -2047 return INDEX_NOT_FOUND; -2048 } -2049 if (startIndex < 0) { -2050 return INDEX_NOT_FOUND; -2051 } else if (startIndex >= array.length) { -2052 startIndex = array.length - 1; -2053 } -2054 for (int i = startIndex; i >= 0; i--) { -2055 if (valueToFind == array[i]) { -2056 return i; -2057 } +2039 * <p>This method does nothing for a {@code null} input array.</p> +2040 * +2041 * <p>Examples: +2042 * <ul> +2043 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +2044 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +2045 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +2046 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +2047 * </ul> +2048 * </p> +2049 * +2050 * @param array the array to swap, may be {@code null} +2051 * @param offset1 the index of the first element to swap +2052 * @param offset2 the index of the second element to swap +2053 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +2054 */ +2055 public static void swap(final float[] array, int offset1, int offset2) { +2056 if (array == null) { +2057 return; 2058 } -2059 return INDEX_NOT_FOUND; +2059 swap(array, offset1, offset2, 1); 2060 } 2061 2062 /** -2063 * <p>Checks if the value is in the given array.</p> +2063 * <p>Swaps two elements in the given array.</p> 2064 * -2065 * <p>The method returns {@code false} if a {@code null} array is passed in.</p> +2065 * <p>This method does nothing for a {@code null} input array.</p> 2066 * -2067 * @param array the array to search through -2068 * @param valueToFind the value to find -2069 * @return {@code true} if the array contains the object -2070 */ -2071 public static boolean contains(final long[] array, final long valueToFind) { -2072 return indexOf(array, valueToFind) != INDEX_NOT_FOUND; -2073 } -2074 -2075 // int IndexOf -2076 //----------------------------------------------------------------------- -2077 /** -2078 * <p>Finds the index of the given value in the array.</p> -2079 * -2080 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2081 * -2082 * @param array the array to search through for the object, may be {@code null} -2083 * @param valueToFind the value to find -2084 * @return the index of the value within the array, -2085 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2086 */ -2087 public static int indexOf(final int[] array, final int valueToFind) { -2088 return indexOf(array, valueToFind, 0); -2089 } -2090 -2091 /** -2092 * <p>Finds the index of the given value in the array starting at the given index.</p> -2093 * -2094 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2095 * -2096 * <p>A negative startIndex is treated as zero. A startIndex larger than the array -2097 * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p> -2098 * -2099 * @param array the array to search through for the object, may be {@code null} -2100 * @param valueToFind the value to find -2101 * @param startIndex the index to start searching at -2102 * @return the index of the value within the array, -2103 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2104 */ -2105 public static int indexOf(final int[] array, final int valueToFind, int startIndex) { -2106 if (array == null) { -2107 return INDEX_NOT_FOUND; -2108 } -2109 if (startIndex < 0) { -2110 startIndex = 0; +2067 * <p>Examples: +2068 * <ul> +2069 * <li>ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]</li> +2070 * <li>ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]</li> +2071 * <li>ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]</li> +2072 * <li>ArrayUtils.swap([1, 2, 3], 0, 5) -> ArrayOutOfBoundsException</li> +2073 * </ul> +2074 * </p> +2075 * +2076 * @param array the array to swap, may be {@code null} +2077 * @param offset1 the index of the first element to swap +2078 * @param offset2 the index of the second element to swap +2079 * @throws ArrayIndexOutOfBoundsException if one of the indices is out of range +2080 */ +2081 public static void swap(final boolean[] array, int offset1, int offset2) { +2082 if (array == null) { +2083 return; +2084 } +2085 swap(array, offset1, offset2, 1); +2086 } +2087 +2088 /** +2089 * <p>Swaps a series of elements in the given array.</p> +2090 * +2091 * <p>This method does nothing for a {@code null} input array.</p> +2092 * +2093 * <p>Examples: +2094 * <ul> +2095 * <li>ArrayUtils.swap(["1", "2", "3", "4"], 0, 2, 1) -> ["3", "2", "1", "4"]</li> +2096 * <li>ArrayUtils.swap(["1", "2", "3", "4"], 0, 0, 1) -> ["1", "2", "3", "4"]</li> +2097 * <li>ArrayUtils.swap(["1", "2", "3", "4"], 2, 0, 2) -> ["3", "4", "1", "2"]</li> +2098 * <li>ArrayUtils.swap(["1", "2", "3", "4"], 0, 3, 3) -> ArrayOutOfBoundsException</li> +2099 * </ul> +2100 * </p> +2101 * +2102 * @param array the array to swap, may be {@code null} +2103 * @param offset1 the index of the first element in the series to swap +2104 * @param offset2 the index of the second element in the series to swap +2105 * @param len the number of elements to swap starting with the given indices +2106 * @throws ArrayIndexOutOfBoundsException if one of the indices (plus the length of the series to swap) is out of range +2107 */ +2108 public static void swap(final boolean[] array, int offset1, int offset2, int len) { +2109 if (array == null) { +2110 return; 2111 } -2112 for (int i = startIndex; i < array.length; i++) { -2113 if (valueToFind == array[i]) { -2114 return i; -2115 } -2116 } -2117 return INDEX_NOT_FOUND; -2118 } -2119 -2120 /** -2121 * <p>Finds the last index of the given value within the array.</p> -2122 * -2123 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2124 * -2125 * @param array the array to travers backwords looking for the object, may be {@code null} -2126 * @param valueToFind the object to find -2127 * @return the last index of the value within the array, -2128 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2129 */ -2130 public static int lastIndexOf(final int[] array, final int valueToFind) { -2131 return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); -2132 } -2133 -2134 /** -2135 * <p>Finds the last index of the given value in the array starting at the given index.</p> -2136 * -2137 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2138 * -2139 * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the -2140 * array length will search from the end of the array.</p> -2141 * -2142 * @param array the array to traverse for looking for the object, may be {@code null} -2143 * @param valueToFind the value to find -2144 * @param startIndex the start index to travers backwards from -2145 * @return the last index of the value within the array, -2146 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2147 */ -2148 public static int lastIndexOf(final int[] array, final int valueToFind, int startIndex) { -2149 if (array == null) { -2150 return INDEX_NOT_FOUND; -2151 } -2152 if (startIndex < 0) { -2153 return INDEX_NOT_FOUND; -2154 } else if (startIndex >= array.length) { -2155 startIndex = array.length - 1; -2156 } -2157 for (int i = startIndex; i >= 0; i--) { -2158 if (valueToFind == array[i]) { -2159 return i; -2160 } -2161 } -2162 return INDEX_NOT_FOUND; -2163 } -2164 -2165 /** -2166 * <p>Checks if the value is in the given array.</p> -2167 * -2168 * <p>The method returns {@code false} if a {@code null} array is passed in.</p> -2169 * -2170 * @param array the array to search through -2171 * @param valueToFind the value to find -2172 * @return {@code true} if the array contains the object -2173 */ -2174 public static boolean contains(final int[] array, final int valueToFind) { -2175 return indexOf(array, valueToFind) != INDEX_NOT_FOUND; -2176 } -2177 -2178 // short IndexOf -2179 //----------------------------------------------------------------------- -2180 /** -2181 * <p>Finds the index of the given value in the array.</p> -2182 * -2183 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2184 * -2185 * @param array the array to search through for the object, may be {@code null} -2186 * @param valueToFind the value to find -2187 * @return the index of the value within the array, -2188 * {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input -2189 */ -2190 public static int indexOf(final short[] array, final short valueToFind) { -2191 return indexOf(array, valueToFind, 0); -2192 } -2193 -2194 /** -2195 * <p>Finds the index of the given value in the array starting at the given index.</p> -2196 * -2197 * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p> -2198 * -2199 * <p>A negative startIndex is treated as zero. A startIndex larger than the array -2200 * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p> -2201 * [... 9979 lines stripped ...]