@@ -69,10 +69,16 @@ private SearchSortedMatrix() {
6969 * @throws NullPointerException if {@code comparator} is null
7070 */
7171 public static <T > boolean search (final T [][] matrix , final T target , final Comparator <? super T > comparator ) {
72- if (matrix == null || matrix . length == 0 ) {
72+ if (matrix == null ) {
7373 return false ;
7474 }
75- if (matrix [0 ] == null || matrix [0 ].length == 0 ) {
75+ if (matrix .length == 0 ) {
76+ return false ;
77+ }
78+ if (matrix [0 ] == null ) {
79+ return false ;
80+ }
81+ if (matrix [0 ].length == 0 ) {
7682 return false ;
7783 }
7884
@@ -93,7 +99,10 @@ public static <T> boolean search(final T[][] matrix, final T target, final Compa
9399 int rowIndex = 0 ;
94100 int colIndex = colCount - 1 ;
95101
96- while (rowIndex < rowCount && colIndex >= 0 ) {
102+ while (rowIndex < rowCount ) {
103+ if (colIndex < 0 ) {
104+ break ;
105+ }
97106 final T value = matrix [rowIndex ][colIndex ];
98107 final int comparison = comparator .compare (value , target );
99108 if (comparison == 0 ) {
@@ -120,10 +129,16 @@ public static <T> boolean search(final T[][] matrix, final T target, final Compa
120129 * @throws IllegalArgumentException if the matrix is jagged or contains null rows
121130 */
122131 public static boolean search (final int [][] matrix , final int target ) {
123- if (matrix == null || matrix . length == 0 ) {
132+ if (matrix == null ) {
124133 return false ;
125134 }
126- if (matrix [0 ] == null || matrix [0 ].length == 0 ) {
135+ if (matrix .length == 0 ) {
136+ return false ;
137+ }
138+ if (matrix [0 ] == null ) {
139+ return false ;
140+ }
141+ if (matrix [0 ].length == 0 ) {
127142 return false ;
128143 }
129144
@@ -142,7 +157,10 @@ public static boolean search(final int[][] matrix, final int target) {
142157 int rowIndex = 0 ;
143158 int colIndex = colCount - 1 ;
144159
145- while (rowIndex < rowCount && colIndex >= 0 ) {
160+ while (rowIndex < rowCount ) {
161+ if (colIndex < 0 ) {
162+ break ;
163+ }
146164 final int value = matrix [rowIndex ][colIndex ];
147165 if (value == target ) {
148166 return true ;
0 commit comments