OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 René Jeschke <rene_jeschke@yahoo.de> | |
3 * | |
4 * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 * you may not use this file except in compliance with the License. | |
6 * You may obtain a copy of the License at | |
7 * | |
8 * http://www.apache.org/licenses/LICENSE-2.0 | |
9 * | |
10 * Unless required by applicable law or agreed to in writing, software | |
11 * distributed under the License is distributed on an "AS IS" BASIS, | |
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 * See the License for the specific language governing permissions and | |
14 * limitations under the License. | |
15 */ | |
16 package com.github.rjeschke.neetutils; | |
17 | |
18 import java.util.Collection; | |
19 import java.util.List; | |
20 import java.util.Map; | |
21 | |
22 /** | |
23 * | |
24 * @author René Jeschke (rene_jeschke@yahoo.de) | |
25 */ | |
26 public final class Objects | |
27 { | |
28 private Objects() | |
29 { | |
30 // | |
31 } | |
32 | |
33 @Deprecated | |
34 public final static boolean implementsInterface(final Object o, final Class<?>
interfaceClass) | |
35 { | |
36 return implementsInterface(o.getClass(), interfaceClass); | |
37 } | |
38 | |
39 @Deprecated | |
40 public final static boolean implementsInterface(final Class<?> clazz, final Cl
ass<?> interfaceClass) | |
41 { | |
42 if (clazz.equals(interfaceClass)) | |
43 { | |
44 return true; | |
45 } | |
46 final Class<?>[] is = clazz.getInterfaces(); | |
47 for (int i = 0; i < is.length; i++) | |
48 { | |
49 if (is[i].equals(interfaceClass)) | |
50 { | |
51 return true; | |
52 } | |
53 } | |
54 return false; | |
55 } | |
56 | |
57 public final static boolean isString(final Object o) | |
58 { | |
59 return o instanceof String; | |
60 } | |
61 | |
62 public final static boolean isBoolean(final Object o) | |
63 { | |
64 return o instanceof Boolean; | |
65 } | |
66 | |
67 public final static boolean isNumber(final Object o) | |
68 { | |
69 return o instanceof Number; | |
70 } | |
71 | |
72 public final static boolean isMap(final Object o) | |
73 { | |
74 return o instanceof Map; | |
75 } | |
76 | |
77 public final static boolean isList(final Object o) | |
78 { | |
79 return o instanceof List; | |
80 } | |
81 | |
82 public final static boolean isCollection(final Object o) | |
83 { | |
84 return o instanceof Collection; | |
85 } | |
86 | |
87 public final static boolean equals(final Object a, final Object b) | |
88 { | |
89 if (a == b) | |
90 { | |
91 return true; | |
92 } | |
93 | |
94 if (a == null) | |
95 { | |
96 return b == null; | |
97 } | |
98 | |
99 if (a.getClass() != b.getClass()) | |
100 { | |
101 return false; | |
102 } | |
103 | |
104 return a.equals(b); | |
105 } | |
106 | |
107 public final static boolean isNullOrEmpty(final Object obj) | |
108 { | |
109 if (obj == null) | |
110 { | |
111 return true; | |
112 } | |
113 | |
114 if (obj instanceof Collection) | |
115 { | |
116 return ((Collection<?>)obj).isEmpty(); | |
117 } | |
118 if (obj instanceof Map) | |
119 { | |
120 return ((Map<?, ?>)obj).isEmpty(); | |
121 } | |
122 if (obj instanceof String) | |
123 { | |
124 return ((String)obj).length() == 0; | |
125 } | |
126 | |
127 return false; | |
128 } | |
129 | |
130 @SuppressWarnings("unchecked") | |
131 public final static <A> A uncheckedCast(final Object a) | |
132 { | |
133 return (A)a; | |
134 } | |
135 } | |
OLD | NEW |