Java Code Examples for java.util.Iterator#hasNext()
The following examples show how to use
java.util.Iterator#hasNext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServerProvider.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static boolean loadProviderAsService() { Iterator<HttpServerProvider> i = ServiceLoader.load(HttpServerProvider.class, ClassLoader.getSystemClassLoader()) .iterator(); for (;;) { try { if (!i.hasNext()) return false; provider = i.next(); return true; } catch (ServiceConfigurationError sce) { if (sce.getCause() instanceof SecurityException) { // Ignore the security exception, try the next provider continue; } throw sce; } } }
Example 2
Source File: SCMContainerManager.java From hadoop-ozone with Apache License 2.0 | 6 votes |
/** * Returns the container ID's matching with specified owner. * @param pipeline * @param owner * @return NavigableSet<ContainerID> */ private NavigableSet<ContainerID> getContainersForOwner( Pipeline pipeline, String owner) throws IOException { NavigableSet<ContainerID> containerIDs = pipelineManager.getContainersInPipeline(pipeline.getId()); Iterator<ContainerID> containerIDIterator = containerIDs.iterator(); while (containerIDIterator.hasNext()) { ContainerID cid = containerIDIterator.next(); try { if (!getContainer(cid).getOwner().equals(owner)) { containerIDIterator.remove(); } } catch (ContainerNotFoundException e) { LOG.error("Could not find container info for container id={} {}", cid, e); containerIDIterator.remove(); } } return containerIDs; }
Example 3
Source File: PolicyInformation.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Set the attribute value. */ @SuppressWarnings("unchecked") // Checked with instanceof public void set(String name, Object obj) throws IOException { if (name.equalsIgnoreCase(ID)) { if (obj instanceof CertificatePolicyId) policyIdentifier = (CertificatePolicyId)obj; else throw new IOException("Attribute value must be instance " + "of CertificatePolicyId."); } else if (name.equalsIgnoreCase(QUALIFIERS)) { if (policyIdentifier == null) { throw new IOException("Attribute must have a " + "CertificatePolicyIdentifier value before " + "PolicyQualifierInfo can be set."); } if (obj instanceof Set) { Iterator<?> i = ((Set<?>)obj).iterator(); while (i.hasNext()) { Object obj1 = i.next(); if (!(obj1 instanceof PolicyQualifierInfo)) { throw new IOException("Attribute value must be a" + "Set of PolicyQualifierInfo objects."); } } policyQualifiers = (Set<PolicyQualifierInfo>) obj; } else { throw new IOException("Attribute value must be of type Set."); } } else { throw new IOException("Attribute name [" + name + "] not recognized by PolicyInformation"); } }
Example 4
Source File: RequestBarrier.java From journalkeeper with Apache License 2.0 | 6 votes |
/** * 清理所有超时的请求 */ public void evict() { Iterator<Map.Entry<Integer, ResponseFuture>> iterator = futures.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Integer, ResponseFuture> entry = iterator.next(); ResponseFuture future = entry.getValue(); long timeout = future.getBeginTime() + future.getTimeout(); if (timeout <= System.currentTimeMillis() && future.getResponse() == null) { iterator.remove(); if (future.release()) { try { future.onFailed(TransportException.RequestTimeoutException .build(IpUtil.toAddress(future.getTransport().remoteAddress()))); } catch (Throwable e) { logger.error("clear timeout response exception", e); } } logger.info("remove timeout request id={} begin={} timeout={}", future.getRequestId(), future.getBeginTime(), timeout); } } }
Example 5
Source File: GroupConfigBundle.java From julongchain with Apache License 2.0 | 6 votes |
/** * 当另一个集合存在相应元素时,则是否相同 * * @param map * @param otherMap * @return */ private boolean itemSameInOtherWhenExists(Map<String, ? extends IOrganizationConfig> map, Map<String, ? extends IOrganizationConfig> otherMap) throws ValidateException { if (map != null && map.size() > 0) { if (otherMap != null && otherMap.size() > 0) { Iterator<? extends Map.Entry<String, ? extends IOrganizationConfig>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, ? extends IOrganizationConfig> entry = iterator.next(); String orgName = entry.getKey(); IOrganizationConfig organizationConfig = entry.getValue(); IOrganizationConfig otherOrganizationConfig = otherMap.get(orgName); if (otherOrganizationConfig != null && !Objects.equals(organizationConfig.getMspId(), otherOrganizationConfig.getMspId())) { //如果要比较的Map也存在对应的组织,但MSP却不相同,则抛出异常 throw new ValidateException("Different org msp: " + orgName + "," + organizationConfig .getMspId() + "," + otherOrganizationConfig.getMspId()); } } } } return true; }
Example 6
Source File: ImageCache.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Entry getEntry(Object key, GraphicsConfiguration config, int w, int h, Object[] args) { Entry entry; Iterator<SoftReference<Entry>> iter = entries.listIterator(); while (iter.hasNext()) { SoftReference<Entry> ref = iter.next(); entry = ref.get(); if (entry == null) { // SoftReference was invalidated, remove the entry iter.remove(); } else if (entry.equals(config, w, h, args)) { // Put most recently used entries at the head iter.remove(); entries.addFirst(ref); return entry; } } // Entry doesn't exist entry = new Entry(config, w, h, args); if (entries.size() >= maxCount) { entries.removeLast(); } entries.addFirst(new SoftReference<Entry>(entry)); return entry; }
Example 7
Source File: HashTrieMap.java From swim with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HashTrieMap<?, ?>) { final HashTrieMap<K, V> that = (HashTrieMap<K, V>) other; if (size() == that.size()) { final Iterator<Entry<K, V>> those = that.iterator(); while (those.hasNext()) { final Entry<K, V> entry = those.next(); final V value = get(entry.getKey()); final V v = entry.getValue(); if (value == null ? v != null : !value.equals(v)) { return false; } } return true; } } return false; }
Example 8
Source File: Org.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Gets the list user ids(Long) taking in DataResult and the key Do we need * to make this public? * @param dataresult the dataresult object containing the results of a query * @param key the key for fetching the value * @return Returns the userIds */ private List getListFromResult(DataResult dataresult, String key) { List userIds = new ArrayList(); Iterator iter = dataresult.iterator(); while (iter.hasNext()) { // convert these to Longs Long bd = (Long) ((HashMap) iter.next()).get(key); userIds.add(bd); } return userIds; }
Example 9
Source File: MemoryGroup.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Return the set of {@link org.apache.catalina.User}s that are members of this group. */ @Override public Iterator<User> getUsers() { List<User> results = new ArrayList<>(); Iterator<User> users = database.getUsers(); while (users.hasNext()) { User user = users.next(); if (user.isInGroup(this)) { results.add(user); } } return results.iterator(); }
Example 10
Source File: MemoryLeakDetectionRule.java From brpc-java with Apache License 2.0 | 5 votes |
private void setupPools(List<Field> allocators) { Iterator<Field> it = allocators.iterator(); while (it.hasNext()) { Field field = it.next(); PooledByteBufAllocator alloc = new PooledByteBufAllocator(true, 0, 1, 8192, 11, 0, 0, 0, false); try { field.set(instance, alloc); } catch (Exception ex) { log.warn("Failed to process field {} for memory leak detection", field.getName()); it.remove(); } } }
Example 11
Source File: TodoService.java From Mastering-Spring-5.1 with MIT License | 5 votes |
public void deleteTodo(int id) { Iterator<Todo> iterator = todos.iterator(); while (iterator.hasNext()) { Todo todo = iterator.next(); if (todo.getId() == id) { iterator.remove(); } } }
Example 12
Source File: RscAutoPlaceApiTest.java From linstor-server with GNU General Public License v3.0 | 5 votes |
private void expectDeployed( String storPoolNameStr, String rscNameStr, String... nodeNameStrs ) throws Exception { StorPoolName storPoolName = new StorPoolName(storPoolNameStr); ResourceName rscName = new ResourceName(rscNameStr); for (String nodeNameStr : nodeNameStrs) { Node node = nodesMap.get(new NodeName(nodeNameStr)); Resource rsc = node.getResource(GenericDbBase.SYS_CTX, rscName); assertNotNull(rsc); Iterator<Volume> vlmIt = rsc.iterateVolumes(); assertTrue(vlmIt.hasNext()); while (vlmIt.hasNext()) { Volume vlm = vlmIt.next(); assertEquals( storPoolName, vlm.getAbsResource() .getLayerData(SYS_CTX) // drbd layer .getSingleChild() // storage layer .getVlmProviderObject(vlm.getVolumeDefinition().getVolumeNumber()) .getStorPool() .getName() .displayValue ); } } }
Example 13
Source File: BusinessRuleTaskActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(execution.getProcessDefinitionId()); String deploymentId = processDefinition.getDeploymentId(); KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId); StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession(); if (variablesInputExpressions != null) { Iterator<Expression> itVariable = variablesInputExpressions.iterator(); while (itVariable.hasNext()) { Expression variable = itVariable.next(); ksession.insert(variable.getValue(execution)); } } if (!rulesExpressions.isEmpty()) { RulesAgendaFilter filter = new RulesAgendaFilter(); Iterator<Expression> itRuleNames = rulesExpressions.iterator(); while (itRuleNames.hasNext()) { Expression ruleName = itRuleNames.next(); filter.addSuffic(ruleName.getValue(execution).toString()); } filter.setAccept(!exclude); ksession.fireAllRules(filter); } else { ksession.fireAllRules(); } Collection<Object> ruleOutputObjects = ksession.getObjects(); if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) { Collection<Object> outputVariables = new ArrayList<Object>(); for (Object object : ruleOutputObjects) { outputVariables.add(object); } execution.setVariable(resultVariable, outputVariables); } ksession.dispose(); leave(execution); }
Example 14
Source File: ResponseObjectMapper.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
private Author mapAuthor(AuthorType authorType) { Author author = new Author(); Iterator i$ = authorType.getHcparties().iterator(); while(i$.hasNext()) { HcpartyType hcpType = (HcpartyType)i$.next(); author.getHcParties().add(this.mapHcParty(hcpType)); } return author; }
Example 15
Source File: VisibleSystemsListAction.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * Normally the select all should clear the set and replace it with * the current dataresult. However, we are touching the SSM here, and * therefore it would be nice to simply add to the set everything in the * dataresult. * @param mapping ActionMapping * @param formIn ActionForm * @param request ServletRequest * @param response ServletResponse * @return The ActionForward to go to next. */ public ActionForward selectall(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { User user = new RequestContext(request).getCurrentUser(); //Get a DataResult containing all of the user's systems DataResult dr = getDataResult(user, formIn, request); //Get the old set RhnSet rs = getSetDecl().get(user); /* * Loop through all items in the DataResult and * add each item to the set. */ Iterator itr = dr.iterator(); while (itr.hasNext()) { BaseDto dto = (BaseDto) itr.next(); if (dto.isSelectable()) { dto.addToSet(rs); } } RhnSetManager.store(rs); Map params = makeParamMap(formIn, request); return getStrutsDelegate().forwardParams( mapping.findForward(RhnHelper.DEFAULT_FORWARD), params); }
Example 16
Source File: TaskTreeTab.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * This executes all default tasks in the specified project. * * @param project the project to execute. */ private void executeDefaultTasksInProject(ProjectView project) { Iterator<TaskView> iterator = project.getDefaultTasks().iterator(); while (iterator.hasNext()) { TaskView task = iterator.next(); gradlePluginLord.addExecutionRequestToQueue(task, false); } }
Example 17
Source File: TwelveBitIntToBitPatternMapper.java From androidthings-cameraCar with Apache License 2.0 | 5 votes |
private List<Boolean> removePauseBits(List<Boolean> bitPatterns) { Iterator<Boolean> iterator = bitPatterns.iterator(); int i = 0; while (iterator.hasNext()) { iterator.next(); if (i == 8) { iterator.remove(); i = 0; continue; } i++; } return bitPatterns; }
Example 18
Source File: Kafka08Fetcher.java From flink with Apache License 2.0 | 4 votes |
/** * Find leaders for the partitions. * * <p>From a high level, the method does the following: * - Get a list of FetchPartitions (usually only a few partitions) * - Get the list of topics from the FetchPartitions list and request the partitions for the topics. (Kafka doesn't support getting leaders for a set of partitions) * - Build a Map<Leader, List<FetchPartition>> where only the requested partitions are contained. * * @param partitionsToAssign fetch partitions list * @return leader to partitions map */ private static Map<Node, List<KafkaTopicPartitionState<TopicAndPartition>>> findLeaderForPartitions( List<KafkaTopicPartitionState<TopicAndPartition>> partitionsToAssign, Properties kafkaProperties) throws Exception { if (partitionsToAssign.isEmpty()) { throw new IllegalArgumentException("Leader request for empty partitions list"); } LOG.info("Refreshing leader information for partitions {}", partitionsToAssign); // this request is based on the topic names PartitionInfoFetcher infoFetcher = new PartitionInfoFetcher(getTopics(partitionsToAssign), kafkaProperties); infoFetcher.start(); // NOTE: The kafka client apparently locks itself up sometimes // when it is interrupted, so we run it only in a separate thread. // since it sometimes refuses to shut down, we resort to the admittedly harsh // means of killing the thread after a timeout. KillerWatchDog watchDog = new KillerWatchDog(infoFetcher, 60000); watchDog.start(); // this list contains ALL partitions of the requested topics List<KafkaTopicPartitionLeader> topicPartitionWithLeaderList = infoFetcher.getPartitions(); // copy list to track unassigned partitions List<KafkaTopicPartitionState<TopicAndPartition>> unassignedPartitions = new ArrayList<>(partitionsToAssign); // final mapping from leader -> list(fetchPartition) Map<Node, List<KafkaTopicPartitionState<TopicAndPartition>>> leaderToPartitions = new HashMap<>(); for (KafkaTopicPartitionLeader partitionLeader: topicPartitionWithLeaderList) { if (unassignedPartitions.size() == 0) { // we are done: all partitions are assigned break; } Iterator<KafkaTopicPartitionState<TopicAndPartition>> unassignedPartitionsIterator = unassignedPartitions.iterator(); while (unassignedPartitionsIterator.hasNext()) { KafkaTopicPartitionState<TopicAndPartition> unassignedPartition = unassignedPartitionsIterator.next(); if (unassignedPartition.getKafkaTopicPartition().equals(partitionLeader.getTopicPartition())) { // we found the leader for one of the fetch partitions Node leader = partitionLeader.getLeader(); List<KafkaTopicPartitionState<TopicAndPartition>> partitionsOfLeader = leaderToPartitions.get(leader); if (partitionsOfLeader == null) { partitionsOfLeader = new ArrayList<>(); leaderToPartitions.put(leader, partitionsOfLeader); } partitionsOfLeader.add(unassignedPartition); unassignedPartitionsIterator.remove(); // partition has been assigned break; } } } if (unassignedPartitions.size() > 0) { throw new RuntimeException("Unable to find a leader for partitions: " + unassignedPartitions); } LOG.debug("Partitions with assigned leaders {}", leaderToPartitions); return leaderToPartitions; }
Example 19
Source File: Javadoc.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
@TaskAction protected void generate() { final File destinationDir = getDestinationDir(); if (options.getDestinationDirectory() == null) { options.destinationDirectory(destinationDir); } options.classpath(new ArrayList<File>(getClasspath().getFiles())); if (!GUtil.isTrue(options.getWindowTitle()) && GUtil.isTrue(getTitle())) { options.windowTitle(getTitle()); } if (options instanceof StandardJavadocDocletOptions) { StandardJavadocDocletOptions docletOptions = (StandardJavadocDocletOptions) options; if (!GUtil.isTrue(docletOptions.getDocTitle()) && GUtil.isTrue(getTitle())) { docletOptions.setDocTitle(getTitle()); } } if (maxMemory != null) { final List<String> jFlags = options.getJFlags(); final Iterator<String> jFlagsIt = jFlags.iterator(); boolean containsXmx = false; while (!containsXmx && jFlagsIt.hasNext()) { final String jFlag = jFlagsIt.next(); if (jFlag.startsWith("-Xmx")) { containsXmx = true; } } if (!containsXmx) { options.jFlags("-Xmx" + maxMemory); } } List<String> sourceNames = new ArrayList<String>(); for (File sourceFile : getSource()) { sourceNames.add(sourceFile.getAbsolutePath()); } options.setSourceNames(sourceNames); executeExternalJavadoc(); }
Example 20
Source File: 103335311.java From docs-apim with Apache License 2.0 | 4 votes |
private List<NameValuePair> getParamsList(API api,String externalPublisher, String action) throws APIManagementException, UserStoreException{ // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(APIConstants.API_ACTION,action)); params.add(new BasicNameValuePair("name", api.getId().getApiName())); params.add(new BasicNameValuePair("version", api.getId().getVersion())); params.add(new BasicNameValuePair("provider", externalPublisher)); params.add(new BasicNameValuePair("description", api.getDescription())); params.add(new BasicNameValuePair("endpoint", api.getUrl())); params.add(new BasicNameValuePair("sandbox", api.getSandboxUrl())); params.add(new BasicNameValuePair("wsdl", api.getWadlUrl())); params.add(new BasicNameValuePair("wadl", api.getWsdlUrl())); params.add(new BasicNameValuePair("endpoint_config", api.getEndpointConfig())); StringBuilder tagsSet = new StringBuilder(""); Iterator it = api.getTags().iterator(); int j = 0; while (it.hasNext()) { Object tagObject = it.next(); tagsSet.append((String) tagObject); if (j != api.getTags().size() - 1) { tagsSet.append(","); } j++; } params.add(new BasicNameValuePair("tags", checkValue(tagsSet.toString()))); StringBuilder tiersSet = new StringBuilder(""); Iterator tier = api.getAvailableTiers().iterator(); int k = 0; while (tier.hasNext()) { Object tierObject = tier.next(); Tier availTier=(Tier) tierObject; tiersSet.append(availTier.getName()); if (k != api.getAvailableTiers().size() - 1) { tiersSet.append(","); } k++; } params.add(new BasicNameValuePair("tiersCollection", checkValue(tiersSet.toString()))); params.add(new BasicNameValuePair("context", api.getContext())); params.add(new BasicNameValuePair("bizOwner", api.getBusinessOwner())); params.add(new BasicNameValuePair("bizOwnerMail", api.getBusinessOwnerEmail())); params.add(new BasicNameValuePair("techOwner", api.getTechnicalOwner())); params.add(new BasicNameValuePair("techOwnerMail", api.getTechnicalOwnerEmail())); params.add(new BasicNameValuePair("visibility", api.getVisibility())); params.add(new BasicNameValuePair("roles", api.getVisibleRoles())); params.add(new BasicNameValuePair("endpointType", String.valueOf(api.isEndpointSecured()))); params.add(new BasicNameValuePair("epUsername", api.getEndpointUTUsername())); params.add(new BasicNameValuePair("epPassword", api.getEndpointUTPassword())); //Setting current API provider as the owner of the externally publishing API params.add(new BasicNameValuePair("apiOwner", api.getId().getProviderName())); params.add(new BasicNameValuePair("advertiseOnly", "true")); String tenantDomain = MultitenantUtils.getTenantDomain( APIUtil.replaceEmailDomainBack(api.getId().getProviderName())); int tenantId = ServiceReferenceHolder.getInstance().getRealmService(). getTenantManager().getTenantId(tenantDomain); params.add(new BasicNameValuePair("redirectURL", getExternalStoreRedirectURL(tenantId))); if(api.getTransports()==null){ params.add(new BasicNameValuePair("http_checked",null)); params.add(new BasicNameValuePair("https_checked",null)); }else{ String[] transports=api.getTransports().split(","); if(transports.length==1){ if("https".equals(transports[0])){ params.add(new BasicNameValuePair("http_checked",null)); params.add(new BasicNameValuePair("https_checked",transports[0])); }else{ params.add(new BasicNameValuePair("https_checked",null)); params.add(new BasicNameValuePair("http_checked",transports[0])); } }else{ params.add(new BasicNameValuePair("http_checked", "http")); params.add(new BasicNameValuePair("https_checked", "https")); } } params.add(new BasicNameValuePair("resourceCount", String.valueOf(api.getUriTemplates().size()))); Iterator urlTemplate = api.getUriTemplates().iterator(); int i=0; while (urlTemplate.hasNext()) { Object templateObject = urlTemplate.next(); URITemplate template=(URITemplate)templateObject; params.add(new BasicNameValuePair("uriTemplate-" + i, template.getUriTemplate())); params.add(new BasicNameValuePair("resourceMethod-" + i, template.getMethodsAsString().replaceAll("\\s",","))); params.add(new BasicNameValuePair("resourceMethodAuthType-" + i, template.getAuthTypeAsString().replaceAll("\\s",","))); params.add(new BasicNameValuePair("resourceMethodThrottlingTier-" + i, template.getThrottlingTiersAsString().replaceAll("\\s",","))); i++; } return params; }