List of usage examples for java.lang UnsupportedOperationException UnsupportedOperationException
public UnsupportedOperationException()
From source file:Main.java
public static <E> Iterator<E> asIterator(final Enumeration<E> e) { return new Iterator<E>() { @Override/*from w w w . ja va 2 s . c o m*/ public boolean hasNext() { return e.hasMoreElements(); } @Override public E next() { return e.nextElement(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:Main.java
/** * Generate an iterator for an array/*w w w . j a v a 2 s. com*/ * * @param array * @return */ public static <T> Iterator<T> getIterator(final T[] array) { return new Iterator<T>() { private int i = 0; public boolean hasNext() { return i < array.length; } public T next() { return array[i++]; } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:Main.java
/** * replaces a list of files with another list of files, indicated by names * @param originalList/* w ww. jav a2 s.co m*/ * @param newList * @return */ public static void replaceFiles(ArrayList<String> originalList, ArrayList<String> newList) throws UnsupportedOperationException, OperationCanceledException { if (originalList.size() != newList.size()) throw new UnsupportedOperationException(); else { String name = null; for (int i = 0, size = originalList.size(); i < size; i++) { name = originalList.get(i); File f = new File(name); File newF = new File(newList.get(i)); if (f.exists() && newF.exists()) { if (f.delete()) { File temp = new File(name); newF.renameTo(temp); } else { throw new OperationCanceledException("Delete failed"); } } else { throw new UnsupportedOperationException("Wrong lists of file names"); } } } }
From source file:Main.java
public static XPath namespaceAwareXpath(final String prefix, final String nsURI) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); NamespaceContext ctx = new NamespaceContext() { @Override//from w w w . ja v a 2 s . c o m public String getNamespaceURI(String aPrefix) { if (aPrefix.equals(prefix)) return nsURI; else return null; } @Override public Iterator getPrefixes(String val) { throw new UnsupportedOperationException(); } @Override public String getPrefix(String uri) { throw new UnsupportedOperationException(); } }; xpath.setNamespaceContext(ctx); return xpath; }
From source file:Main.java
public static Iterable<Node> iterate(final NodeList nodeList) { return new Iterable<Node>() { @Override//from ww w.j a v a 2 s .co m public Iterator<Node> iterator() { return new Iterator<Node>() { int index = 0; @Override public void remove() { throw new UnsupportedOperationException(); } @Override public Node next() { return nodeList.item(index++); } @Override public boolean hasNext() { return index < nodeList.getLength(); } }; } }; }
From source file:Main.java
public static XPathExpression buildXPath(String path, Map<String, String> map) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); if (map != null) xpath.setNamespaceContext(new NamespaceContext() { public Iterator getPrefixes(String namespaceURI) { throw new UnsupportedOperationException(); }/*from www . j a va 2 s .c o m*/ public String getPrefix(String namespaceURI) { throw new UnsupportedOperationException(); } public String getNamespaceURI(String prefix) { Objects.requireNonNull(prefix); if (map.containsKey(prefix)) return map.get(prefix); return XMLConstants.NULL_NS_URI; } }); try { return xpath.compile(path); } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static <T> Iterable<T> replicate(final T value, final int count) { return new Iterable<T>() { @Override/*from w ww. j a v a2 s.c om*/ 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
/** * Converts a w3c DOM nodelist into an iterator. * @param nl the node list/* w ww . j a v a2 s . com*/ * @return the iterator wrapping the list of DOM nodes */ public static Iterator nodeList2Iterator(final NodeList nl) { final int[] i = new int[] { 0 }; return new Iterator() { public boolean hasNext() { return i[0] < nl.getLength(); } public Object next() { return nl.item(i[0]++); } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:Main.java
static <T> Iterator<T> cycle(final Iterable<T> iterable) { return new Iterator<T>() { Iterator<T> iterator = Collections.<T>emptySet().iterator(); @Override//from w w w. jav a 2 s .co m public boolean hasNext() { return true; } @Override public T next() { if (!iterator.hasNext()) { iterator = iterable.iterator(); } return iterator.next(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
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(); }/* ww w. j a v a 2s.c om*/ 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; } }; } }; }