Java Code Examples for java.util.Iterator.hasNext()

The following are Jave code examples for showing how to use hasNext() of the java.util.Iterator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: myfaces-trinidad   File: CoreRenderer.java   View Source Code Vote up 7 votes
/**
 * @param afterChildIndex The children coming after this index, will
 * be considered.
 * @return the index of the next child that must be rendered, or
 * {@link #NO_CHILD_INDEX} if there is none.
 */
public static int getNextRenderedChildIndex(
  List<UIComponent> components,
  int               afterChildIndex
  )
{
  int childIndex = afterChildIndex + 1;
  Iterator<UIComponent> iter = components.listIterator(childIndex);
  for(; iter.hasNext(); childIndex++)
  {
    if(iter.next().isRendered())
    {
      return childIndex;
    }
  }

  return NO_CHILD_INDEX;
}
 
Example 2
Project: flume-release-1.7.0   File: FlumeConfiguration.java   View Source Code Vote up 6 votes
private void validateConfiguration() {
  Iterator<String> it = agentConfigMap.keySet().iterator();

  while (it.hasNext()) {
    String agentName = it.next();
    AgentConfiguration aconf = agentConfigMap.get(agentName);

    if (!aconf.isValid()) {
      logger.warn("Agent configuration invalid for agent '" + agentName
          + "'. It will be removed.");
      errors.add(new FlumeConfigurationError(agentName, "",
          FlumeConfigurationErrorType.AGENT_CONFIGURATION_INVALID,
          ErrorOrWarning.ERROR));

      it.remove();
    }
    logger.debug("Channels:" + aconf.channels + "\n");
    logger.debug("Sinks " + aconf.sinks + "\n");
    logger.debug("Sources " + aconf.sources + "\n");
  }

  logger.info("Post-validation flume configuration contains configuration"
      + " for agents: " + agentConfigMap.keySet());
}
 
Example 3
Project: onprom   File: EBDAModelWithOptimizedXAttributesEncodingImpl.java   View Source Code Vote up 6 votes
private void addMapping(CaseAnnotationQuery taq, QuestOWLReasonerExt reasoner) 
		throws OWLException, OBDAException, MalformedQueryException{

	//TODO: make a check if reformulateSPARQL2 ada masalah, lanjut ke query berikutnya, jangan mati
	List<SQLWithVarMap> unfoldedQuery = reasoner.reformulateSPARQL2(taq.getQuery());
	Iterator<SQLWithVarMap> it = unfoldedQuery.iterator(); 
	
	while(it.hasNext()){

		SQLWithVarMap sqlWithVarMap = it.next();
		HashMap<String, String> varMap = sqlWithVarMap.getVariableMap();
		
		//TODO: need to check whether taq.getTraceAnsVariable() is null or not before calling varMap.get
		//TODO: need to check whether taq.getNameAnsVariable() is null or not before calling varMap.get
		addTraceNameMapping(sqlWithVarMap.getSQL(), 
					cleanURI(varMap.get(taq.getTraceAnsVariable())),
					cleanURI(varMap.get(taq.getNameAnsVariable()))
			);
	}
}
 
Example 4
Project: javaide   File: CreateListFromObjectArrayExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
  //create an array of type Object, in this case we will create String array
  String[] strArray = new String[]{"Object", "Array", "Converted", "To", "List"};

  /*
    To create List from an array of type Object use,
    static List asList(Object[] objArray) method of Arrays class.

    This method returns a fixed sized list backed by original array.
  */

  List list = Arrays.asList(strArray);

  //get an iterator
  Iterator itr = list.iterator();

  //iterate through list created from Array
  System.out.println("List created from an Array of type Object contains,");
  while (itr.hasNext()) System.out.println(itr.next());
}
 
Example 5
Project: iTAP-controller   File: ACL.java   View Source Code Vote up 6 votes
/**
 * enforce new added rule
 */
