Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

In this page you can find the example usage for java.util NoSuchElementException NoSuchElementException.

Prototype

public NoSuchElementException() 

Source Link

Document

Constructs a NoSuchElementException with null as its error message string.

Usage

From source file:UnifyHash.java

public Iterator iterateHashCode(final int hash) {
    ///#ifdef JDK12
    cleanUp();//from  w ww. j  a va  2s.c o  m
    ///#endif
    return new Iterator() {
        private int known = modCount;
        private Bucket nextBucket = buckets[Math.abs(hash % buckets.length)];
        private Object nextVal;

        {
            internalNext();
        }

        private void internalNext() {
            while (nextBucket != null) {
                if (nextBucket.hash == hash) {
                    nextVal = nextBucket.get();
                    if (nextVal != null)
                        return;
                }

                nextBucket = nextBucket.next;
            }
        }

        public boolean hasNext() {
            return nextBucket != null;
        }

        public Object next() {
            if (known != modCount)
                throw new ConcurrentModificationException();
            if (nextBucket == null)
                throw new NoSuchElementException();
            Object result = nextVal;
            nextBucket = nextBucket.next;
            internalNext();
            return result;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.cinchapi.concourse.util.ConcurrentSkipListMultiset.java

@Override
public Iterator<T> iterator() {
    return new Iterator<T>() {
        // This implementation is adapted from that in Guava's
        // MultisetIteratorImpl class

        private boolean canRemove;
        private Entry<T> currentEntry;

        private final Iterator<ConcurrentSkipListMultiset<T>.SkipListEntry> entryIterator = ConcurrentSkipListMultiset.this.backing
                .values().iterator();// ww w .j  a v a  2  s. c  o  m
        /** Count of subsequent elements equal to current element */
        private int laterCount;
        private final Multiset<T> multiset = ConcurrentSkipListMultiset.this;
        /** Count of all elements equal to current element */
        private int totalCount;

        @Override
        public boolean hasNext() {
            return laterCount > 0 || entryIterator.hasNext();
        }

        @Override
        public T next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            if (laterCount == 0) {
                currentEntry = entryIterator.next();
                totalCount = laterCount = currentEntry.getCount();
            }
            laterCount--;
            canRemove = true;
            return currentEntry.getElement();
        }

        @Override
        public void remove() {
            Preconditions.checkState(canRemove, "no calls to next() since the last call to remove()");
            if (totalCount == 1) {
                entryIterator.remove();
            } else {
                multiset.remove(currentEntry.getElement());
            }
            totalCount--;
            canRemove = false;
        }
    };
}

From source file:MicroMap.java

/**
 * @see java.util.Map#entrySet()//from   ww w  .j av  a  2  s . c  o m
 */
public Set<Entry<K, V>> entrySet() {
    return new AbstractSet<Entry<K, V>>() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
            return new Iterator<Entry<K, V>>() {
                public boolean hasNext() {
                    return index < MicroMap.this.size();
                }

                public Entry<K, V> next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    index++;

                    return new Map.Entry<K, V>() {
                        public K getKey() {
                            return key;
                        }

                        public V getValue() {
                            return value;
                        }

                        public V setValue(final V value) {
                            final V oldValue = MicroMap.this.value;

                            MicroMap.this.value = value;

                            return oldValue;
                        }
                    };
                }

                public void remove() {
                    clear();
                }

                int index = 0;
            };
        }

        @Override
        public int size() {
            return MicroMap.this.size();
        }
    };
}

From source file:com.daveoxley.cbus.Response.java

public Iterator<String> iterator() {
    return new Iterator<String>() {
        private int index = 0;

        public boolean hasNext() {
            synchronized (iterator_mutex) {
                while (array_response == null || (index >= array_response.size() && !response_generated)) {
                    try {
                        iterator_mutex.wait();
                    } catch (InterruptedException ie) {
                    }//from  w w w .java  2  s  . com
                }

                if (index < array_response.size())
                    return true;

                if (response_generated)
                    return false;

                throw new IllegalStateException("Impossible");
            }
        }

        public String next() {
            synchronized (iterator_mutex) {
                if (index >= array_response.size())
                    throw new NoSuchElementException();

                return array_response.get(index++);
            }
        }

        public void remove() {
            throw new UnsupportedOperationException("remove not supported");
        }
    };
}

From source file:BoundedPriorityQueue.java

/**
 * Returns and removes the highest scoring element in
 * this queue, throwing an exception if it is empty.
 *
 * <p>This method differs from {@link #poll()} only in
 * that it throws an exception for an empty queue
 * instead of returning {@code null}./*from  w w  w  . ja v  a2 s .  co m*/
 *
 * @return The highest scoring element in this queue.
 */
public E remove() {
    E result = poll();
    if (result == null)
        throw new NoSuchElementException();
    return result;
}

From source file:net.javacoding.queue.DiskQueue.java

/**
 *
 *///  w ww .  j  av a2 s  .  c o  m
private void loadHead() {
    try {
        if (!isInitialized) {
            lazyInitialize();
        }
        headObject = headStream.readObject();
    } catch (IOException e) {
        e.printStackTrace();
        throw new NoSuchElementException();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new NoSuchElementException();
    }
}

From source file:com.trenako.values.DeliveryDate.java

private static Iterable<Integer> inverseRange(final int start, final int end) {
    return new Iterable<Integer>() {
        @Override/*from  ww w .  j av a2 s  . c  o  m*/
        public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private int current = end;

                @Override
                public boolean hasNext() {
                    return current >= start;
                }

                @Override
                public Integer next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    int n = current;
                    current--;
                    return n;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:at.molindo.utils.reflect.ClassUtils.java

/**
 * @return an {@link Iterator} over the {@link Class} hierarchy
 * //w  ww .  ja v a 2  s  .c  o  m
 * @see Class#getSuperclass()
 */
public static Iterator<Class<?>> hierarchy(Class<?> cls) {
    if (cls == null) {
        return IteratorUtils.empty();
    }

    class ClassHierarchyIterator implements Iterator<Class<?>> {

        private Class<?> _next;

        private ClassHierarchyIterator(Class<?> cls) {
            if (cls == null) {
                throw new NullPointerException("cls");
            }
            _next = cls;
        }

        @Override
        public boolean hasNext() {
            return _next != null;
        }

        @Override
        public Class<?> next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }

            Class<?> next = _next;
            _next = _next.getSuperclass();
            return next;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("read-only");
        }
    }

    return new ClassHierarchyIterator(cls);
}

From source file:com.telefonica.euro_iaas.sdc.pupperwrapper.services.tests.FileAccessServiceTest.java

@Test(expected = NoSuchElementException.class)
public void generateManifest_node_not_exists() throws IOException {
    when(catalogManager.getNode("nodenotexists")).thenThrow(new NoSuchElementException());

    fileAccessService.generateManifestFile("nodenotexists");
}

From source file:com.telefonica.euro_iaas.sdc.pupperwrapper.services.tests.ActionsServiceTest.java

@Test(expected = NoSuchElementException.class)
public void uninstallNodeNotExists() {

    when(catalogManagerMongo.getNode("nodenoexists")).thenThrow(new NoSuchElementException());

    actionsService.action(Action.UNINSTALL, "groupnoexists", "nodenoexists", "testSoft", "1.0.0",
            attributeList);//from  w  w  w . ja va 2  s . c o m

    verify(catalogManagerMongo, times(1)).getNode(anyString());
}