Skip to content

Commit d2073be

Browse files
committed
minor refactoring, javadoc changes
Signed-off-by: ceki <ceki@qos.ch>
1 parent 32a9854 commit d2073be

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

slf4j-api/src/main/java/org/slf4j/MDC.java

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
public class MDC {
6464

6565
static final String NULL_MDCA_URL = "http://www.slf4j.org/codes.html#null_MDCA";
66-
private static final String MDC_APAPTER_CANNOT_BE_NULL_MESSAGE = "MDCAdapter cannot be null. See also " + NULL_MDCA_URL;
66+
private static final String MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE = "MDCAdapter cannot be null. See also " + NULL_MDCA_URL;
6767
static final String NO_STATIC_MDC_BINDER_URL = "http://www.slf4j.org/codes.html#no_static_mdc_binder";
6868
static MDCAdapter MDC_ADAPTER;
6969

@@ -132,7 +132,7 @@ public static void put(String key, String val) throws IllegalArgumentException {
132132
throw new IllegalArgumentException("key parameter cannot be null");
133133
}
134134
if (getMDCAdapter() == null) {
135-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
135+
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
136136
}
137137
getMDCAdapter().put(key, val);
138138
}
@@ -187,9 +187,7 @@ public static String get(String key) throws IllegalArgumentException {
187187
throw new IllegalArgumentException("key parameter cannot be null");
188188
}
189189

190-
if (getMDCAdapter() == null) {
191-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
192-
}
190+
mdcAdapterNullCheck();
193191
return getMDCAdapter().get(key);
194192
}
195193

@@ -208,19 +206,15 @@ public static void remove(String key) throws IllegalArgumentException {
208206
throw new IllegalArgumentException("key parameter cannot be null");
209207
}
210208

211-
if (getMDCAdapter() == null) {
212-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
213-
}
209+
mdcAdapterNullCheck();
214210
getMDCAdapter().remove(key);
215211
}
216212

217213
/**
218214
* Clear all entries in the MDC of the underlying implementation.
219215
*/
220216
public static void clear() {
221-
if (getMDCAdapter() == null) {
222-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
223-
}
217+
mdcAdapterNullCheck();
224218
getMDCAdapter().clear();
225219
}
226220

@@ -232,9 +226,7 @@ public static void clear() {
232226
* @since 1.5.1
233227
*/
234228
public static Map<String, String> getCopyOfContextMap() {
235-
if (getMDCAdapter() == null) {
236-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
237-
}
229+
mdcAdapterNullCheck();
238230
return getMDCAdapter().getCopyOfContextMap();
239231
}
240232

@@ -250,9 +242,7 @@ public static Map<String, String> getCopyOfContextMap() {
250242
* @since 1.5.1
251243
*/
252244
public static void setContextMap(Map<String, String> contextMap) {
253-
if (getMDCAdapter() == null) {
254-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
255-
}
245+
mdcAdapterNullCheck();
256246
getMDCAdapter().setContextMap(contextMap);
257247
}
258248

@@ -280,7 +270,7 @@ public static MDCAdapter getMDCAdapter() {
280270
*/
281271
static void setMDCAdapter(MDCAdapter anMDCAdapter) {
282272
if(anMDCAdapter == null) {
283-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
273+
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
284274
}
285275
MDC_ADAPTER = anMDCAdapter;
286276
}
@@ -293,38 +283,38 @@ static void setMDCAdapter(MDCAdapter anMDCAdapter) {
293283
* @since 2.0.0
294284
*/
295285
static public void pushByKey(String key, String value) {
296-
if (getMDCAdapter() == null) {
297-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
298-
}
286+
mdcAdapterNullCheck();
299287
getMDCAdapter().pushByKey(key, value);
300288
}
301289

302290
/**
303-
* Pop the stack referenced by 'key' and return the value possibly null.
291+
* Pop the <b>stack</b> referenced by 'key' and return the value possibly null.
304292
*
305293
* @param key identifies the deque(stack)
306294
* @return the value just popped. May be null/
307295
* @since 2.0.0
308296
*/
309297
static public String popByKey(String key) {
310-
if (getMDCAdapter() == null) {
311-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
312-
}
298+
mdcAdapterNullCheck();
313299
return getMDCAdapter().popByKey(key);
314300
}
315301

316302
/**
317-
* Returns a copy of the deque(stack) referenced by 'key'. May be null.
303+
* Returns a copy of the <b>deque(stack)</b> referenced by 'key'. May be null.
318304
*
319305
* @param key identifies the stack
320306
* @return copy of stack referenced by 'key'. May be null.
321307
*
322308
* @since 2.0.0
323309
*/
324310
public Deque<String> getCopyOfDequeByKey(String key) {
311+
mdcAdapterNullCheck();
312+
return getMDCAdapter().getCopyOfDequeByKey(key);
313+
}
314+
315+
private static void mdcAdapterNullCheck() {
325316
if (getMDCAdapter() == null) {
326-
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
317+
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
327318
}
328-
return getMDCAdapter().getCopyOfDequeByKey(key);
329319
}
330320
}

slf4j-api/src/main/java/org/slf4j/spi/MDCAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public interface MDCAdapter {
9393
public void setContextMap(Map<String, String> contextMap);
9494

9595
/**
96-
* Push a value into the deque(stack) referenced by 'key'.
96+
* Push a value into the <b>deque(stack)</b> referenced by 'key'.
9797
*
9898
* @param key identifies the appropriate stack
9999
* @param value the value to push into the stack
@@ -102,7 +102,7 @@ public interface MDCAdapter {
102102
public void pushByKey(String key, String value);
103103

104104
/**
105-
* Pop the stack referenced by 'key' and return the value possibly null.
105+
* Pop the <b>stack</b> referenced by 'key' and return the value possibly null.
106106
*
107107
* @param key identifies the deque(stack)
108108
* @return the value just popped. May be null/
@@ -111,7 +111,7 @@ public interface MDCAdapter {
111111
public String popByKey(String key);
112112

113113
/**
114-
* Returns a copy of the deque(stack) referenced by 'key'. May be null.
114+
* Returns a copy of the <b>deque(stack)</b> referenced by 'key'. May be null.
115115
*
116116
* @param key identifies the stack
117117
* @return copy of stack referenced by 'key'. May be null.
@@ -122,7 +122,7 @@ public interface MDCAdapter {
122122

123123

124124
/**
125-
* Clear the deque(stack) referenced by 'key'.
125+
* Clear the <b>deque(stack)</b> referenced by 'key'.
126126
*
127127
* @param key identifies the stack
128128
*

0 commit comments

Comments
 (0)