private void enforceAddedRule(ACLRule rule) {

	Set<String> dpidSet;
	if (rule.getNw_src() != null) {
		dpidSet = apManager.getDpidSet(rule.getNw_src_prefix(),rule.getNw_src_maskbits());
	} else {
		dpidSet = apManager.getDpidSet(rule.getNw_dst_prefix(),rule.getNw_dst_maskbits());
	}

	Iterator<String> dpidIter = dpidSet.iterator();
	Set<String> nameSet = new HashSet<String>();

	while (dpidIter.hasNext()) {
		String dpid = dpidIter.next();
		String flowName = "ACLRule_" + rule.getId() + "_" + dpid;
		generateFlow(rule, dpid, flowName);
		nameSet.add(flowName);
	}
	ruleId2FlowName.put(rule.getId(), nameSet);
	ruleId2Dpid.put(rule.getId(), dpidSet);
}
 
Example 6
Project: ipack   File: PKIXNameConstraintValidator.java   View Source Code Vote up 6 votes
private Set unionEmail(Set excluded, String email)
{
    if (excluded.isEmpty())
    {
        if (email == null)
        {
            return excluded;
        }
        excluded.add(email);
        return excluded;
    }
    else
    {
        Set union = new HashSet();

        Iterator it = excluded.iterator();
        while (it.hasNext())
        {
            String _excluded = (String)it.next();

            unionEmail(_excluded, email, union);
        }

        return union;
    }
}
 
Example 7
Project: rapidminer   File: ValueSource.java   View Source Code Vote up 5 votes
private void fireValueSourceChanged(ValueSourceChangeEvent e) {
	Iterator<WeakReference<ValueSourceListener>> it = listeners.iterator();
	while (it.hasNext()) {
		ValueSourceListener l = it.next().get();
		if (l != null) {
			l.valueSourceChanged(e);
		} else {
			it.remove();
		}
	}
}
 
Example 8
Project: oscm   File: LoggerFactory.java   View Source Code Vote up 5 votes
/**
 * Changes the initial ConsoleAppender to a RollingFileAppender using the
 * current configuration settings.
 * 
 * @param logFilePath
 *            The path to the log files.
 * @param logConfigFile
 *            The path to the log4j configuration file.
 * @param logLevel
 *            The log level to be used.
 */
public static void activateRollingFileAppender(String logFilePath,
        String logConfigFile, String logLevel) {
    synchronized (managedLoggers) {
        try {
            LoggerFactory.logLevel = logLevel;
            LoggerFactory.logFilePath = logFilePath;
            LoggerFactory.logConfigPath = logConfigFile;

            initAppenders();

            Iterator<Class<?>> iterator = managedLoggers.keySet()
                    .iterator();
            while (iterator.hasNext()) {
                Class<?> loggerName = iterator.next();
                Log4jLogger logger = managedLoggers.get(loggerName);

                // initialize the loggers
                setFileAppendersForLogger(logger);

            }
            switchedToFileAppender = true;
        } catch (IOException e) {
            System.err.println("Log file could not be created!");
        }
    }
}
 
Example 9
Project: mpd-2017-i41d   File: WeatherWebApi.java   View Source Code Vote up 5 votes
/**
 * E.g. http://api.worldweatheronline.com/free/v2/search.ashx?query=oporto&format=tab&key=*****
 */

public Iterable<Location> search(String query) {
    String url=WEATHER_HOST + WEATHER_SEARCH + WEATHER_SEARCH_ARGS;
    url = String.format(url, query, WEATHER_TOKEN);
    List<Location> locations= new ArrayList<>();
    Iterator<String> iteratorString= req.getContent(url).iterator();
    while(iteratorString.hasNext()) {
        String line = iteratorString.next();
        if(!line.startsWith("#")) locations.add(Location.valueOf(line));
    }
    return locations;
}
 
