1 /*
2 * Copyright 2013 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 /**
17 * Copyright (c) 2004-2011 QOS.ch
18 * All rights reserved.
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 *
39 */
40 package com.foxinmy.weixin4j.logging;
41
42 /**
43 * Holds the results of formatting done by {@link MessageFormatter}.
44 */
45 class FormattingTuple {
46
47 static final FormattingTuple NULL = new FormattingTuple(null);
48
49 private final String message;
50 private final Throwable throwable;
51 private final Object[] argArray;
52
53 FormattingTuple(String message) {
54 this(message, null, null);
55 }
56
57 FormattingTuple(String message, Object[] argArray, Throwable throwable) {
58 this.message = message;
59 this.throwable = throwable;
60 if (throwable == null) {
61 this.argArray = argArray;
62 } else {
63 this.argArray = trimmedCopy(argArray);
64 }
65 }
66
67 static Object[] trimmedCopy(Object[] argArray) {
68 if (argArray == null || argArray.length == 0) {
69 throw new IllegalStateException("non-sensical empty or null argument array");
70 }
71 final int trimemdLen = argArray.length - 1;
72 Object[] trimmed = new Object[trimemdLen];
73 System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
74 return trimmed;
75 }
76
77 public String getMessage() {
78 return message;
79 }
80
81 public Object[] getArgArray() {
82 return argArray;
83 }
84
85 public Throwable getThrowable() {
86 return throwable;
87 }
88 }