Here you can find the source of inRange(int firstIndex, int secondIndex)
Parameter | Description |
---|---|
firstIndex | a parameter |
secondIndex | a parameter |
private static boolean inRange(int firstIndex, int secondIndex)
//package com.java2s; /*/* w w w. j a v a 2s . c o m*/ * Copyright (C) 2010 Gregor Trefs, Dominique Ritze * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Check whether the first index is in range of the second one. * This means firstIndex in [secondIndex-6,secondIndex-1] * * @param firstIndex * @param secondIndex * @return */ private static boolean inRange(int firstIndex, int secondIndex) { //before the "circle" closes, nothing to consider if (firstIndex < 34 && secondIndex < 34) { //just check whether the difference is less than 7 if (Math.abs(secondIndex - firstIndex) <= 6.0) { return true; } else { return false; } } //at the end of the "circle", be careful of indicies if (firstIndex > 33) { //adapt the indicies int adaptedFirstIndex = firstIndex - 40; if (secondIndex > 33) { int adaptedSecondIndex = secondIndex - 40; //with adapted indicies easy to check whether difference less than 7 if (Math.abs(adaptedSecondIndex - adaptedFirstIndex) <= 6.0) { return true; } else { return false; } } //second one must not be adapted because it is at //the beginning and not at the end if (Math.abs(secondIndex - adaptedFirstIndex) <= 6.0) { return true; } else { return false; } } return false; } }