Example 10
Project: openjdk-jdk10   File: InvokableTypeImpl.java   View Source Code Vote up 5 votes
final void addInterfaces(List<InterfaceType> list) {
    List<InterfaceType> immediate = interfaces();
    list.addAll(interfaces());
    Iterator<InterfaceType> iter = immediate.iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        interfaze.addInterfaces(list);
    }
    ClassTypeImpl superclass = (ClassTypeImpl) superclass();
    if (superclass != null) {
        superclass.addInterfaces(list);
    }
}
 
Example 11
Project: scanning   File: MandelbrotExampleTest.java   View Source Code Vote up 5 votes
@Test
public void test2DGridScanNoImage() throws Exception {
	detector.getModel().setSaveImage(false);
	try {

		IRunnableDevice<ScanModel> scanner = createGridScan(detector, output, false, new int[]{8,5}); // Outer scan of another scannable, for instance temp.
		assertScanNotFinished(getNexusRoot(scanner).getEntry());
		scanner.run(null);

		NXroot rootNode = getNexusRoot(scanner);
		NXentry entry = rootNode.getEntry();
		Map<String, NXdata> nxDataGroups = entry.getChildren(NXdata.class);

		boolean found = false;

		Iterator<NXdata> it = nxDataGroups.values().iterator();
		//check no NXdata of rank 4
		while (it.hasNext()) {

			NXdata next = it.next();
			String signal = next.getAttributeSignal();
			if (next.getDataNode(signal).getDataset().getRank()==4) {
				found = true;
				break;
			}

		}
		assertFalse(found);

	} finally {
		detector.getModel().setSaveImage(true);
	}

}
 
Example 12
Project: hy.common.ui   File: JTimePanel.java   View Source Code Vote up 5 votes
/**
 * 通知所有注册事件监听的对象
 * 
 * @param i_Event
 */
private void notifyListeners(TimeChangeEvent i_Event)
{
	Iterator<TimeChangeListener> v_Iter = this.listeners.iterator();

	while ( v_Iter.hasNext() ) 
	{
		TimeChangeListener v_Listener = v_Iter.next();

		v_Listener.onChangeListener(i_Event);
	}
}
 
Example 13
Project: solo-spring   File: ArchiveDateDao.java   View Source Code Vote up 5 votes
/**
 * Removes archive dates of unpublished articles from the specified archive
 * dates.
 *
 * @param archiveDates
 *            the specified archive dates
 * @throws RepositoryException
 *             repository exception
 */
private void removeForUnpublishedArticles(final List<JSONObject> archiveDates) throws RepositoryException {
	final Iterator<JSONObject> iterator = archiveDates.iterator();

	while (iterator.hasNext()) {
		final JSONObject archiveDate = iterator.next();

		if (0 == archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT)) {
			iterator.remove();
		}
	}
}
 
Example 14
Project: home-assistant-Android   File: Entity.java   View Source Code Vote up 5 votes
public void notifyObservers() {
    Iterator<WeakReference<BaseViewHolder>> iterator = observers.iterator();
    while (iterator.hasNext()) {
        BaseViewHolder viewHolder = iterator.next().get();
        if (viewHolder != null) {
            if (viewHolder.getAdapterPosition() != RecyclerView.NO_POSITION) {
                viewHolder.notifyChanged();
                return;
            }
        }
        iterator.remove();
    }
}
 
