Coverage Report - org.jtheque.core.utils.Response
 
Classes in this File Line Coverage Branch Coverage Complexity
Response
0 %
0/11
0 %
0/2
1.25
 
 1  
 package org.jtheque.core.utils;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque 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
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.language.ILanguageManager;
 21  
 
 22  
 /**
 23  
  * A generic response.
 24  
  *
 25  
  * @author Baptiste Wicht
 26  
  */
 27  
 public final class Response {
 28  
     private final boolean ok;
 29  
     private final String key;
 30  
     private String[] replaces;
 31  
 
 32  
     /**
 33  
      * Construct a response with a response true or false and a message key.
 34  
      *
 35  
      * @param ok  The real response.
 36  
      * @param key The message key.
 37  
      */
 38  
     public Response(boolean ok, String key) {
 39  0
         super();
 40  
 
 41  0
         this.key = key;
 42  0
         this.ok = ok;
 43  0
     }
 44  
 
 45  
     /**
 46  
      * Construct a response with a response true or false, a message key and some replaces for the message.
 47  
      *
 48  
      * @param ok       The real response.
 49  
      * @param key      The message key.
 50  
      * @param replaces The message replaces.
 51  
      */
 52  
     public Response(boolean ok, String key, String[] replaces) {
 53  0
         super();
 54  
 
 55  0
         this.key = key;
 56  0
         this.ok = ok;
 57  0
         this.replaces = replaces.clone();
 58  0
     }
 59  
 
 60  
     /**
 61  
      * Indicate if the response is true or false.
 62  
      *
 63  
      * @return true if the response is ok else false.
 64  
      */
 65  
     public boolean isOk() {
 66  0
         return ok;
 67  
     }
 68  
 
 69  
     /**
 70  
      * Return internationalized the message.
 71  
      *
 72  
      * @return The internationalized message.
 73  
      */
 74  
     public String getMessage() {
 75  0
         return replaces == null ?
 76  
                 Managers.getManager(ILanguageManager.class).getMessage(key) :
 77  
                 Managers.getManager(ILanguageManager.class).getMessage(key, replaces);
 78  
     }
 79  
 }