public static <T> Iterator<T> iterator(Class<T> class1, final Object value) { if (value == null) { return Collections.EMPTY_LIST.iterator(); } if (Boon.isArray(value)) { final int length = Arry.len(value); return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < length; } @Override public T next() { if (i >= length) throw new NoSuchElementException("No more properties"); T next = (T) BeanUtils.idx(value, i); i++; return next; } @Override public void remove() {} }; } else if (Typ.isCollection(value.getClass())) { return ((Collection<T>) value).iterator(); } else { return (Iterator<T>) Collections.singleton(value).iterator(); } }
@SuppressWarnings("unchecked") public SpectrumIterator() { try { it = new Ms2QueryIterator(); } catch (FileNotFoundException e) { // do nothing it = Collections.EMPTY_LIST.iterator(); } }
/** * Iterator type that can combine multiple iterators into one logical iterator. * * @author Abe White */ public abstract class MultiIterator implements Iterator { private static final int PAST_END = -1; private Iterator _itr = Collections.EMPTY_LIST.iterator(); private Iterator _last = null; private int _index = 0; public boolean hasNext() { setIterator(); return _itr.hasNext(); } public Object next() { setIterator(); return _itr.next(); } public void remove() { setIterator(); _last.remove(); } /** * Implement this method to return the iterator at the <code>index</code>th position in the list * of iterators to process. Indexing starts at 0 and will proceed upward linearly, never repeating * the same index. Return null to indicate that there are no more iterators to process. You may * return null to index 0, in which case this iterator will act like an iterator over an empty * collection. */ protected abstract Iterator newIterator(int index); /** Sets internal iterator to the iterator to use for processing. */ private void setIterator() { // if already iterated through all, nothing to do if (_index == PAST_END) return; // always remove from the last iterator used _last = _itr; // find next iterator with a value Iterator newItr = _itr; while (newItr != null && !newItr.hasNext()) newItr = newIterator(_index++); // switch current iter if needed if (newItr != null && _itr != newItr) _itr = newItr; else if (newItr == null) _index = PAST_END; } }
/** * Assign the right TARGET if found. * * @param iArgs Parameters to bind * @return true if the target has been recognized, otherwise false */ protected boolean assignTarget(final Map<Object, Object> iArgs) { parameters = iArgs; if (parsedTarget == null) return true; if (iArgs != null && iArgs.size() > 0 && compiledFilter != null) compiledFilter.bindParameters(iArgs); if (target == null) { if (parsedTarget.getTargetClasses() != null) searchInClasses(); else if (parsedTarget.getTargetIndexValues() != null) { target = new IndexValuesIterator( parsedTarget.getTargetIndexValues(), parsedTarget.isTargetIndexValuesAsc()); } else if (parsedTarget.getTargetClusters() != null) searchInClusters(); else if (parsedTarget.getTargetRecords() != null) { if (!lazyIteration && parsedTarget.getTargetQuery() != null) { // EXECUTE THE QUERY TO ALLOW DISTRIB EXECUTION target = ((Iterable<? extends OIdentifiable>) getDatabase() .command(new OCommandSQL(parsedTarget.getTargetQuery())) .execute(iArgs)) .iterator(); } else if (parsedTarget.getTargetRecords() instanceof OIterableRecordSource) { target = ((OIterableRecordSource) parsedTarget.getTargetRecords()).iterator(iArgs); } else { target = parsedTarget.getTargetRecords().iterator(); } } else if (parsedTarget.getTargetVariable() != null) { final Object var = getContext().getVariable(parsedTarget.getTargetVariable()); if (var == null) { target = Collections.EMPTY_LIST.iterator(); return true; } else if (var instanceof OIdentifiable) { final ArrayList<OIdentifiable> list = new ArrayList<OIdentifiable>(); list.add((OIdentifiable) var); target = list.iterator(); } else if (var instanceof Iterable<?>) target = ((Iterable<? extends OIdentifiable>) var).iterator(); } else return false; } return true; }
synchronized Iterator<Mutation> getFeatures(String trackKey, String chr, int start, int end) throws IOException { if (currentRange == null || !currentRange.contains(chr, start, end)) { Iterator<Feature> features = tribbleFeatureSource.getFeatures(chr, start, end); while (features.hasNext()) { Mutation feat = (Mutation) features.next(); String thisKey = feat.getSampleId(); List<Mutation> keyFeatures = featureMap.get(thisKey); if (keyFeatures == null) { keyFeatures = new ArrayList<Mutation>(); featureMap.put(thisKey, keyFeatures); } keyFeatures.add(feat); currentRange = new Range(chr, start, end); } } List<Mutation> featureList = featureMap.get(trackKey); return featureList == null ? Collections.EMPTY_LIST.iterator() : featureList.iterator(); }
public ListIterator childrenFolded() { if (isFolded()) { return Collections.EMPTY_LIST.listIterator(); } return childrenUnfolded(); }
public ListIterator childrenUnfolded() { return children != null ? children.listIterator() : Collections.EMPTY_LIST.listIterator(); }
/** * return a sub list of this list * * @param fromIndex start index * @param toIndex end index * @return a list */ public List subList(int fromIndex, int toIndex) { if (this.collection != null) return ((List) this.collection).subList(fromIndex, toIndex); return Collections.EMPTY_LIST.subList(fromIndex, toIndex); }
/** * return a list iterator over the list * * @param index * @return an instance of ListIterator */ public ListIterator listIterator(int index) { if (this.collection != null) return ((List) this.collection).listIterator(index); return Collections.EMPTY_LIST.listIterator(index); }