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:com.buaa.cfs.fs.AbstractFileSystem.java

/**
 * The specification of this method matches that of {@link FileContext#listStatus(Path)} except that Path f must be
 * for this file system.//from   w  w  w  .  j  a  va2s.  co  m
 */
public RemoteIterator<FileStatus> listStatusIterator(final Path f)
        throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
    return new RemoteIterator<FileStatus>() {
        private int i = 0;
        private FileStatus[] statusList = listStatus(f);

        @Override
        public boolean hasNext() {
            return i < statusList.length;
        }

        @Override
        public FileStatus next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            return statusList[i++];
        }
    };
}

From source file:com.cloudbees.plugins.credentials.CredentialsProvider.java

/**
 * Returns a lazy {@link Iterable} of all the {@link CredentialsStore} instances contributing credentials to the
 * supplied object.//from   w ww  .j  a va2 s  .  co m
 *
 * @param context the {@link Item} or {@link ItemGroup} or {@link User} to get the {@link CredentialsStore}s of.
 * @return a lazy {@link Iterable} of all {@link CredentialsStore} instances.
 * @since 1.8
 */
public static Iterable<CredentialsStore> lookupStores(final ModelObject context) {
    final ExtensionList<CredentialsProvider> providers = all();
    return new Iterable<CredentialsStore>() {
        public Iterator<CredentialsStore> iterator() {
            return new Iterator<CredentialsStore>() {
                private ModelObject current = context;
                private Iterator<CredentialsProvider> iterator = providers.iterator();
                private CredentialsStore next;

                public boolean hasNext() {
                    if (next != null) {
                        return true;
                    }
                    while (current != null) {
                        while (iterator.hasNext()) {
                            CredentialsProvider p = iterator.next();
                            if (!p.isEnabled(context)) {
                                continue;
                            }
                            next = p.getStore(current);
                            if (next != null) {
                                return true;
                            }
                        }
                        // now walk up the model object tree
                        // TODO make this an extension point perhaps ContextResolver could help
                        if (current instanceof Item) {
                            current = ((Item) current).getParent();
                            iterator = providers.iterator();
                        } else if (current instanceof User) {
                            Jenkins jenkins = Jenkins.getActiveInstance();
                            Authentication a;
                            if (jenkins.hasPermission(USE_ITEM) && current == User.current()) {
                                // this is the fast path for the 99% of cases
                                a = Jenkins.getAuthentication();
                            } else {
                                try {
                                    a = ((User) current).impersonate();
                                } catch (UsernameNotFoundException e) {
                                    a = null;
                                }
                            }
                            if (current == User.current() && jenkins.getACL().hasPermission(a, USE_ITEM)) {
                                current = jenkins;
                                iterator = providers.iterator();
                            } else {
                                current = null;
                            }
                        } else if (current instanceof Jenkins) {
                            // escape
                            current = null;
                        } else if (current instanceof ComputerSet) {
                            current = Jenkins.getActiveInstance();
                            iterator = providers.iterator();
                        } else if (current instanceof Computer) {
                            current = Jenkins.getActiveInstance();
                            iterator = providers.iterator();
                        } else if (current instanceof Node) {
                            current = Jenkins.getActiveInstance();
                            iterator = providers.iterator();
                        } else {
                            // fall back to Jenkins as the ultimate parent of everything else
                            current = Jenkins.getActiveInstance();
                            iterator = providers.iterator();
                        }
                    }
                    return false;
                }

                public CredentialsStore next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    try {
                        return next;
                    } finally {
                        next = null;
                    }
                }

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

From source file:jp.terasoluna.fw.file.dao.standard.AbstractFileLineIterator.java

/**
 * ???<br>//from w  w  w . jav  a2s  .c om
 * ?????????? ?????????<br>
 * ????????????????<br>
 * ??????????<br>
 * ??????????<br>
 * @throws FileException ???????
 */
private void buildTrailerQueue() {
    if (0 < trailerLineCount) {
        // ??
        trailerQueue = new ArrayBlockingQueue<String>(trailerLineCount);

        // ???
        for (int i = 0; i < trailerLineCount; i++) {
            if (!hasNext()) {
                throw new FileException("The data which can be acquired doesn't exist.",
                        new NoSuchElementException(), fileName);
            }
            try {
                trailerQueue.add(lineReader.readLine());
            } catch (FileException e) {
                throw new FileException("Error occurred by reading processing of a File.", e, fileName);
            }
        }
    }
}

From source file:jp.terasoluna.fw.file.dao.standard.AbstractFileLineIterator.java

/**
 * ??????<br>/*w w w  .  jav  a2  s . c om*/
 * @param skipLines ???
 */
@Override
public void skip(int skipLines) {
    for (int i = 0; i < skipLines; i++) {
        if (!hasNext()) {
            throw new FileLineException("The data which can be acquired doesn't exist.",
                    new NoSuchElementException(), fileName, currentLineCount + 1);
        }
        readLine();
        currentLineCount++;
    }
}

From source file:com.aliyun.odps.local.common.WareHouse.java

public Iterator<Object[]> readResourceTable(String project, String resource, final char inputColumnSeperator)
        throws IOException, OdpsException {
    if (!existsResource(project, resource)) {
        DownloadUtils.downloadResource(WareHouse.getInstance().getOdps(), getOdps().getDefaultProject(),
                resource, Constants.DEFAULT_DOWNLOAD_RECORD, inputColumnSeperator);
    }//from   w ww  .jav a 2s . c  om

    File tableResourceDir = getReourceFile(project, resource);
    if (!tableResourceDir.isDirectory()) {
        throw new OdpsException("Resource " + project + "." + resource
                + " is not a valid file Resource, because it is not a direcotry");
    }

    // LOG.info("Reading resource table from " +
    // tableResourceDir.getAbsolutePath());
    TableInfo tableInfo = getReferencedTable(project, resource);
    PartitionSpec partitionSpec = PartitionUtils.convert(tableInfo.getPartSpec());

    final List<File> datafiles = getDataFiles(project, tableInfo.getTableName(), partitionSpec,
            inputColumnSeperator);

    final Column[] schema = SchemaUtils.readSchema(getTableDir(project, tableInfo.getTableName())).getCols();

    return new Iterator<Object[]>() {
        CsvReader reader;
        Object[] current;
        boolean fetched;

        @Override
        public boolean hasNext() {
            if (fetched) {
                return current != null;
            }
            // Fetch new one
            try {
                fetch();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return current != null;

        }

        private void fetch() throws IOException {

            // first time
            if (reader == null) {
                if (datafiles.isEmpty()) {
                    current = null;
                    fetched = true;
                    return;
                }

                File f = datafiles.remove(0);
                reader = DownloadUtils.newCsvReader(f.getAbsolutePath(), inputColumnSeperator, encoding);
                reader.setSafetySwitch(false);
                current = read();
                fetched = true;
                return;
            }

            current = read();

            if (current == null && !datafiles.isEmpty()) {
                File f = datafiles.remove(0);
                reader = DownloadUtils.newCsvReader(f.getAbsolutePath(), inputColumnSeperator, encoding);
                reader.setSafetySwitch(false);

                current = read();

                fetched = true;
                return;
            }

            fetched = true;
        }

        @Override
        public Object[] next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            fetched = false;
            return current;
        }

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

        private Object[] read() throws IOException {
            Object[] result;
            if (!reader.readRecord()) {
                return null;
            }
            String[] vals = reader.getValues();
            if (vals == null || vals.length == 0) {
                result = null;
            } else {
                result = new Object[vals.length];
                for (int i = 0; i < vals.length; i++) {
                    result[i] = LocalRunUtils.fromString(schema[i].getType(), vals[i], "\\N");
                }
            }
            return result;
        }

    };
}

From source file:jef.tools.XMLUtils.java

/**
 * n(?)/*from  ww  w  .ja v  a 2 s. c  o  m*/
 * 
 * @param parent
 *            
 * @param elementName
 *            ??
 * @param index
 *            ??
 * @return DOM
 */
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 source file:io.minio.MinioClient.java

/**
 * Lists object information as {@code Iterable<Result><Item>>} in given bucket, prefix and recursive flag.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code Iterable<Result<Item>> myObjects = minioClient.listObjects("my-bucketname");
 * for (Result<Item> result : myObjects) {
 *   Item item = result.get();/*from   ww  w .  java 2s.co m*/
 *   System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
 * } }</pre>
 *
 * @param bucketName Bucket name.
 * @param prefix     Prefix string.  List objects whose name starts with `prefix`.
 * @param recursive when false, emulates a directory structure where each listing returned is either a full object
 *                  or part of the object's key up to the first '/'. All objects wit the same prefix up to the first
 *                  '/' will be merged into one entry.
 *
 * @return an iterator of Result Items.
 *
 * @see #listObjects(String bucketName)
 * @see #listObjects(String bucketName, String prefix)
 */
public Iterable<Result<Item>> listObjects(final String bucketName, final String prefix,
        final boolean recursive) {
    return new Iterable<Result<Item>>() {
        @Override
        public Iterator<Result<Item>> iterator() {
            return new Iterator<Result<Item>>() {
                private String lastObjectName;
                private ListBucketResult listBucketResult;
                private Result<Item> error;
                private Iterator<Item> itemIterator;
                private Iterator<Prefix> prefixIterator;
                private boolean completed = false;

                private synchronized void populate() {
                    String delimiter = "/";
                    if (recursive) {
                        delimiter = null;
                    }

                    String marker = null;
                    if (this.listBucketResult != null) {
                        if (delimiter != null) {
                            marker = listBucketResult.nextMarker();
                        } else {
                            marker = this.lastObjectName;
                        }
                    }

                    this.listBucketResult = null;
                    this.itemIterator = null;
                    this.prefixIterator = null;

                    try {
                        this.listBucketResult = listObjects(bucketName, marker, prefix, delimiter, null);
                    } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException
                            | IOException | InvalidKeyException | NoResponseException | XmlPullParserException
                            | ErrorResponseException | InternalException e) {
                        this.error = new Result<>(null, e);
                    } finally {
                        if (this.listBucketResult != null) {
                            this.itemIterator = this.listBucketResult.contents().iterator();
                            this.prefixIterator = this.listBucketResult.commonPrefixes().iterator();
                        } else {
                            this.itemIterator = new LinkedList<Item>().iterator();
                            this.prefixIterator = new LinkedList<Prefix>().iterator();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    if (this.completed) {
                        return false;
                    }

                    if (this.error == null && this.itemIterator == null && this.prefixIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.itemIterator.hasNext() && !this.prefixIterator.hasNext()
                            && this.listBucketResult.isTruncated()) {
                        populate();
                    }

                    if (this.error != null) {
                        return true;
                    }

                    if (this.itemIterator.hasNext()) {
                        return true;
                    }

                    if (this.prefixIterator.hasNext()) {
                        return true;
                    }

                    this.completed = true;
                    return false;
                }

                @Override
                public Result<Item> next() {
                    if (this.completed) {
                        throw new NoSuchElementException();
                    }

                    if (this.error == null && this.itemIterator == null && this.prefixIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.itemIterator.hasNext() && !this.prefixIterator.hasNext()
                            && this.listBucketResult.isTruncated()) {
                        populate();
                    }

                    if (this.error != null) {
                        this.completed = true;
                        return this.error;
                    }

                    if (this.itemIterator.hasNext()) {
                        Item item = this.itemIterator.next();
                        this.lastObjectName = item.objectName();
                        return new Result<>(item, null);
                    }

                    if (this.prefixIterator.hasNext()) {
                        Prefix prefix = this.prefixIterator.next();
                        Item item;
                        try {
                            item = new Item(prefix.prefix(), true);
                        } catch (XmlPullParserException e) {
                            // special case: ignore the error as we can't propagate the exception in next()
                            item = null;
                        }

                        return new Result<>(item, null);
                    }

                    this.completed = true;
                    throw new NoSuchElementException();
                }

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

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

/**
 * Selects a specific preference header.
 *
 * @param preferenceHeader/*  w ww . ja v  a2 s  .c om*/
 *         The preference header, which should be selected, as an instance of the class {@link
 *         PreferenceHeader}. The preference header may not be null. If the preference header
 *         does not belong to the activity, a {@link NoSuchElementException} will be thrown
 * @param parameters
 *         The parameters, which should be passed to the preference header's fragment, as an
 *         instance of the class {@link Bundle} or null, if the preference header's extras
 *         should be used instead
 */
public final void selectPreferenceHeader(@NonNull final PreferenceHeader preferenceHeader,
        @Nullable final Bundle parameters) {
    ensureNotNull(preferenceHeader, "The preference header may not be null");
    int position = getListAdapter().indexOf(preferenceHeader);

    if (position == -1) {
        throw new NoSuchElementException();
    }

    selectPreferenceHeader(position, parameters);
}

From source file:NavigableMap.java

/**
 * Returns the first (lowest) key currently in this map.
 * //from w ww .  j a va2  s  .  c o m
 * @return the first (lowest) key currently in this map.
 * @throws NoSuchElementException
 *           Map is empty.
 */
public K firstKey() {
    Node<K, V> n = findFirst();
    if (n == null)
        throw new NoSuchElementException();
    return n.key;
}

From source file:NavigableMap.java

/**
 * Returns the last (highest) key currently in this map.
 * //from   w ww.j  a v a2s . c o m
 * @return the last (highest) key currently in this map.
 * @throws NoSuchElementException
 *           Map is empty.
 */
public K lastKey() {
    Node<K, V> n = findLast();
    if (n == null)
        throw new NoSuchElementException();
    return n.key;
}