001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Java Data Mining Package (JDMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * JDMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * JDMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with JDMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.core.script;
025    
026    import org.ujmp.core.exceptions.MatrixException;
027    
028    public class Result {
029    
030            private Object object = null;
031    
032            private String text = null;
033    
034            private String label = null;
035    
036            private Throwable exception = null;
037    
038            public Result(String text) {
039                    this(null, null, text, null);
040            }
041    
042            public Result(Throwable e) {
043                    this(null, null, null, e);
044            }
045    
046            public Result(String s, Throwable e) {
047                    this(null, null, s, e);
048            }
049    
050            public Result(String s, Object o) {
051                    this(s, o, null, null);
052            }
053    
054            public Result(String label, Object o, String s, Throwable e) {
055                    this.label = label;
056                    this.object = o;
057                    this.text = s;
058                    this.exception = e;
059            }
060    
061            public Throwable getException() {
062                    return exception;
063            }
064    
065            public void setException(Throwable exception) {
066                    this.exception = exception;
067            }
068    
069            @Override
070            public String toString() {
071                    StringBuilder s = new StringBuilder();
072                    if (label != null) {
073                            s.append(label + " =\n");
074                    }
075                    if (object != null) {
076                            s.append(object.toString());
077                    }
078                    if (text != null) {
079                            s.append(text);
080                    }
081                    if (text != null && exception != null) {
082                            s.append(": ");
083                    }
084                    if (exception != null) {
085                            s.append(getExceptionText());
086                    }
087                    return s.toString();
088            }
089    
090            public String getExceptionText() {
091                    if (exception instanceof MatrixException) {
092                            return exception.getMessage();
093                    } else {
094                            return exception.toString();
095                    }
096            }
097    
098            public String getText() {
099                    return text;
100            }
101    
102            public void setText(String text) {
103                    this.text = text;
104            }
105    
106            public Object getObject() {
107                    return object;
108            }
109    
110            public void setObject(Object object) {
111                    this.object = object;
112            }
113    
114            public String getLabel() {
115                    return label;
116            }
117    
118            public void setLabel(String label) {
119                    this.label = label;
120            }
121    }