Example 15
Project: ctsms   File: ServiceUtil.java   View Source Code Vote up 5 votes
public static CVPDFPainter createCVPDFPainter(Collection<StaffOutVO> staffVOs, StaffDao staffDao, CvSectionDao cvSectionDao, CvPositionDao cvPositionDao,
		CourseParticipationStatusEntryDao courseParticipationDao, StaffAddressDao staffAddressDao) throws Exception {
	CVPDFPainter painter = new CVPDFPainter();
	Collection allCvSections = cvSectionDao.loadAllSorted(0, 0);
	cvSectionDao.toCvSectionVOCollection(allCvSections);
	if (staffVOs != null) {
		ArrayList<StaffOutVO> personVOs = new ArrayList<StaffOutVO>(staffVOs.size());
		HashMap<Long, StaffAddressOutVO> addressVOMap = new HashMap<Long, StaffAddressOutVO>(staffVOs.size());
		HashMap<Long, StaffImageOutVO> imageVOMap = new HashMap<Long, StaffImageOutVO>(staffVOs.size());
		HashMap<Long, HashMap<Long, Collection<CvPositionPDFVO>>> cvPositionVOMap = new HashMap<Long, HashMap<Long, Collection<CvPositionPDFVO>>>(staffVOs.size());
		Iterator<StaffOutVO> staffIt = staffVOs.iterator();
		while (staffIt.hasNext()) {
			StaffOutVO staffVO = staffIt.next();
			if (staffVO.isPerson()) {
				personVOs.add(staffVO);
				StaffAddressOutVO addressVO = findOrganisationCvAddress(staffVO, true, staffAddressDao);
				addressVOMap.put(staffVO.getId(), addressVO);
				imageVOMap.put(staffVO.getId(), staffDao.toStaffImageOutVO(staffDao.load(staffVO.getId())));
				HashMap<Long, Collection<CvPositionPDFVO>> staffPositionVOMap = new HashMap<Long, Collection<CvPositionPDFVO>>(allCvSections.size());
				Iterator<CvSectionVO> sectionIt = allCvSections.iterator();
				while (sectionIt.hasNext()) {
					CvSectionVO sectionVO = sectionIt.next();
					staffPositionVOMap.put(sectionVO.getId(), loadCvPositions(staffVO.getId(), sectionVO.getId(), cvPositionDao, courseParticipationDao));
				}
				cvPositionVOMap.put(staffVO.getId(), staffPositionVOMap);
			}
		}
		painter.setStaffVOs(personVOs);
		painter.setCvPositionVOMap(cvPositionVOMap);
		painter.setAddressVOMap(addressVOMap);
		painter.setImageVOMap(imageVOMap);
	}
	painter.setAllCvSectionVOs(allCvSections);
	return painter;
}
 
Example 16
Project: googles-monorepo-demo   File: AbstractSortedMultiset.java   View Source Code Vote up 5 votes
@Override
public Entry<E> pollLastEntry() {
  Iterator<Entry<E>> entryIterator = descendingEntryIterator();
  if (entryIterator.hasNext()) {
    Entry<E> result = entryIterator.next();
    result = Multisets.immutableEntry(result.getElement(), result.getCount());
    entryIterator.remove();
    return result;
  }
  return null;
}
 
Example 17
Project: monarch   File: JSONObject.java   View Source Code Vote up 5 votes
/**
 * Produce a JSONArray containing the names of the elements of this JSONObject.
 * 
 * @return A JSONArray containing the key strings, or null if the JSONObject is empty.
 */
public JSONArray names() {
  JSONArray ja = new JSONArray();
  Iterator keys = this.keys();
  while (keys.hasNext()) {
    ja.put(keys.next());
  }
  return ja.length() == 0 ? null : ja;
}
 
Example 18
Project: x7   File: Jedis.java   View Source Code Vote up 5 votes
public ScanResult<Tuple> zscan(final String key, final String cursor, final ScanParams params) {
  checkIsInMultiOrPipeline();
  client.zscan(key, cursor, params);
  List<Object> result = client.getObjectMultiBulkReply();
  String newcursor = new String((byte[]) result.get(0));
  List<Tuple> results = new ArrayList<Tuple>();
  List<byte[]> rawResults = (List<byte[]>) result.get(1);
  Iterator<byte[]> iterator = rawResults.iterator();
  while (iterator.hasNext()) {
    results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double.valueOf(SafeEncoder
        .encode(iterator.next()))));
  }
  return new ScanResult<Tuple>(newcursor, results);
}
 
Example 19
Project: jdk8u-jdk   File: ImageCache.java   View Source Code Vote up 4 votes
/**
 * Sets the cached image for the specified constraints.
 *
 * @param image  The image to store in cache
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return true if the image could be cached or false if the image is too big
 */
