|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
HiveMind.java | 88.9% | 93.1% | 88.9% | 91.1% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind;
|
|
16 |
|
|
17 |
import java.util.Collection;
|
|
18 |
|
|
19 |
/**
|
|
20 |
* Static utility class for HiveMind.
|
|
21 |
*
|
|
22 |
* @author Howard Lewis Ship
|
|
23 |
*/
|
|
24 |
public final class HiveMind |
|
25 |
{ |
|
26 |
/**
|
|
27 |
* The full id of the {@link org.apache.hivemind.service.ThreadEventNotifier}service.
|
|
28 |
*/
|
|
29 |
public static final String THREAD_EVENT_NOTIFIER_SERVICE = "hivemind.ThreadEventNotifier"; |
|
30 |
|
|
31 |
/**
|
|
32 |
* The full id of the {@link org.apache.hivemind.service.ThreadLocale}service.
|
|
33 |
*
|
|
34 |
* @since 1.1
|
|
35 |
*/
|
|
36 |
|
|
37 |
public static final String THREAD_LOCALE_SERVICE = "hivemind.ThreadLocale"; |
|
38 |
|
|
39 |
/**
|
|
40 |
* The full id of the {@link org.apache.hivemind.service.InterfaceSynthesizer}service.
|
|
41 |
*
|
|
42 |
* @since 1.1
|
|
43 |
*/
|
|
44 |
|
|
45 |
public static final String INTERFACE_SYNTHESIZER_SERVICE = "hivemind.InterfaceSynthesizer"; |
|
46 |
|
|
47 |
/**
|
|
48 |
* An object used to synchronize access to {@link java.beans.Introspector}(which is not fully
|
|
49 |
* threadsafe).
|
|
50 |
*
|
|
51 |
* @since 1.1
|
|
52 |
*/
|
|
53 |
|
|
54 |
public static final Object INTROSPECTOR_MUTEX = new Object(); |
|
55 |
|
|
56 | 0 |
private HiveMind()
|
57 |
{ |
|
58 |
// Prevent instantiation
|
|
59 |
} |
|
60 |
|
|
61 | 8 |
public static ApplicationRuntimeException createRegistryShutdownException() |
62 |
{ |
|
63 | 8 |
return new ApplicationRuntimeException(HiveMindMessages.registryShutdown()); |
64 |
} |
|
65 |
|
|
66 |
/**
|
|
67 |
* Selects the first {@link Location}in an array of objects. Skips over nulls. The objects may
|
|
68 |
* be instances of Location or {@link Locatable}. May return null if no Location can be found.
|
|
69 |
*/
|
|
70 |
|
|
71 | 133 |
public static Location findLocation(Object[] locations) |
72 |
{ |
|
73 | 133 |
for (int i = 0; i < locations.length; i++) |
74 |
{ |
|
75 | 351 |
Object location = locations[i]; |
76 |
|
|
77 | 351 |
Location result = getLocation(location); |
78 |
|
|
79 | 351 |
if (result != null) |
80 | 26 |
return result;
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 | 107 |
return null; |
85 |
} |
|
86 |
|
|
87 |
/**
|
|
88 |
* Extracts a location from an object, checking to see if it implement {@link Location} or
|
|
89 |
* {@link Locatable}.
|
|
90 |
*
|
|
91 |
* @return the Location, or null if it can't be found
|
|
92 |
*/
|
|
93 | 364 |
public static Location getLocation(Object object) |
94 |
{ |
|
95 | 364 |
if (object == null) |
96 | 278 |
return null; |
97 |
|
|
98 | 86 |
if (object instanceof Location) |
99 | 19 |
return (Location) object;
|
100 |
|
|
101 | 67 |
if (object instanceof Locatable) |
102 |
{ |
|
103 | 15 |
Locatable locatable = (Locatable) object; |
104 |
|
|
105 | 15 |
return locatable.getLocation();
|
106 |
} |
|
107 |
|
|
108 | 52 |
return null; |
109 |
} |
|
110 |
|
|
111 |
/**
|
|
112 |
* Invokes {@link #getLocation(Object)}, then translate the result to a string value, or
|
|
113 |
* "unknown location" if null.
|
|
114 |
*/
|
|
115 | 4 |
public static String getLocationString(Object object) |
116 |
{ |
|
117 | 4 |
Location l = getLocation(object); |
118 |
|
|
119 | 4 |
if (l != null) |
120 | 0 |
return l.toString();
|
121 |
|
|
122 | 4 |
return HiveMindMessages.unknownLocation();
|
123 |
} |
|
124 |
|
|
125 |
/**
|
|
126 |
* Returns true if the string is null, empty, or contains only whitespace.
|
|
127 |
* <p>
|
|
128 |
* The commons-lang library provides a version of this, but the naming and behavior changed
|
|
129 |
* between 1.0 and 2.0, which causes some dependency issues.
|
|
130 |
*/
|
|
131 | 57050 |
public static boolean isBlank(String string) |
132 |
{ |
|
133 | 57050 |
if (string == null || string.length() == 0) |
134 | 54011 |
return true; |
135 |
|
|
136 | 3039 |
if (string.trim().length() == 0)
|
137 | 0 |
return true; |
138 |
|
|
139 | 3039 |
return false; |
140 |
} |
|
141 |
|
|
142 |
/**
|
|
143 |
* As with {@link #isBlank(String)}, but inverts the response.
|
|
144 |
*/
|
|
145 | 61 |
public static boolean isNonBlank(String string) |
146 |
{ |
|
147 | 61 |
return !isBlank(string);
|
148 |
} |
|
149 |
|
|
150 |
/**
|
|
151 |
* Updates the location of an object, if the object implements {@link LocationHolder}.
|
|
152 |
*
|
|
153 |
* @param holder
|
|
154 |
* the object to be updated
|
|
155 |
* @param location
|
|
156 |
* the location to assign to the holder object
|
|
157 |
*/
|
|
158 | 43996 |
public static void setLocation(Object holder, Location location) |
159 |
{ |
|
160 | 43996 |
if (holder != null && holder instanceof LocationHolder) |
161 |
{ |
|
162 | 42116 |
LocationHolder lh = (LocationHolder) holder; |
163 |
|
|
164 | 42116 |
lh.setLocation(location); |
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
/**
|
|
169 |
* Returns true if the Collection is null or empty.
|
|
170 |
*/
|
|
171 | 797 |
public static boolean isEmpty(Collection c) |
172 |
{ |
|
173 | 797 |
return c == null || c.isEmpty(); |
174 |
} |
|
175 |
} |
|