Java Array Equal getClosestIndexEqualToOrLargerThanGivenCoordinate(double[] coordinates, double coordinate)

Here you can find the source of getClosestIndexEqualToOrLargerThanGivenCoordinate(double[] coordinates, double coordinate)

Description

get Closest Index Equal To Or Larger Than Given Coordinate

License

Open Source License

Declaration

private static int getClosestIndexEqualToOrLargerThanGivenCoordinate(double[] coordinates, double coordinate) 

Method Source Code


//package com.java2s;
/* MOD_V2.0//from  w ww. j  a va2s. c om
 * Copyright (c) 2012 OpenDA Association
 * All rights reserved.
 *
 * This file is part of OpenDA.
 *
 * OpenDA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * OpenDA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with OpenDA.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;

public class Main {
    private static int getClosestIndexEqualToOrLargerThanGivenCoordinate(double[] coordinates, double coordinate) {
        int i = Arrays.binarySearch(coordinates, coordinate);
        if (i >= 0)
            return i;
        int insertionIndex = -i - 1;
        if (insertionIndex <= 0) {//if outside grid.
            return -1;
        }
        if (insertionIndex >= coordinates.length) {//if outside grid.
            return coordinates.length;
        }
        return insertionIndex;
    }
}

Related

  1. equalsIgnoreSequence(final T[] array1, final T[] array2)
  2. equalsIgnoreSequence(Object[] array1, Object[] array2)
  3. equalsToElement(final Object[] arr, final Object obj)
  4. equalStringArrays(String[] expected, String[] actual)
  5. findMinimaGreaterOrEqual(final int[] min, final int elt)
  6. isEquals(byte[] id1, byte[] id2)
  7. isEquals(char[] o1, char[] o2)
  8. isEquals(Object firstArray, Object secondArray)
  9. safeEquals(final byte[] obj1, final byte[] obj2)