GridInfo { static int getIndex(int[] lineLocations, int location, boolean skipEqualLineLocations) { if (lineLocations.length < 2) { throw new IllegalArgumentException(Arrays.toString(lineLocations)); } else if (location < lineLocations[0] || location > lineLocations[lineLocations.length - 1]) { return -1; } for (int i = 0, j = 0; i < lineLocations.length - 1; i++) { if (skipEqualLineLocations && lineLocations[i] == lineLocations[i + 1]) { continue; } if (lineLocations[i] <= location && location < lineLocations[i + 1]) { return j; } j++; } throw new AssertionError(); } GridInfo(NlComponent layout);   }
@Test public void getIndex() { final int[] lineLocatoin = {100, 248, 248, 248, 248, 248, 248, 248, 248, 520, 767}; assertEquals(1, GridInfo.getIndex(lineLocatoin, 380, true)); assertEquals(2, GridInfo.getIndex(lineLocatoin, 600, true)); assertEquals(8, GridInfo.getIndex(lineLocatoin, 380, false)); assertEquals(-1, GridInfo.getIndex(lineLocatoin, 50, true)); assertEquals(-1, GridInfo.getIndex(lineLocatoin, 800, true)); }