當前位置: 首頁>>代碼示例>>Java>>正文


Java Iterator類代碼示例

本文整理匯總了Java中java.util.Iterator的典型用法代碼示例。如果您正苦於以下問題:Java Iterator類的具體用法?Java Iterator怎麽用?Java Iterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Iterator類屬於java.util包,在下文中一共展示了Iterator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: iterator

import java.util.Iterator; //導入依賴的package包/類
/**
 * page iterator
 *
 * @return iterator
 */
public Iterator<Page> iterator() {
    return new Iterator<Page>() {
        @Override
        public boolean hasNext() {
            return mCurrentPage < mPages;
        }

        @Override
        public Page next() {
            if (hasNext()) {
                return new Page(mCurrentPage++);
            }
            return null;
        }

        @Override
        public void remove() {
        }
    };
}
 
開發者ID:cleaninsights,項目名稱:cleaninsights-android-sdk,代碼行數:26,代碼來源:TrackerBulkURLWrapper.java

示例2: getRealm

import java.util.Iterator; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T getRealm(Class<? extends Realm> realmType){
	RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
	if(!CollectionUtils.isEmpty(securityManager.getRealms())){
		for(Iterator<Realm> it = securityManager.getRealms().iterator(); it.hasNext();){
			Realm realm = it.next();
			if(realm.getClass().equals(realmType)){
				return (T) realm;
			}
		}
	}
	return null;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:14,代碼來源:ShiroUtils.java

示例3: matchCredentials

import java.util.Iterator; //導入依賴的package包/類
/**
 * Find matching {@link Credentials credentials} for the given authentication scope.
 *
 * @param map the credentials hash map
 * @param token the {@link AuthScope authentication scope}
 * @return the credentials 
 * 
 */
private static Credentials matchCredentials(final HashMap map, final AuthScope authscope) {
    // see if we get a direct hit
    Credentials creds = (Credentials)map.get(authscope);
    if (creds == null) {
        // Nope.
        // Do a full scan
        int bestMatchFactor  = -1;
        AuthScope bestMatch  = null;
        Iterator items = map.keySet().iterator();
        while (items.hasNext()) {
            AuthScope current = (AuthScope)items.next();
            int factor = authscope.match(current);
            if (factor > bestMatchFactor) {
                bestMatchFactor = factor;
                bestMatch = current;
            }
        }
        if (bestMatch != null) {
            creds = (Credentials)map.get(bestMatch);
        }
    }
    return creds;
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:32,代碼來源:HttpState.java

示例4: iterator

import java.util.Iterator; //導入依賴的package包/類
@Override
public Iterator<V> iterator() {
    return new MapIterator<V>() {
        @Override
        public V next() {
            if (mapEntry == null) {
                throw new NoSuchElementException();
            }
            
            V value = readValue(mapEntry.getValue());
            mapEntry = null;
            return value;
        }

        @Override
        public void remove() {
            if (mapEntry == null) {
                throw new IllegalStateException();
            }
            map.remove(mapEntry.getKey(), mapEntry.getValue());
            mapEntry = null;
        }
    };
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:25,代碼來源:AbstractCacheMap.java

示例5: a

import java.util.Iterator; //導入依賴的package包/類
public synchronized void a(String[] strArr) {
    for (int size = this.j.size() - 1; size >= 0; size--) {
        for (CharSequence equals : strArr) {
            if (TextUtils.equals(((e) this.j.get(size)).a, equals)) {
                this.j.remove(size);
                break;
            }
        }
    }
    Iterator it = this.j.iterator();
    int i = 0;
    while (it.hasNext()) {
        e eVar = (e) it.next();
        i = eVar.b > i ? eVar.b : i;
    }
    for (int i2 = 0; i2 < strArr.length; i2++) {
        a(new e(strArr[i2], (strArr.length + i) - i2));
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:Fallback.java

示例6: getProblem

import java.util.Iterator; //導入依賴的package包/類
/**
 * Creates a support vector problem for the LibSVM.
 * 
 * @throws UserError
 */
private svm_problem getProblem(ExampleSet exampleSet) throws UserError {
	log("Creating LibSVM problem.");
	FastExample2SparseTransform ripper = new FastExample2SparseTransform(exampleSet);
	int nodeCount = 0;
	svm_problem problem = new svm_problem();
	problem.l = exampleSet.size();
	problem.y = new double[exampleSet.size()];
	problem.x = new svm_node[exampleSet.size()][];
	Iterator<Example> i = exampleSet.iterator();
	Attribute label = exampleSet.getAttributes().getLabel();
	int j = 0;
	while (i.hasNext()) {
		Example e = i.next();
		problem.x[j] = makeNodes(e, ripper);
		problem.y[j] = e.getValue(label);
		nodeCount += problem.x[j].length;
		j++;
	}
	log("Created " + nodeCount + " nodes for " + j + " examples.");
	return problem;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:27,代碼來源:LibSVMLearner.java

示例7: createBlockingResultSet

import java.util.Iterator; //導入依賴的package包/類
private ResultSet<String> createBlockingResultSet(BlockingQueue<String> queue, Supplier<Boolean> finished) {
  AtomicReference<String> ref = new AtomicReference<>();
  AtomicInteger sizeref = new AtomicInteger(0);
  Iterator<String> blockingIterator = new Iterator<String>() {
    @Override
    public boolean hasNext() {
      if (ref.get() != null) return true;
      while (!finished.get()) {
        if (ref.get() != null) return true;
        try {
          ref.set(queue.poll(1000, TimeUnit.MILLISECONDS));
        } catch (InterruptedException e) {
          throw new RuntimeException(e);
        }
      }
      return ref.get() != null;
    }

    @Override
    public String next() {
      sizeref.incrementAndGet();
      return ref.getAndSet(null);
    }
  };
  return createResultSet(blockingIterator);
}
 
開發者ID:mnemonic-no,項目名稱:common-services,代碼行數:27,代碼來源:ServiceMessageHandlerTest.java

示例8: toString

import java.util.Iterator; //導入依賴的package包/類
@Override
public String toString(){
	StringBuilder sb = new StringBuilder();
	sb.append(this.getName());
	Iterator<String> attNames = this._attrs.keySet().iterator();
	while(attNames.hasNext()){
		String attName = attNames.next();
		ArrayList<String> attValues = this._attrs.get(attName);
		sb.append("|");
		sb.append(attName);
		for(String attValue : attValues){
			sb.append(":");
			sb.append(attValue);
		}
	}
	return sb.toString();
}
 
開發者ID:justhalf,項目名稱:weak-semi-crf-naacl2016,代碼行數:18,代碼來源:AttributedWord.java

示例9: checkElementNumber

import java.util.Iterator; //導入依賴的package包/類
/**
 * Checks number of elements within a iterator.
 * @param it iterator to check
 * @param n number of elements found
 * @return true if n equals elements number in iterator, otherwise false.
 */
public static boolean checkElementNumber (Iterator<?> it, int n)
{
   int i = 0;      
   while (it.hasNext ())
   {
      if (it.next () == null)
      {
         return false;
      }
      i++;
   }
   return (i == n);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:CheckIterator.java

示例10: combineOrdered

import java.util.Iterator; //導入依賴的package包/類
/**
 * Returns a hash code, having the same bit length as each of the input hash codes, that combines
 * the information of these hash codes in an ordered fashion. That is, whenever two equal hash
 * codes are produced by two calls to this method, it is <i>as likely as possible</i> that each
 * was computed from the <i>same</i> input hash codes in the <i>same</i> order.
 *
 * @throws IllegalArgumentException if {@code hashCodes} is empty, or the hash codes do not all
 *     have the same bit length
 */
public static HashCode combineOrdered(Iterable<HashCode> hashCodes) {
  Iterator<HashCode> iterator = hashCodes.iterator();
  checkArgument(iterator.hasNext(), "Must be at least 1 hash code to combine.");
  int bits = iterator.next().bits();
  byte[] resultBytes = new byte[bits / 8];
  for (HashCode hashCode : hashCodes) {
    byte[] nextBytes = hashCode.asBytes();
    checkArgument(
        nextBytes.length == resultBytes.length, "All hashcodes must have the same bit length.");
    for (int i = 0; i < nextBytes.length; i++) {
      resultBytes[i] = (byte) (resultBytes[i] * 37 ^ nextBytes[i]);
    }
  }
  return HashCode.fromBytesNoCopy(resultBytes);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:Hashing.java

示例11: copyProbandListEntryTagValueOutToIn

import java.util.Iterator; //導入依賴的package包/類
public static void copyProbandListEntryTagValueOutToIn(ProbandListEntryTagValueInVO in, ProbandListEntryTagValueOutVO out) {
	if (in != null && out != null) {
		ProbandListEntryOutVO listEntryVO = out.getListEntry();
		ProbandListEntryTagOutVO tagVO = out.getTag();
		Collection<InputFieldSelectionSetValueOutVO> tagValueVOs = out.getSelectionValues();
		in.setBooleanValue(out.getBooleanValue());
		in.setDateValue(out.getDateValue());
		in.setTimeValue(out.getTimeValue());
		in.setFloatValue(out.getFloatValue());
		in.setId(out.getId());
		in.setListEntryId(listEntryVO == null ? null : listEntryVO.getId());
		in.setLongValue(out.getLongValue());
		ArrayList<Long> selectionValueIds = new ArrayList<Long>(tagValueVOs.size());
		Iterator<InputFieldSelectionSetValueOutVO> tagValueVOsIt = tagValueVOs.iterator();
		while (tagValueVOsIt.hasNext()) {
			selectionValueIds.add(tagValueVOsIt.next().getId());
		}
		in.setSelectionValueIds(selectionValueIds);
		in.setTagId(tagVO == null ? null : tagVO.getId());
		in.setTextValue(out.getTextValue());
		in.setTimestampValue(out.getTimestampValue());
		in.setInkValues(out.getInkValues());
		in.setVersion(out.getVersion());
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:26,代碼來源:ProbandListEntryTagValueBean.java

示例12: obfuscateCriterions

import java.util.Iterator; //導入依賴的package包/類
private static CriteriaOutVO obfuscateCriterions(CriteriaOutVO criteriaVO) {
	if (criteriaVO != null) {
		CriteriaOutVO result = new CriteriaOutVO(criteriaVO);
		ArrayList<CriterionOutVO> obfuscatedCriterions = new ArrayList<CriterionOutVO>();
		Iterator<CriterionOutVO> criterionsIt = criteriaVO.getCriterions().iterator();
		while (criterionsIt.hasNext()) {
			CriterionOutVO obfuscatedCriterion = new CriterionOutVO(criterionsIt.next());
			obfuscatedCriterion.setCriteria(result);
			CriterionPropertyVO property = obfuscatedCriterion.getProperty();
			if (property != null && OmittedFields.isOmitted(property.getProperty())) {
				obfuscatedCriterion.setStringValue(OmittedFields.OBFUSCATED_STRING);
			}
			obfuscatedCriterions.add(obfuscatedCriterion);
		}
		result.setCriterions(obfuscatedCriterions);
		return result;
	}
	return null;
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:20,代碼來源:SearchServiceImpl.java

示例13: listWriters

import java.util.Iterator; //導入依賴的package包/類
/**
 * List any valid writers that can be found.
 * 
 * @param loader Loader to search for classes. If <code>null</code>, the system class
 *   loader is used.
 * 
 * @return A sorted list of writer names.
 */
public static String[] listWriters(URLClassLoader loader) {
	
	// Create structures
	Set<String> urlSet = SystemUtil.findSubPackages(PACKAGE_NAME, loader.getURLs(), true);
	
	Iterator<String> setIter = urlSet.iterator();
	
	while (setIter.hasNext()) {
		String url = setIter.next();
		
		try {
			getWriterClass(url, loader);
			
		} catch (Throwable ex) {
			setIter.remove();
		}
	}
	
	// Sort and return
	String[] writers = urlSet.toArray(new String[0]);
	Arrays.sort(writers);
	
	return writers;
}
 
開發者ID:paudano,項目名稱:kestrel,代碼行數:33,代碼來源:VariantWriter.java

示例14: parse

import java.util.Iterator; //導入依賴的package包/類
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().before(Version.V_1_3_0)) {
        throw new IllegalArgumentException("type="+CONTENT_TYPE+" is not supported on indices created before version 1.3.0. Is your cluster running multiple datanode versions?");
    }
    
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }

    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            builder.enabled(nodeBooleanValue(fieldNode));
            iterator.remove();
        }
    }
    return builder;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:23,代碼來源:FieldNamesFieldMapper.java

示例15: forEachButLast

import java.util.Iterator; //導入依賴的package包/類
/**
 * Executes the given closure on each but the last element in the iterator.
 * <p>
 * If the input iterator is null no change is made.
 *
 * @param <E> the type of object the {@link Iterator} contains
 * @param iterator  the iterator to get the input from, may be null
 * @param closure  the closure to perform, may not be null
 * @return the last element in the iterator, or null if iterator is null or empty
 * @throws NullPointerException if closure is null
 * @since 4.1
 */
public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) {
    if (closure == null) {
        throw new NullPointerException("Closure must not be null.");
    }
    if (iterator != null) {
        while (iterator.hasNext()) {
            final E element = iterator.next();
            if (iterator.hasNext()) {
                closure.execute(element);
            } else {
                return element;
            }
        }
    }
    return null;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:29,代碼來源:IteratorUtils.java


注:本文中的java.util.Iterator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。