Class ConstraintEnforcementException

 1 /*
 2  * Copyright (c) 2016 Vivid Solutions.
 3  *
 4  * All rights reserved. This program and the accompanying materials
 5  * are made available under the terms of the Eclipse Public License 2.0
 6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 8  * and the Eclipse Distribution License is available at
 9  *
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  */
12  
13 package org.locationtech.jts.triangulate;
14  
15 import org.locationtech.jts.geom.Coordinate;
16 import org.locationtech.jts.io.WKTWriter;
17  
18 /**
19  * Indicates a failure during constraint enforcement.
20  * 
21  * @author Martin Davis
22  * @version 1.0
23  */
24 public class ConstraintEnforcementException extends RuntimeException {
25  
26     private static final long serialVersionUID = 386496846550080140L;
27  
28     private static String msgWithCoord(String msg, Coordinate pt) {
29         if (pt != null)
30             return msg + " [ " + WKTWriter.toPoint(pt) + " ]";
31         return msg;
32     }
33  
34     private Coordinate pt = null;
35  
36     /**
37      * Creates a new instance with a given message.
38      * 
39      * @param msg a string
40      */
41     public ConstraintEnforcementException(String msg) {
42         super(msg);
43     }
44  
45     /**
46      * Creates a new instance with a given message and approximate location.
47      * 
48      * @param msg a string
49      * @param pt the location of the error
50      */
51     public ConstraintEnforcementException(String msg, Coordinate pt) {
52         super(msgWithCoord(msg, pt));
53         this.pt = new Coordinate(pt);
54     }
55  
56     /**
57      * Gets the approximate location of this error.
58      * 
59      * @return a location
60      */
61     public Coordinate getCoordinate() {
62         return pt;
63     }
64 }
65