public boolean setImage(Image image, GraphicsConfiguration config, int w, int h, Object... args) {
    if (!isImageCachable(w, h)) return false;
    int hash = hash(config, w, h, args);
    lock.writeLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash);
        // check if currently in map
        if (ref != null && ref.get() == image) {
            return true;
        }
        // clear out old
        if (ref != null) {
            currentPixelCount -= ref.pixelCount;
            map.remove(hash);
        }
        // add new image to pixel count
        int newPixelCount = image.getWidth(null) * image.getHeight(null);
        currentPixelCount += newPixelCount;
        // clean out lost references if not enough space
        if (currentPixelCount > maxPixelCount) {
            while ((ref = (PixelCountSoftReference)referenceQueue.poll()) != null){
                //reference lost
                map.remove(ref.hash);
                currentPixelCount -= ref.pixelCount;
            }
        }
        // remove old items till there is enough free space
        if (currentPixelCount > maxPixelCount) {
            Iterator<Map.Entry<Integer, PixelCountSoftReference>> mapIter = map.entrySet().iterator();
            while ((currentPixelCount > maxPixelCount) && mapIter.hasNext()) {
                Map.Entry<Integer, PixelCountSoftReference> entry = mapIter.next();
                mapIter.remove();
                Image img = entry.getValue().get();
                if (img != null) img.flush();
                currentPixelCount -= entry.getValue().pixelCount;
            }
        }
        // finaly put new in map
        map.put(hash, new PixelCountSoftReference(image, referenceQueue, newPixelCount,hash, config, w, h, args));
        return true;
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 20
Project: s-store   File: Multimaps.java   View Source Code Vote up 3 votes
/**
 * Creates an index {@code ImmutableListMultimap} that contains the results of
 * applying a specified function to each item in an {@code Iterator} of
 * values. Each value will be stored as a value in the resulting multimap,
 * yielding a multimap with the same size as the input iterator. The key used
 * to store that value in the multimap will be the result of calling the
 * function on that value. The resulting multimap is created as an immutable
 * snapshot. In the returned multimap, keys appear in the order they are first
 * encountered, and the values corresponding to each key appear in the same
 * order as they are encountered.
 *
 * <p>For example, <pre>   {@code
 *
 *   List<String> badGuys =
 *       Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
 *   Function<String, Integer> stringLengthFunction = ...;
 *   Multimap<Integer, String> index =
 *       Multimaps.index(badGuys.iterator(), stringLengthFunction);
 *   System.out.println(index);}</pre>
 *
 * <p>prints <pre>   {@code
 *
 *   {4=[Inky], 6=[Blinky], 5=[Pinky, Pinky, Clyde]}}</pre>
 *
 * <p>The returned multimap is serializable if its keys and values are all
 * serializable.
 *
 * @param values the values to use when constructing the {@code
 *     ImmutableListMultimap}
 * @param keyFunction the function used to produce the key for each value
 * @return {@code ImmutableListMultimap} mapping the result of evaluating the
 *     function {@code keyFunction} on each value in the input collection to
 *     that value
 * @throws NullPointerException if any of the following cases is true:
 *     <ul>
 *     <li>{@code values} is null
 *     <li>{@code keyFunction} is null
 *     <li>An element in {@code values} is null
 *     <li>{@code keyFunction} returns {@code null} for any element of {@code
 *         values}
 *     </ul>
 * @since 10.0
 */
public static <K, V> ImmutableListMultimap<K, V> index(
    Iterator<V> values, Function<? super V, K> keyFunction) {
  checkNotNull(keyFunction);
  ImmutableListMultimap.Builder<K, V> builder
      = ImmutableListMultimap.builder();
  while (values.hasNext()) {
    V value = values.next();
    checkNotNull(value, values);
    builder.put(keyFunction.apply(value), value);
  }
  return builder.build();
}