public static LinkKind getbyid(int id) { if (id == 1) return SAME; else if (id == 2) return MAYBESAME; else if (id == 3) return DIFFERENT; throw new DukeException("No kind with id " + id); } }
@Test public void testBigBadFile() throws IOException { // the problem with this file is that it contains unbalanced quotes, // leading to a row that's longer than the buffer. that used to cause // a stack overflow crash. we verify that instead we get an error message ClassLoader cloader = Thread.currentThread().getContextClassLoader(); InputStream istream = cloader.getResourceAsStream("big-bad.csv"); CSVReader reader = new CSVReader(new InputStreamReader(istream), 65536, "big-bad.csv"); try { String[] row = reader.next(); while (reader.next() != null) ; fail("Shouldn't accept malformed file"); } catch (DukeException e) { // error message must contain name of file assertTrue(e.getMessage().indexOf("big-bad.csv") != -1); } }
@Test public void testBigBadFile2() throws IOException { // the problem with this file is that it contains unbalanced quotes, // but now we've set the buffer size bigger than the file size. that // should lead to a different error message ClassLoader cloader = Thread.currentThread().getContextClassLoader(); InputStream istream = cloader.getResourceAsStream("big-bad.csv"); CSVReader reader = new CSVReader(new InputStreamReader(istream), 90000, "big-bad.csv"); try { String[] row = reader.next(); while (reader.next() != null) ; fail("Shouldn't accept malformed file"); } catch (DukeException e) { // error message must contain name of file assertTrue(e.getMessage().indexOf("big-bad.csv") != -1); } }
private Database getDB(int no) { if (no == 1) return database1; else if (no == 2) return database2; else throw new DukeException("Unknown database " + no); }
private boolean valid(double lat, double lon) { if (lat > 90.0 || lat < -90.0 || // north pole: 90 deg north lon > 180.0 || lon < -180.0) { // date line at -180 and +180 if (strict) throw new DukeException("Position outside legal range: " + lat + ", " + lon); return false; } else return true; } }
public Link inferLink(String id1, String id2) { // are we sure this method really belongs in the interface, and // not in an external utility? throw new DukeException("not implemented yet"); }
public static LinkStatus getbyid(int id) { if (id == 2) return ASSERTED; else if (id == 1) return INFERRED; else if (id == 0) return RETRACTED; throw new DukeException("No status with id " + id); } }
/** * Returns the Database in which the Duke index is stored for the * given group in record linkage mode. This will be the Lucene index * if you are using the Lucene database. * @param group Must be 1 or 2. */ public Database getDatabase(int group) { if (group == 1) return database1; else if (group == 2) return database2; throw new DukeException("Unknown group " + group); }
private void addToClass(String id, int clid) { try { stmt.executeUpdate("insert into classes values ('" + id + "', " + clid + ")"); } catch (SQLException e) { throw new DukeException(e); } }
protected void write(Writer writer, char c) { try { writer.write(c); } catch (IOException e) { throw new DukeException(e); } }
protected void write(Writer writer, char[] c, int off, int len) { try { writer.write(c, off, len); } catch (IOException e) { throw new DukeException(e); } }
protected void flush(Writer writer) { try { writer.flush(); } catch (IOException e) { throw new DukeException(e); } }
private void merge(int clid1, int clid2) { try { stmt.executeUpdate("update classes set clid = " + clid1 + " where clid = " + clid2); } catch (SQLException e) { throw new DukeException(e); } }
protected void write(Writer writer, String s) { try { writer.write(s); } catch (IOException e) { throw new DukeException(e); } }
public void setPortNumber(String port) { int parsedPort; try{ parsedPort = Integer.parseInt(port,10); if(parsedPort>=MIN_PORT && parsedPort<=MAX_PORT){ this.port = parsedPort; } } catch(NumberFormatException ex){ System.out.println("** Invalid port number: "+port); throw new DukeException(ex); } }
public void spawnThread(DukeController controller, int check_interval) { if (this.controller != null) throw new DukeException("Timer thread already running!"); this.controller = controller; this.check_interval = check_interval * 1000; // convert to ms keep_running = true; // spawn away Thread thread = new Thread(this); thread.setDaemon(true); thread.start(); }
private void parsedatatype() { pos++; // skip first ^ if (line.charAt(pos++) != '^') throw new DukeException("Incorrect start of datatype"); if (line.charAt(pos) != '<') throw new DukeException("Datatype URI does not start with '<'"); parseuri(); }
private String parseuri() { int start = pos + 1; // skip initial '<' while (pos < line.length() && line.charAt(pos) != '>') pos++; if (pos >= line.length()) throw new DukeException("Line ends in URI at line " + lineno); pos++; // skip final '>' return line.substring(start, pos - 1); }
private String parsebnode() { int start = pos; pos++; // skip '_' if (line.charAt(pos++) != ':') throw new DukeException("Incorrect start of blank node"); char ch = line.charAt(pos++); while ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) ch = line.charAt(pos++); return line.substring(start, pos - 1); }
/** * Get a configured database connection via JNDI. */ public static Statement open(String jndiPath) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiPath); Connection conn = ds.getConnection(); return conn.createStatement(); } catch (NamingException e) { throw new DukeException("No database configuration found via JNDI at " + jndiPath, e); } catch (SQLException e) { throw new DukeException("Error connecting to database via " + jndiPath, e); } }