List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private String lookupIdFromIndex(String indexedValue, String fieldName, String indexName) throws RuntimeException { try {// w w w.j a v a 2 s . com RedissonIndex index = null; Field field = cls.getDeclaredField(fieldName); if (field.isAnnotationPresent(RedissonIndex.List.class)) { RedissonIndex.List list = field.getAnnotation(RedissonIndex.List.class); index = Arrays.stream(list.value()).filter(r -> r.name().equals(indexName)).findFirst().get(); } if (field.isAnnotationPresent(RedissonIndex.class)) { index = field.getAnnotation(RedissonIndex.class); if (!index.name().equals(indexName)) { throw new NoSuchElementException("Index not found: " + indexName); } } if (index == null) { throw new NoSuchElementException(); } return index.valueResolver().newInstance().lookup(indexedValue, index); } catch (NoSuchFieldException | SecurityException | InstantiationException | IllegalAccessException | NoSuchElementException e) { throw new RuntimeException("Can not find index " + indexName + " for field " + fieldName + " under class " + cls.getCanonicalName() + " to resolve value " + indexedValue, e); } }
From source file:com.buaa.cfs.fs.FileSystem.java
/** * List the statuses and block locations of the files in the given path. * <p>/*w ww . ja v a2s . c o m*/ * If the path is a directory, if recursive is false, returns files in the directory; if recursive is true, return * files in the subtree rooted at the path. If the path is a file, return the file's status and block locations. * * @param f is the path * @param recursive if the subdirectories need to be traversed recursively * * @return an iterator that traverses statuses of the files * * @throws FileNotFoundException when the path does not exist; IOException see specific implementation */ public RemoteIterator<LocatedFileStatus> listFiles(final Path f, final boolean recursive) throws FileNotFoundException, IOException { return new RemoteIterator<LocatedFileStatus>() { private Stack<RemoteIterator<LocatedFileStatus>> itors = new Stack<RemoteIterator<LocatedFileStatus>>(); private RemoteIterator<LocatedFileStatus> curItor = listLocatedStatus(f); private LocatedFileStatus curFile; @Override public boolean hasNext() throws IOException { while (curFile == null) { if (curItor.hasNext()) { handleFileStat(curItor.next()); } else if (!itors.empty()) { curItor = itors.pop(); } else { return false; } } return true; } /** * Process the input stat. * If it is a file, return the file stat. * If it is a directory, traverse the directory if recursive is true; * ignore it if recursive is false. * @param stat input status * @throws IOException if any IO error occurs */ private void handleFileStat(LocatedFileStatus stat) throws IOException { if (stat.isFile()) { // file curFile = stat; } else if (recursive) { // directory itors.push(curItor); curItor = listLocatedStatus(stat.getPath()); } } @Override public LocatedFileStatus next() throws IOException { if (hasNext()) { LocatedFileStatus result = curFile; curFile = null; return result; } throw new NoSuchElementException("No more entry in " + f); } }; }
From source file:edu.ku.brc.specify.Specify.java
/** * //from ww w . j a v a 2s.c o m */ protected void importPrefs() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); String title = getResourceString("Specify.SELECT_FILE_OR_DIR");//$NON-NLS-1$ if (chooser.showDialog(null, title) != JFileChooser.CANCEL_OPTION) { File destFile = chooser.getSelectedFile(); Properties properties = new Properties(); try { properties.load(new FileInputStream(destFile)); AppPreferences remotePrefs = AppPreferences.getRemote(); for (Object key : properties.keySet()) { String keyStr = (String) key; remotePrefs.getProperties().put(keyStr, properties.get(key)); } } catch (Exception ex) { log.error(ex); // XXX Error Dialog } } else { throw new NoSuchElementException("The External File Repository needs a valid directory."); //$NON-NLS-1$ } }
From source file:edu.ku.brc.specify.Specify.java
/** * /*from w w w. j a va 2 s.c o m*/ */ protected void exportPrefs() { AppPreferences remotePrefs = AppPreferences.getRemote(); Properties props = remotePrefs.getProperties(); try { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); String title = getResourceString("Specify.SELECT_FILE_OR_DIR");//$NON-NLS-1$ if (chooser.showDialog(null, title) != JFileChooser.CANCEL_OPTION) { File destFile = chooser.getSelectedFile(); props.store(new FileOutputStream(destFile), "User Prefs"); //$NON-NLS-1$ } else { throw new NoSuchElementException("The External File Repository needs a valid directory."); //$NON-NLS-1$ } } catch (Exception ex) { log.error(ex); // XXX Error Dialog } }
From source file:i5.las2peer.services.mobsos.SurveyService.java
/** * Stores a new survey described with JSON into the MobSOS database. * The MobSOS database thereby generates a new id returned by this method. * @throws ParseException /* w w w .j a v a 2s.c o m*/ */ private int storeNewSurvey(JSONObject survey) throws IllegalArgumentException, SQLException, ParseException { Connection conn = null; PreparedStatement stmt = null; ResultSet rset = null; String sub = (String) getActiveUserInfo().get("sub"); try { conn = dataSource.getConnection(); stmt = conn.prepareStatement("insert into " + jdbcSchema + ".survey(owner, organization, logo, name, description, resource, start, end, lang ) values (?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.clearParameters(); stmt.setString(1, sub); // active agent becomes owner automatically stmt.setString(2, (String) survey.get("organization")); stmt.setString(3, (String) survey.get("logo")); stmt.setString(4, (String) survey.get("name")); stmt.setString(5, (String) survey.get("description")); stmt.setString(6, (String) survey.get("resource")); stmt.setTimestamp(7, new Timestamp(DatatypeConverter.parseDateTime((String) survey.get("start")).getTimeInMillis())); stmt.setTimestamp(8, new Timestamp(DatatypeConverter.parseDateTime((String) survey.get("end")).getTimeInMillis())); stmt.setString(9, (String) survey.get("lang")); stmt.executeUpdate(); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { return rs.getInt(1); } else { throw new NoSuchElementException("No new survey was created!"); } } catch (UnsupportedOperationException e) { e.printStackTrace(); } finally { try { if (rset != null) rset.close(); } catch (Exception e) { e.printStackTrace(); } try { if (stmt != null) stmt.close(); } catch (Exception e) { e.printStackTrace(); } try { if (conn != null) conn.close(); } catch (Exception e) { e.printStackTrace(); } } throw new NoSuchElementException("No new survey was created!"); }
From source file:i5.las2peer.services.mobsos.SurveyService.java
/** * Stores a new questionnaire described with JSON into the MobSOS database. * The MobSOS database thereby generates a new id returned by this method. * @throws UnsupportedEncodingException * @throws ParseException //w ww .j ava 2 s . c om */ private int storeNewQuestionnaire(JSONObject questionnaire) throws IllegalArgumentException, SQLException, UnsupportedEncodingException, ParseException { String sub = (String) getActiveUserInfo().get("sub"); Connection conn = null; PreparedStatement stmt = null; ResultSet rset = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement("insert into " + jdbcSchema + ".questionnaire(owner, organization, logo, name, description, lang) values (?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.clearParameters(); stmt.setString(1, sub); // active agent becomes owner automatically stmt.setString(2, (String) questionnaire.get("organization")); stmt.setString(3, (String) questionnaire.get("logo")); stmt.setString(4, (String) questionnaire.get("name")); stmt.setString(5, (String) questionnaire.get("description")); stmt.setString(6, (String) questionnaire.get("lang")); stmt.executeUpdate(); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { return rs.getInt(1); } else { throw new NoSuchElementException("No new questionnaire was created!"); } } catch (UnsupportedOperationException e) { e.printStackTrace(); } finally { try { if (rset != null) rset.close(); } catch (Exception e) { e.printStackTrace(); } try { if (stmt != null) stmt.close(); } catch (Exception e) { e.printStackTrace(); } try { if (conn != null) conn.close(); } catch (Exception e) { e.printStackTrace(); } } throw new NoSuchElementException("No new questionnaire was created!"); }