Result.java |
/* Copyright (C) 2009 CSE,IIT Bombay http://www.cse.iitb.ac.in This file is part of the ConStore open source storage facility for concept-nets. ConStore is free software and distributed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License; you can copy, distribute and transmit the work with the work attribution in the manner specified by the author or licensor. You may not use this work for commercial purposes and may not alter, transform, or build upon this work. Please refer the legal code of the license, available at http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode ConStore is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ package iitb.con.util; /** * Result class holds the status of the method execution. * It acts like a <tt>boolean</tt> wrapper. User can set the * status as <tt>true</tt> or <tt>false</tt> with appropriate * message or exception. * * @author Prathab K * */ public class Result { /** * Stores true or false value of the method execution status */ public boolean Success; /** * Error messages of the method execution */ public String ErrMessage; /** * Information of method execution status */ public String Message; /** * Stores exception of the method execution */ public Throwable Exception; /** * Stores return object */ public Object Object; public Result() { } /** * Initializes the newly created <code>Result</code> with success status. * @param Success success status */ public Result(boolean Success) { this.Success = Success; } /** * Initializes the newly created <code>Result</code> with * the failure status and error message. * @param Success success status * @param message error message */ public Result(boolean Success, String message) { this.Success = Success; if(Success) this.Message = message; else this.ErrMessage = message; } /** * Initializes the newly created <code>Result</code> with * the failure status and error message. * @param Success success status * @param message error message */ public Result(boolean Success, String message, Throwable Exception) { this.Success = Success; this.Exception = Exception; if(Success) this.Message = message; else this.ErrMessage = message; } /** * Outputs the status of the <tt>Result</tt> object * @param result the <tt>Result</tt> object */ public static void status(Result result) { if(!result.Success) { if(result.ErrMessage != null) System.out.println(result.ErrMessage); if(result.Exception != null) result.Exception.printStackTrace(); } else { if(result.Message != null) System.out.println(result.Message); } } /** * Outputs the status of the <tt>Result</tt> object along with the user's message * @param msg message * @param result the <tt>Result</tt> object */ public static void status(String msg, Result result) { System.out.print(msg + " "); status(result); } }