View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  
21  /*
22   * Copyright 2013 The Netty Project
23   * The Netty Project licenses this file to you under the Apache License,
24   * version 2.0 (the "License"); you may not use this file except in compliance
25   * with the License. You may obtain a copy of the License at:
26   * http://www.apache.org/licenses/LICENSE-2.0
27   * Unless required by applicable law or agreed to in writing, software
28   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30   * License for the specific language governing permissions and limitations
31   * under the License.
32   */
33  /**
34   * Copyright (c) 2004-2011 QOS.ch
35   * All rights reserved.
36   * <p>
37   * Permission is hereby granted, free of charge, to any person obtaining
38   * a copy of this software and associated documentation files (the
39   * "Software"), to deal in the Software without restriction, including
40   * without limitation the rights to use, copy, modify, merge, publish,
41   * distribute, sublicense, and/or sell copies of the Software, and to
42   * permit persons to whom the Software is furnished to do so, subject to
43   * the following conditions:
44   * <p>
45   * The above copyright notice and this permission notice shall be
46   * included in all copies or substantial portions of the Software.
47   * <p>
48   * THE SOFTWARE IS PROVIDED "AS  IS", WITHOUT WARRANTY OF ANY KIND,
49   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
51   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
52   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
53   * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
54   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55   */
56  package org.waarp.common.logging;
57  
58  /**
59   * Holds the results of formatting done by MessageFormatter.
60   */
61  class FormattingTuple {
62  
63    private final String message;
64    private final Throwable throwable;
65    private final Object[] argArray;
66  
67    FormattingTuple(final String message) {
68      this(message, null, null);
69    }
70  
71    FormattingTuple(final String message, final Object[] argArray,
72                    final Throwable throwable) {
73      this.message = message;
74      this.throwable = throwable;
75      if (throwable == null) {
76        this.argArray = argArray;
77      } else {
78        this.argArray = trimmedCopy(argArray);
79      }
80    }
81  
82    static Object[] trimmedCopy(final Object[] argArray) {
83      if (argArray == null || argArray.length == 0) {
84        throw new IllegalStateException(
85            "non-sensical empty or null argument array");
86      }
87      final int trimemdLen = argArray.length - 1;
88      final Object[] trimmed = new Object[trimemdLen];
89      System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
90      return trimmed;
91    }
92  
93    public final String getMessage() {
94      return message;
95    }
96  
97    public final Object[] getArgArray() {
98      return argArray;
99    }
100 
101   public final Throwable getThrowable() {
102     return throwable;
103   }
104 }