1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.logging.internal.helpers

File ExtendedMessageFormatter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

14
17
2
1
86
41
11
0.65
8.5
2
5.5

Classes

Class Line # Actions
ExtendedMessageFormatter 37 17 0% 11 3
0.9090909490.9%
 

Contributing tests

This file is covered by 13 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.logging.internal.helpers;
21   
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.xwiki.logging.internal.helpers.MessageParser.MessageElement;
27    import org.xwiki.logging.internal.helpers.MessageParser.MessageIndex;
28    import org.xwiki.logging.internal.helpers.MessageParser.MessageString;
29   
30    /**
31    * Provide what is missing in {@link org.slf4j.helpers.MessageFormatter}.
32    *
33    * @version $Id: b668c8bfe55994a2a1891ee3672b6174f1dcbdc2 $
34    * @since 4.2M1
35    */
36    // TODO: remove as soon as all that is provided by org.slf4j.helpers.MessageFormatter
 
37    public final class ExtendedMessageFormatter
38    {
39    /**
40    * Default constructor.
41    */
 
42  0 toggle private ExtendedMessageFormatter()
43    {
44   
45    }
46   
47    /**
48    * @param messagePattern the message pattern to parse
49    * @param arguments the arguments
50    * @return the list version of the message pattern
51    */
 
52  2340 toggle public static List<String> parseMessage(final String messagePattern, Object[] arguments)
53    {
54  2340 if (messagePattern == null) {
55  1 return null;
56    }
57   
58  2339 if (arguments == null || arguments.length == 0) {
59  139 return Arrays.asList(messagePattern);
60    }
61   
62  2200 List<String> messageList = new ArrayList<String>(arguments.length + 1);
63   
64  2200 MessageParser parser = new MessageParser(messagePattern, false);
65   
66  2200 StringBuilder lastElement = new StringBuilder();
67  12774 for (MessageElement element = parser.next(), previous = null; element != null; previous = element, element =
68    parser.next()) {
69  10574 if (arguments.length < messageList.size()) {
70  0 lastElement.append(element.getString());
71    } else {
72  10574 if (element instanceof MessageString) {
73  6293 messageList.add(element.getString());
74  4281 } else if (!(previous instanceof MessageString)) {
75  122 messageList.add("");
76    }
77    }
78    }
79   
80  2200 if (lastElement.length() > 0 || parser.getCurrentMessageElement() instanceof MessageIndex) {
81  66 messageList.add(lastElement.toString());
82    }
83   
84  2200 return messageList;
85    }
86    }