Java Array Last Index Of lastIndexOf(Object o, Object[] vals)

Here you can find the source of lastIndexOf(Object o, Object[] vals)

Description

LAST INDEX OF

License

Open Source License

Declaration


public static int lastIndexOf(Object o, Object[] vals) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * The MIT License (MIT)/* ww  w .  j a  va  2  s.  c  o m*/
 * 
 * Copyright (c) 2016 Dalibor Drgo? <emptychannelmc@gmail.com>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/

public class Main {
    /****************
     * LAST INDEX OF
     */

    public static int lastIndexOf(Object o, Object[] vals) {
        return lastIndexOf(o, vals, 0);
    }

    public static int lastIndexOf(Object o, Object[] vals, int i) {
        if (vals == null || vals.length == 0) {
            return -1;
        }
        if (i >= vals.length) {
            i = vals.length - 1;
        }
        if (o == null) {
            for (; i >= 0; i--) {
                if (vals[i] == null) {
                    return i;
                }
            }
        } else {
            for (; i >= 0; i--) {
                if (o.equals(vals[i])) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static boolean equals(Object[] one, Object[] two, int size) {
        if (one == two) {
            return true;
        }
        while (size-- != 0) {
            Object on = one[size];
            Object tw = two[size];
            if ((on == null) ? tw != null : !on.equals(tw)) {
                return false;
            }
        }
        return true;
    }

    public static boolean equals(Object[] one, int off1, Object[] two,
            int off2, int size) {
        if (one == two && off1 == off2) {
            return true;
        }
        size += off1;
        for (; off1 < size; off1++, off2++) {
            Object on = one[off1];
            Object tw = two[off2];
            if ((on == null) ? tw != null : !on.equals(tw)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. lastIndexOf(final byte[] str, int startIndex, int endIndex, final byte ch)
  2. lastIndexOf(final char[] source, final int start, final int end, final char ch)
  3. lastIndexOf(final Object[] array, final Object objectToFind)
  4. lastIndexOf(int[] array, int intToFind)
  5. lastIndexOf(int[] array, int valueToFind)
  6. lastIndexOf(Object[] array, Object object)
  7. lastIndexOf(Object[] array, Object objectToFind)
  8. lastIndexOf(Object[] elements, Object value)
  9. lastIndexOf(String source, char[] chars)