List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException()
From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java
/** * Password Manager entry point/* w w w .j ava2s . c om*/ * * @param argv * @throws Exception */ public static void main(String argv[]) throws Exception { keystoreManager = new KeystoreManagerCtrl(); // --- Options --- CommandLine line = null; try { CommandLineParser parser = new GnuParser(); // --- Parse the command line arguments --- // --- Help line = parser.parse(keystoreManager.helpOptions, argv, true); if (line.hasOption(_HELP)) { DisplayHelpAndExit(EXIT_CODE.EXIT_OK); } // --- Program command line options line = parser.parse(keystoreManager.options, argv); // --- Compulsory arguments : Get options --- if (line.hasOption(_KEYSTORE_LOCATION)) keystoreManager.keystoreLocation = line.getOptionValue(_KEYSTORE_LOCATION); if (line.hasOption(_KEY_ALIAS)) keystoreManager.keyAlias = line.getOptionValue(_KEY_ALIAS); if (line.hasOption(_KEY_TYPE)) { String keyType = line.getOptionValue(_KEY_TYPE); // This will throw an exception if the type is not recognised KEYSTORE_TYPE certificateTYpe = KEYSTORE_TYPE.fromString(keyType); keystoreManager.keyType = certificateTYpe; } if (line.hasOption(_KEYSTORE_PASSWORD)) keystoreManager.keystorePassword = line.getOptionValue(_KEYSTORE_PASSWORD); if (line.hasOption(_KEY_PASSWORD)) keystoreManager.keyPassword = line.getOptionValue(_KEY_PASSWORD); } catch (ParseException exp) { logger.error(exp.getMessage()); DisplayHelpAndExit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { // Workaround for Junit test if (e.toString().contains("CheckExitCalled")) { throw e; } else // Normal behaviour { logger.error(e.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } } // --- Perform commands --- // ######### Check password ########## if (line.hasOption(_CHECK)) { try { if (keystoreManager.keystorePassword == null || keystoreManager.keyPassword == null) { // --- Get passwords from stdin if not given on command line List<String> listPrompts = Arrays.asList("Keystore password:", MessageFormat.format("Password for key {0}:", keystoreManager.keyAlias)); List<String> listUserInput = keystoreManager.getUserInputFromStdin(listPrompts); if (listUserInput.size() == listPrompts.size()) { keystoreManager.keystorePassword = listUserInput.get(0); keystoreManager.keyPassword = listUserInput.get(1); } else { throw new NoSuchElementException(); } } try { // --- Check that all keys in keystore use the keystore // password logger.info(MessageFormat.format("Using keystore:{0}", keystoreManager.keystoreLocation)); SecurityHelper.checkKeyStorePasswords(keystoreManager.keystoreLocation, keystoreManager.keyType, keystoreManager.keystorePassword, keystoreManager.keyAlias, keystoreManager.keyPassword); logger.info(MessageFormat.format("OK : Identical password for Keystore and key={0}", keystoreManager.keyAlias)); } catch (UnrecoverableKeyException uke) { logger.error(MessageFormat.format("At least 1 key has a wrong password.{0}", uke.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("{0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } catch (NoSuchElementException nse) { logger.error(nse.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("Error while running the program: {0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } Exit(EXIT_CODE.EXIT_OK); }
From source file:Main.java
public static <ELEMENT_TYPE> Iterator<ELEMENT_TYPE> unmodifiableEmptyIterator() { return new Iterator<ELEMENT_TYPE>() { @Override//from w ww. j a v a 2s .c o m public boolean hasNext() { return false; } @Override public ELEMENT_TYPE next() { throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException("This collection is imutable and empty"); } }; }
From source file:Main.java
public static final int getAdapterPositionById(final Adapter adapter, final long id) throws NoSuchElementException { final int count = adapter.getCount(); for (int pos = 0; pos < count; pos++) { if (id == adapter.getItemId(pos)) { return pos; }/*from ww w. j a v a 2 s . co m*/ } throw new NoSuchElementException(); }
From source file:Main.java
public static <E extends Comparable<E>> E getSmallest(final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }/* w w w .j a v a 2s . c o m*/ if ((c instanceof List) && (c instanceof RandomAccess)) { return getSmallest((List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (element.compareTo(result) < 0) { result = element; } } return result; }
From source file:Main.java
public static <E extends Comparable<E>> E getGreatest(final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }//ww w . j av a 2 s . com if ((c instanceof List) && (c instanceof RandomAccess)) { return getGreatest((List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (element.compareTo(result) > 0) { result = element; } } return result; }
From source file:Main.java
public static <T> Iterable<T> asIterable(final T[] a) { return new Iterable<T>() { @Override/*from w w w.jav a 2s. co m*/ public Iterator<T> iterator() { return new Iterator<T>() { int index = 0; @Override public boolean hasNext() { return index < a.length; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } return a[index++]; } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; } }; }
From source file:Main.java
public static <T> Iterable<T> replicate(final T value, final int count) { return new Iterable<T>() { @Override/*ww w.j a va 2s .c o m*/ public Iterator<T> iterator() { return new Iterator<T>() { int remaining = count; @Override public boolean hasNext() { return remaining > 0; } @Override public T next() { if (remaining-- <= 0) throw new NoSuchElementException(); return value; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:Main.java
private static <E> Collection<E> asCollection(final E[] elements) { return new AbstractCollection<E>() { public Iterator<E> iterator() { return new Iterator<E>() { // Object field private int index = 0; // Interface methods public boolean hasNext() { return index < elements.length; }/*from w w w. ja v a2 s . c o m*/ public E next() { if (!hasNext()) { throw new NoSuchElementException(); } return elements[index++]; } public void remove() { throw new UnsupportedOperationException("remove"); } }; } public int size() { return elements.length; } }; }
From source file:Permutator.java
public static <T> Iterable<List<T>> permutations(final List<T> list) { return new Iterable<List<T>>() { public Iterator<List<T>> iterator() { return new Iterator<List<T>>() { private int current = 0; private final long length = factorial(list.size()); public List<T> next() { if (!hasNext()) { throw new NoSuchElementException(); }//w ww . ja va 2 s .co m List<T> permutation = new ArrayList<T>(list); int k = current; for (int j = 2; j <= list.size(); j++) { k /= j - 1; Collections.swap(permutation, (k % j), j - 1); } current++; return permutation; } public void remove() { throw new UnsupportedOperationException(); } public boolean hasNext() { return current < length; } }; } }; }
From source file:Main.java
public static Element nthElement(Element parent, String elementName, int index) { NodeList nds = parent.getElementsByTagName(elementName); if (nds.getLength() < index) throw new NoSuchElementException(); Element node = (Element) nds.item(index - 1); return node;/*from ww w . j a v a 2 s. c om*/ }