1 /*
2  * This file is part of ELKI:
3  * Environment for Developing KDD-Applications Supported by Index-Structures
4  *
5  * Copyright (C) 2018
6  * ELKI Development Team
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 package de.lmu.ifi.dbs.elki.data.type;
22 
23 import java.util.Collection;
24 
25 /**
26  * Exception thrown when no supported data type was found.
27  *
28  * @author Erich Schubert
29  * @since 0.4.0
30  *
31  * @assoc - - - TypeInformation
32  */
33 public class NoSupportedDataTypeException extends IllegalStateException {
34   /**
35    * Serial version.
36    */
37   private static final long serialVersionUID = 1L;
38 
39   /**
40    * Available types
41    */
42   private Collection<TypeInformation> types = null;
43 
44   /**
45    * Constructor.
46    *
47    * @param type Requested type
48    * @param types Available types.
49    */
NoSupportedDataTypeException(TypeInformation type, Collection<TypeInformation> types)50   public NoSupportedDataTypeException(TypeInformation type, Collection<TypeInformation> types) {
51     super("No data type found satisfying: " + type.toString());
52     this.types = types;
53   }
54 
55   /**
56    * Constructor with string message. If possible, use the type parameter
57    * instead!
58    *
59    * @param string Error message
60    */
NoSupportedDataTypeException(String string)61   public NoSupportedDataTypeException(String string) {
62     super(string);
63   }
64 
65   @Override
getMessage()66   public String getMessage() {
67     StringBuilder buf = new StringBuilder(super.getMessage());
68     if(types != null) {
69       buf.append("\nAvailable types:");
70       for(TypeInformation type : types) {
71         buf.append(' ').append(type.toString());
72       }
73     }
74     return buf.toString();
75   }
76 }
77