Finds the nearest tab index that is available. This is primarily used for when the active
tab is removed.
@param newIndex
@returns {*}
978948
function getNearestSafeIndex (newIndex) {
    if (newIndex === -1) return -1;
    var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
        i, tab;
    for (i = 0; i <= maxOffset; i++) {
      tab = ctrl.tabs[ newIndex + i ];
      if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
      tab = ctrl.tabs[ newIndex - i ];
      if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
    }
    return newIndex;
  }
1153431
public List<Map.Entry<Integer, Float>> nearest(String query)
    {
        return queryNearest(query, 10);
    }
1302618
def index_of_nearest(p, hot_points, distance_f=distance):
    
    min_dist = None
    nearest_hp_i = None
    for i, hp in enumerate(hot_points):
        dist = distance_f(p, hp)
        if min_dist is None or dist < min_dist:
            min_dist = dist
            nearest_hp_i = i
    return nearest_hp_i
5650
private void setCurrentTab(final int index)
	{
		if (this.currentTab == index)
		{
			// already current
			return;
		}
		this.currentTab = index;

		final Component component;

		if ((currentTab == -1) || tabs.isEmpty() || !getVisiblityCache().isVisible(currentTab))
		{
			// no tabs or the current tab is not visible
			component = newPanel();
		}
		else
		{
			// show panel from selected tab
			final T tab = tabs.get(currentTab);
			component = tab.getPanel(TAB_PANEL_ID);
			if (component == null)
			{
				throw new WicketRuntimeException("ITab.getPanel() returned null. TabbedPanel ["
					+ getPath() + "] ITab index [" + currentTab + "]");
			}
		}

		if (!component.getId().equals(TAB_PANEL_ID))
		{
			throw new WicketRuntimeException(
				"ITab.getPanel() returned a panel with invalid id [" + component.getId()
					+ "]. You always have to return a panel with id equal to the provided panelId parameter. TabbedPanel ["
					+ getPath() + "] ITab index [" + currentTab + "]");
		}

		addOrReplace(component);
	}
694576
public int indexOfRelativeIndex(int relativeIndex) {
    for (int i = 0; i < relativeIndices.length; i++) {
      if (relativeIndices[i] == relativeIndex) {
        return i;
      }
    }
    return -1;
  }
669149
public function compareIndexes(Index $oldIndex, Index $newIndex)
    {
        return ($oldIndex->getName() !== $newIndex->getName())
            || ($oldIndex->getColumnNames() !== $newIndex->getColumnNames())
            || ($oldIndex->isUnique() !== $newIndex->isUnique());
    }
1224744
function nearestCharAfter(char, str, index) {
  // Find the nearest char index before given index. skip white space strings
  // If not found, return -1
  let i = index + 1;
  while (i < str.length) {
    if (str.charAt(i) === char) return i;
    if (!/\s/.test(str.charAt(i))) return -1;
    i += 1;
  }
  return -1;
}
976379
public boolean isTouchedByRange(int globalStartIndex, int globalEndIndex) {
        return ((startIndex >= globalStartIndex) && (startIndex <= globalEndIndex))
                || ((endIndex >= globalStartIndex) && (endIndex <= globalEndIndex))
                || ((startIndex <= globalStartIndex) && (endIndex >= globalEndIndex));

    }
535648
public int getNextRangeIndex() {
        int length = rangeIndexList.size();
        if (length > 0) {
            Integer rindex = rangeIndexList.get(length - 1);
            return rindex.intValue();
        }
        return 0;
    }
1002518
public Object remove(int index) {

        //Check that the index is less than size because the getInternal
        //method is being called with index - 1 and its checks will therefore
        //not be useful in this case.
        if (index >= size()) {
            throw new IndexOutOfBoundsException("Index out of bounds: "
                                                + index + " >= " + size());
        }

        //Get the node that is previous to the node being removed
        Node previousToRemove;

        if (index == 0) {
            previousToRemove = first;
        } else {
            previousToRemove = getInternal(index - 1);
        }

        //previousToRemove.next will never be null because of the check above
        //that index < size.
        Node toRemove = previousToRemove.next;

        previousToRemove.next = toRemove.next;

        elementCount--;

        //If they removed at the last valid index, then a the last element
        //was removed, therfore update the last pointer
        if (last == toRemove) {
            last = previousToRemove;
        }

        return toRemove.data;
    }
1244702
def index_nearest(value, array):
    

    a = (array-value)**2
    return index(a.min(), a)
379638
public FluentSelect deselectByIndex(final int index) {
        executeAndWrapReThrowIfNeeded(new DeselectByIndex(index), Context.singular(context, "deselectByIndex", null, index), true);
        return new FluentSelect(super.delegate, currentElement.getFound(), this.context, monitor, booleanInsteadOfNotFoundException);
    }
895312
protected int getNextIndex(final int currentIndex) {

        if (!isPaused()) {
            return currentIndex + 1;
        }

        int ret = currentIndex;

        while (isPaused()) {

            sendStepPausing(ret + 1);

            try {
                Thread.sleep(getPauseSpan());
            } catch (InterruptedException e) {
                LOG.warn("thread.sleep.error", e);
            }

            TestScript testScript = current.getTestScript();
            if (testScript.isScriptFileChanged()) {
                LOG.info("script.file.changed");
                current.setTestScript(
                        dao.load(testScript.getScriptFile(), testScript.getSheetName(), false));
            }

            // コンソールから有効なコマンド入力があるまでループします。
            if (cmd == null || cmd.key == null) {
                continue;
            }

            final int cmdRet = cmd.execute(ret, current.getTestScript(), appCtx);

            if (cmdRet < 0) {
                LOG.info("cmd.error");
            } else {
                ret = cmdRet;

                if (current.getTestScript().getTestStep(ret) == null) {
                    LOG.info("test.step.end");
                    break;
                }

                LOG.info("empty");
                LOG.info("test.step.next.prev");
                for (int i = ret - 1; i <= ret + 1; i++) {
                    TestStep nextStep = current.getTestScript().getTestStep(i);
                    if (nextStep == null) {
                        continue;
                    }
                    String nextMark = i == ret + 1 ? " <- 次に実行" : "";
                    LOG.info("test.step.next", new Object[] { nextStep.getNo(),
                            nextStep.getItemName(), nextStep.getLocator(), nextMark });
                }
                LOG.info("empty");
            }

            //
            if (cmd.key.release && cmdRet >= 0) {
                cmd = null;
                break;
            } else {
                cmd = null;
            }

        }

        return ret;
    }
435078
@SuppressWarnings("unchecked")
    public V get(int index) {
	int pos = Arrays.binarySearch(keyIndices, index);
	return (pos >= 0) ? (V)(values[pos]) : null;	
    }
517228
public MtasSpanQuery getNegativeQuery(int index) {
    if ((index >= 0) && (index < negativeQueryList.size())) {
      return negativeQueryList.get(index);
    } else {
      return null;
    }
  }
855149
function(index) {
        var nextIndex = index + 1;
        if (nextIndex < this.order.length) {
            var nextElement = OpenLayers.Util.getElement(this.order[nextIndex]);
            if (nextElement == undefined) {
                nextElement = this.getNextElement(nextIndex);
            }
            return nextElement;
        } else {
            return null;
        } 
    }
277409
function isCombinableRangeReturnIndex(range, fusable, index) {
    var start = index + range.low;
    var end = index + range.high;
    // example range = -1, 0             index = 1  => start = 0, end = 1, test fusable[1]
    for (var i = start; i < end; ++i) {
        if (!fusable[i + 1]) {
            return -1;
        }
    }
    return start;
}