Java Array arrayLookup(int[] ar, int keystart, int keyend, int forbidden)

Here you can find the source of arrayLookup(int[] ar, int keystart, int keyend, int forbidden)

Description

Find first entry in integer array, whose value is in a given range.

License

Open Source License

Parameter

Parameter Description
ar Array to perform lookup in
keystart lower limit of range, range includes this value
keyend high limit of range, range excludes this value
forbidden a value that may not be looked up.

Return

index of entry in array, -1 if no entry found

Declaration


public static int arrayLookup(int[] ar, int keystart, int keyend, int forbidden) 

Method Source Code

//package com.java2s;
/*/*from  w  ww . ja v a  2  s.  c  om*/
 * Copyright 2005--2008 Helsinki Institute for Information Technology
 *
 * This file is a part of Fuego middleware.  Fuego middleware is free
 * software; you can redistribute it and/or modify it under the terms
 * of the MIT license, included as the file MIT-LICENSE in the Fuego
 * middleware source distribution.  If you did not receive the MIT
 * license with the distribution, write to the Fuego Core project at
 * fuego-core-users@googlegroups.com.
 */

public class Main {
    /** Find first entry in integer array, whose value is in a given range.
     * @param ar Array to perform lookup in
     * @param keystart lower limit of range, range includes this value
     * @param keyend high limit of range, range excludes this value
     * @param forbidden a value that may not be looked up.
     * @return index of entry in array, -1 if no entry found
     */

    public static int arrayLookup(int[] ar, int keystart, int keyend, int forbidden) {
        for (int i = 0; ar != null && i < ar.length; i++)
            if (ar[i] >= keystart && ar[i] < keyend && ar[i] != forbidden)
                return i;
        return -1;
    }

    /** Find first entry in integer array, whose value is in a given range.
     * @param ar Array to perform lookup in
     * @param keystart lower limit of range, range includes this value
     * @param keyend high limit of range, range excludes this value
     * @return index of entry in array, -1 if no entry found
     */

    public static int arrayLookup(int[] ar, int keystart, int keyend) {
        for (int i = 0; ar != null && i < ar.length; i++)
            if (ar[i] >= keystart && ar[i] < keyend)
                return i;
        return -1;
    }
}

Related

  1. arrayExclude(double[] src, int excludeIndex)
  2. arrayFirstIndexOf(final T[] array, final T value)
  3. arrayFlatten(final int[][] arr)
  4. arrayGetCenter(byte[] array, int location, int length)
  5. arrayIsHave(String[] strs, String str)
  6. arrayMember(String[] array, String member)
  7. arrayMinus(double[] w, double[] v)
  8. arrayNotEmpty(T[] objects, String message)
  9. arrayOfClassType(T... array)