1+ /*
2+ * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
3+ * Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+ package fr .greencodeinitiative .java .checks ;
19+
20+ class AvoidMultipleIfElseStatementCompareMethod {
21+
22+ public int compare (FieldVo o1 , FieldVo o2 ) {
23+
24+ if (o1 .getIdBlock ().equals (o2 .getIdBlock ())) {
25+ if (o1 .getIdField ().equals (o2 .getIdField ())) {
26+ return 0 ;
27+ }
28+ // First original
29+ if (o1 .isOriginal () && !o2 .isOriginal ()) {
30+ return -1 ;
31+ } else if (!o1 .isOriginal () && o2 .isOriginal ()) {
32+ return 1 ;
33+ }
34+ // First min posgafld
35+ Long result = o1 .getColumnPos () - o2 .getColumnPos ();
36+ if (result != 0 ) {
37+ return result .intValue ();
38+ }
39+
40+ // First min ordgaflc
41+ result = o1 .getIndex () - o2 .getIndex ();
42+ return result .intValue ();
43+ }
44+ // First BQRY block
45+ if (o1 .getIdBlock ().startsWith ("BQRY" ) && !o2 .getIdBlock ().startsWith ("BQRY" )) {
46+ return -1 ;
47+ } else if (!o1 .getIdBlock ().startsWith ("BQRY" ) && o2 .getIdBlock ().startsWith ("BQRY" )) {
48+ return 1 ;
49+ }
50+ // If both block don't start with BQRY, sort alpha with String.compareTo method
51+ return o1 .getIdBlock ().compareTo (o2 .getIdBlock ());
52+ }
53+
54+ }
0 commit comments