001    /*
002     * Copyright (c) 2005 Peter Palotas, Fredrik Johansson, Einar Pehrson,
003     * Sebastian Kekkonen, Lars Magnus Lång, Malin Johansson and Sofia Nilsson
004     *
005     * This file is part of
006     * CleanSheets Extension for Assertions
007     *
008     * CleanSheets Extension for Assertions is free software; you can
009     * redistribute it and/or modify it under the terms of the GNU General Public
010     * License as published by the Free Software Foundation; either version 2 of
011     * the License, or (at your option) any later version.
012     *
013     * CleanSheets Extension for Assertions is distributed in the hope that
014     * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
015     * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with CleanSheets Extension for Assertions; if not, write to the
020     * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
021     * Boston, MA  02111-1307  USA
022     */
023    package csheets.ext.assertion;
024    
025    import java.io.Serializable;
026    
027    /** This class contains information about a warning in an assertion.
028            A warning denotes a possible inconsistency or incorrectens in
029            an assertion. Objects of this type are returned by <code>Assertion.getWarnings()</code>
030            @see Assertion
031            @author Peter Palotas
032    */
033    public class AssertionWarning implements Serializable {
034    
035            /** The unique version identifier used for serialization */
036            private static final long serialVersionUID = -390161028866493880L;
037    
038            private Interval i1;
039            private Interval i2;
040            private Type type;
041    
042            /** Denotes the type of a warning. See documentation for the constructor for more info. */
043            public enum Type {
044                    INTERSECTING,
045                    ENCLOSING,
046                    EXCLUDING
047            };
048    
049            /** Constructor.
050                    @param type Either INTERSECTING meaning that i1 and i2 intersects,
051                            ENCLOSING meaning that i2 is completely enclosed by i1 or
052                            EXCLUDING meaning that i2 is completely excluded by i1.
053                    @param i1 One of the intervals of the conflict.
054                    @param i2 The other interval of the conflict.
055            */
056            public AssertionWarning(Type type, Interval i1, Interval i2) {
057                    this.type = type;
058                    this.i1 = i1;
059                    this.i2 = i2;
060            }
061    
062            /** Returns a message in english describing the conflict represented
063              *  by this warning.
064              */
065            public String toString() {
066    
067                    switch (type) {
068                            case INTERSECTING:
069                                    return "Interval " + i1 + " intersects with " + i2;
070    
071                            case ENCLOSING:
072                                    return "Interval " + i2 + " completely encloses " + i1;
073    
074                            case EXCLUDING:
075                                    return "Interval " + i2 + " completely encloses " + i1;
076                    }
077                    return "Unknown conflict between the intervals " + i1 + " and " + i2;
078            }
079    
080            /** Returns the type of this warning.
081               @return the type of this warning.
082            */
083            public Type getType() {
084                    return type;
085            }
086    
087            /** Returns the first interval involved in this warning.
088                    @return the first interval involved in this warning. */
089            public Interval getI1() {
090                    return i1;
091            }
092    
093            /** Returns the second interval involved in this warning.
094                    @return the second interval involved in this warning. */
095            public Interval getI2() {
096                    return i2;
097            }
098    }