Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EqualsUtils |
|
| 4.0;4 |
1 | package org.jtheque.utils; | |
2 | ||
3 | import java.io.File; | |
4 | ||
5 | /* | |
6 | * This file is part of JTheque. | |
7 | * | |
8 | * JTheque is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License. | |
11 | * | |
12 | * JTheque is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | /** | |
22 | * An utility class for equality test. | |
23 | * | |
24 | * @author Baptiste Wicht | |
25 | */ | |
26 | public final class EqualsUtils { | |
27 | /** | |
28 | * Construct a new DatabaseUtils. This class is an utility class, it cannot be instanciated. | |
29 | * | |
30 | */ | |
31 | private EqualsUtils() { | |
32 | 0 | super(); |
33 | 0 | } |
34 | ||
35 | /** | |
36 | * Test if 2 objects are incompatible for equality test. | |
37 | * | |
38 | * @param object The first object to test. | |
39 | * @param other The second object to test. | |
40 | * | |
41 | * @return true if the objects are incompatibles else false. | |
42 | */ | |
43 | public static boolean areObjectIncompatible(Object object, Object other) { | |
44 | 3 | if (other == null) { |
45 | 0 | return true; |
46 | } | |
47 | ||
48 | 3 | return object.getClass() != other.getClass(); |
49 | } | |
50 | ||
51 | /** | |
52 | * Test if 2 object are not equals. | |
53 | * | |
54 | * @param object The first object to test. | |
55 | * @param other The second object to test. | |
56 | * | |
57 | * @return true if the objects aren't equals else false. | |
58 | */ | |
59 | public static boolean areNotEquals(Object object, Object other){ | |
60 | 8 | if (object == null) { |
61 | 3 | if (other != null) { |
62 | 1 | return true; |
63 | } | |
64 | 5 | } else if (!object.equals(other)) { |
65 | 3 | return true; |
66 | } | |
67 | ||
68 | 4 | return false; |
69 | } | |
70 | ||
71 | /** | |
72 | * Test if 2 files are not the sames files. | |
73 | * | |
74 | * @param file The first file to test. | |
75 | * @param other The second file to test. | |
76 | * | |
77 | * @return true if the files are not the same else false. | |
78 | * | |
79 | */ | |
80 | public static boolean areNotSameFile(File file, File other){ | |
81 | 4 | if (file == null) { |
82 | 0 | if (other != null) { |
83 | 0 | return true; |
84 | } | |
85 | 4 | } else if (!file.getAbsolutePath().equals(other.getAbsolutePath())) { |
86 | 2 | return true; |
87 | } | |
88 | ||
89 | 2 | return false; |
90 | } | |
91 | } |