Java Examples for java.util.Iterator

The following java examples will help you to understand the usage of java.util.Iterator. These source code samples are taken from different open source projects.

Example 1
Project: sosies-generator-master  File: ObjectGraphIteratorTest.java View source code
@Test(timeout = 1000)
public void testIteratorConstructor_null1() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(), this, "testIteratorConstructor_null1");
    final Iterator<java.lang.Object> it = new ObjectGraphIterator<java.lang.Object>(null);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 4120, it, 4119, it.hasNext());
    try {
        it.next();
        it.next();
    } catch (final NoSuchElementException ex) {
    }
    try {
        it.remove();
    } catch (final IllegalStateException ex) {
    }
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
Example 2
Project: Technomap-master  File: EulerIntegrator.java View source code
/**
     * @see prefuse.util.force.Integrator#integrate(prefuse.util.force.ForceSimulator, long)
     */
public void integrate(ForceSimulator sim, long timestep) {
    float speedLimit = sim.getSpeedLimit();
    Iterator iter = sim.getItems();
    while (iter.hasNext()) {
        ForceItem item = (ForceItem) iter.next();
        item.location[0] += timestep * item.velocity[0];
        item.location[1] += timestep * item.velocity[1];
        float coeff = timestep / item.mass;
        item.velocity[0] += coeff * item.force[0];
        item.velocity[1] += coeff * item.force[1];
        float vx = item.velocity[0];
        float vy = item.velocity[1];
        float v = (float) Math.sqrt(vx * vx + vy * vy);
        if (v > speedLimit) {
            item.velocity[0] = speedLimit * vx / v;
            item.velocity[1] = speedLimit * vy / v;
        }
    }
}
Example 3
Project: codemap-master  File: Concat.java View source code
@Override
public Iterator<T> iterator() {
    return new Iterator<T>() {

        Iterator<Iterable<T>> more = Arrays.asList(iterables).iterator();

        Iterator<T> current = more.hasNext() ? more.next().iterator() : null;

        @Override
        public boolean hasNext() {
            if (current == null)
                return false;
            if (current.hasNext())
                return true;
            current = more.hasNext() ? more.next().iterator() : null;
            return this.hasNext();
        }

        @Override
        public T next() {
            if (!hasNext())
                throw new NoSuchElementException();
            return current.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Example 4
Project: Prefuse-master  File: SortedTupleIterator.java View source code
/**
     * Initialize this iterator for the given source iterator and
     * comparator.
     * @param iter the source iterator of tuples
     * @param c the comparator to use for sorting
     */
public void init(Iterator iter, Comparator c) {
    m_tuples.clear();
    m_cmp = c;
    // populate tuple list
    while (iter.hasNext()) {
        Tuple t = (Tuple) iter.next();
        m_tuples.add(t);
    }
    // sort tuple list
    Collections.sort(m_tuples, m_cmp);
    // create sorted iterator
    m_iter = m_tuples.iterator();
}
Example 5
Project: xapi-master  File: TestCodegen.java View source code
@Test
public void testGenericImports() {
    final SourceBuilder<Object> b = new SourceBuilder<Object>("public static abstract class Test");
    b.setPackage("xapi.test");
    b.getClassBuffer().addGenerics("K", "V extends java.util.Date, ? extends java.lang.String, ? super xapi.test.Thing").addInterfaces("java.util.Iterator");
    String src = b.toSource();
    Assert.assertTrue("Must contain import java.util.Date;\n" + src, src.contains("import java.util.Date;"));
    Assert.assertTrue("Must contain import java.util.Iterator;\n" + src, b.toString().contains("import java.util.Iterator;"));
}
Example 6
Project: sqlpower-library-master  File: RmiTest.java View source code
public static void main(String[] args) {
    Collection message = null;
    DBConnectionSpecServer obj = null;
    try {
        obj = (DBConnectionSpecServer) Naming.lookup("//arthur/DBConnectionSpecServer");
        message = obj.getAvailableDatabases();
        Iterator messageIt = message.iterator();
        while (messageIt.hasNext()) {
            System.out.println(messageIt.next());
        }
        System.out.println("passcheck: " + obj.checkPassword("mo"));
        obj.setAvailableDatabases(message, "cow", "cow");
    } catch (Exception e) {
        System.out.println("exception: " + e.getMessage());
        e.printStackTrace();
    }
}
Example 7
Project: extension-aws-master  File: BsfScriptRunner.java View source code
@Override
public Object exec(Script inScript, Map context) throws OpenEditException {
    BSFManager bsfManager = new BSFManager();
    try {
        // expose standard items in the context
        for (Iterator iter = context.keySet().iterator(); iter.hasNext(); ) {
            String element = (String) iter.next();
            Object val = context.get(element);
            if (val != null) {
                bsfManager.declareBean(element, val, val.getClass());
            }
        }
        bsfManager.exec(BSFManager.getLangFromFilename(inScript.getDescription()), inScript.getDescription(), 0, 0, inScript.getScriptText());
    } catch (BSFException ex) {
        Throwable ext = ex.getTargetException();
        if (ext instanceof OpenEditException) {
            throw (OpenEditException) ext;
        }
        throw new OpenEditException(ext);
    }
    return null;
}
Example 8
Project: Klyph-master  File: TagSerializer.java View source code
public void serializeMap(Map<String, List<Tag>> tags, JSONObject json, String field) {
    JSONObject tagObject = new JSONObject();
    for (Iterator<String> iterator = tags.keySet().iterator(); iterator.hasNext(); ) {
        String key = (String) iterator.next();
        List<Tag> tag = tags.get(key);
        try {
            tagObject.put(key, super.serializeArray(tag));
        } catch (JSONException e) {
            Log.d("TagSerializer", "JsonException " + e.getMessage());
        }
    }
    try {
        json.put(field, tagObject);
    } catch (JSONException e) {
        Log.d("TagSerializer", "JsonException " + e.getMessage());
    }
}
Example 9
Project: spring-framework-2.5.x-master  File: UpdateCartQuantitiesAction.java View source code
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    CartActionForm cartForm = (CartActionForm) form;
    Iterator cartItems = cartForm.getCart().getAllCartItems();
    while (cartItems.hasNext()) {
        CartItem cartItem = (CartItem) cartItems.next();
        String itemId = cartItem.getItem().getItemId();
        try {
            int quantity = Integer.parseInt(request.getParameter(itemId));
            cartForm.getCart().setQuantityByItemId(itemId, quantity);
            if (quantity < 1) {
                cartItems.remove();
            }
        } catch (NumberFormatException e) {
        }
    }
    return mapping.findForward("success");
}
Example 10
Project: O2OMobile_Android-master  File: Transmitter.java View source code
public static void transmit(Command c, Map h, String b, java.io.OutputStream out) throws IOException {
    StringBuffer message = new StringBuffer(c.toString());
    message.append("\n");
    if (h != null) {
        for (Iterator keys = h.keySet().iterator(); keys.hasNext(); ) {
            String key = (String) keys.next();
            String value = (String) h.get(key);
            message.append(key);
            message.append(":");
            message.append(value);
            message.append("\n");
        }
    }
    message.append("\n");
    if (b != null)
        message.append(b);
    message.append("\000");
    out.write(message.toString().getBytes(Command.ENCODING));
}
Example 11
Project: openjdk-master  File: XMLEventFactoryImpl.java View source code
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {
    EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
    if (namespaces != null) {
        while (namespaces.hasNext()) event.addNamespace((Namespace) namespaces.next());
    }
    if (location != null)
        event.setLocation(location);
    return event;
}
Example 12
Project: classlib6-master  File: XMLEventFactoryImpl.java View source code
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {
    EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
    if (namespaces != null) {
        while (namespaces.hasNext()) event.addNamespace((Namespace) namespaces.next());
    }
    if (location != null)
        event.setLocation(location);
    return event;
}
Example 13
Project: ikvm-openjdk-master  File: XMLEventFactoryImpl.java View source code
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {
    EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
    if (namespaces != null) {
        while (namespaces.hasNext()) event.addNamespace((Namespace) namespaces.next());
    }
    if (location != null)
        event.setLocation(location);
    return event;
}
Example 14
Project: ManagedRuntimeInitiative-master  File: XMLEventFactoryImpl.java View source code
public javax.xml.stream.events.EndElement createEndElement(String prefix, String namespaceUri, String localName, java.util.Iterator namespaces) {
    EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
    if (namespaces != null) {
        while (namespaces.hasNext()) event.addNamespace((Namespace) namespaces.next());
    }
    if (location != null)
        event.setLocation(location);
    return event;
}
Example 15
Project: jade_agents-master  File: HashSet.java View source code
public Iterator iterator() {
    return new Iterator() {

        java.util.Iterator it = internalHashSet.iterator();

        /**
			 * @see jade.util.leap.Iterator interface
			 */
        public boolean hasNext() {
            return it.hasNext();
        }

        /**
			 * @see jade.util.leap.Iterator interface
			 */
        public Object next() {
            return it.next();
        }

        /**
			 * @see jade.util.leap.Iterator interface
			 */
        public void remove() {
            it.remove();
        }
    };
}
Example 16
Project: extFM-Tooling-master  File: MtextInterruptibleEcoreResolver.java View source code
/**
	 * Searches for all unresolved proxy objects in the given resource.
	 * 
	 * @param resource
	 * 
	 * @return all proxy objects that are not resolvable
	 */
public java.util.Set<org.eclipse.emf.ecore.EObject> findUnresolvedProxies(org.eclipse.emf.ecore.resource.Resource resource) {
    java.util.Set<org.eclipse.emf.ecore.EObject> unresolvedProxies = new java.util.LinkedHashSet<org.eclipse.emf.ecore.EObject>();
    for (java.util.Iterator<org.eclipse.emf.ecore.EObject> elementIt = org.eclipse.emf.ecore.util.EcoreUtil.getAllContents(resource, true); elementIt.hasNext(); ) {
        org.eclipse.emf.ecore.InternalEObject nextElement = (org.eclipse.emf.ecore.InternalEObject) elementIt.next();
        if (terminate) {
            return unresolvedProxies;
        }
        if (nextElement.eIsProxy()) {
            unresolvedProxies.add(nextElement);
        }
        for (org.eclipse.emf.ecore.EObject crElement : nextElement.eCrossReferences()) {
            if (terminate) {
                return unresolvedProxies;
            }
            crElement = org.eclipse.emf.ecore.util.EcoreUtil.resolve(crElement, resource);
            if (crElement.eIsProxy()) {
                unresolvedProxies.add(crElement);
            }
        }
    }
    return unresolvedProxies;
}
Example 17
Project: openmap-master  File: SoloMapComponentRejectPolicy.java View source code
/**
     * @param bc BeanContext, or MapHandler
     * @param obj the object to check before adding to MapHandler
     * @throws MultipleSoloMapComponentException if a duplicate
     *         instance of SoloMapComponent exists.
     * @return true if the object can be added to the MapHandler.
     */
public boolean canAdd(BeanContextSupport bc, Object obj) throws MultipleSoloMapComponentException {
    if (obj instanceof SoloMapComponent) {
        Class<?> firstClass = obj.getClass();
        for (Iterator<?> it = bc.iterator(); it.hasNext(); ) {
            Object someObj = it.next();
            if (someObj instanceof SoloMapComponent) {
                Class<?> secondClass = someObj.getClass();
                if (firstClass == secondClass || firstClass.isAssignableFrom(secondClass) || secondClass.isAssignableFrom(firstClass)) {
                    throw new MultipleSoloMapComponentException(firstClass, secondClass);
                }
            }
        }
    }
    return true;
}
Example 18
Project: OrganicBuilder-master  File: JoinSameValidator.java View source code
@Override
public String evaluate(final Collection<? extends Atom> atoms, final LevelMessages messages) {
    for (final Atom atom : atoms) {
        // get everything that's joined to this atom
        final LinkedList<Atom> joined = new LinkedList<Atom>();
        atom.getAllConnectedAtoms(joined);
        // is there any atom in this list of a different type?
        final Iterator<Atom> it = joined.iterator();
        while (it.hasNext()) {
            final Atom other = it.next();
            if (other.getType() != atom.getType()) {
                return messages.getError(1);
            }
        }
        // are there any atoms of the same type not on this list?
        for (final Atom otherAtom : atoms) {
            if (otherAtom.getType() == atom.getType() && !joined.contains(otherAtom)) {
                return messages.getError(2);
            }
        }
    }
    return null;
}
Example 19
Project: GeoGig-master  File: Representations.java View source code
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> AsyncCommandRepresentation<T> newRepresentation(AsyncCommand<T> cmd, MediaType mediaType, String baseURL) {
    ServiceLoader<CommandRepresentationFactory> serviceLoader;
    serviceLoader = ServiceLoader.load(CommandRepresentationFactory.class);
    CommandRepresentationFactory factory;
    for (Iterator<CommandRepresentationFactory> it = serviceLoader.iterator(); it.hasNext(); ) {
        factory = it.next();
        if (factory.supports(cmd.getCommandClass())) {
            AsyncCommandRepresentation<T> rep = factory.newRepresentation(cmd, mediaType, baseURL);
            return rep;
        }
    }
    return new SimpleAsyncCommandRepresentation<T>(mediaType, cmd, baseURL);
}
Example 20
Project: yarep-master  File: VFSRevisionIterator.java View source code
/**
     * @see java.util.Iterator#hasNext()
     */
public boolean hasNext() {
    if (currentRevision == null) {
        // INFO: Iterator is still at the beginning
        if (pointInTime != null) {
            // TODO: What exactly means 'reverse' when using pointInTime?!
            try {
                if (dis.getRevision(pointInTime) != null) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception e) {
                log.error(e, e);
                return false;
            }
        } else {
            if (reverse) {
                if (dis.getOldestRevision() != null) {
                    return true;
                } else {
                    log.warn("No revisions at all.");
                    return false;
                }
            } else {
                if (dis.getMostRecentRevision() != null) {
                    return true;
                } else {
                    log.warn("No revisions at all.");
                    return false;
                }
            }
        }
    } else {
        try {
            log.debug("Check if there is another revision older than: " + format(currentRevision.getCreationDate()));
            if (reverse) {
                if (dis.getRevisionYoungerThan(currentRevision.getCreationDate()) != null) {
                    return true;
                } else {
                    log.debug("No revision younger than '" + currentRevision.getCreationDate() + "', hence stop iteration.");
                    return false;
                }
            } else {
                if (dis.getRevisionOlderThan(currentRevision.getCreationDate()) != null) {
                    return true;
                } else {
                    log.debug("No revision older than '" + currentRevision.getCreationDate() + "', hence stop iteration.");
                    return false;
                }
            }
        } catch (Exception e) {
            log.error(e, e);
            return false;
        }
    }
}
Example 21
Project: oobd-master  File: JcaCRLStore.java View source code
private static Collection convertCRLs(Collection collection) throws CRLException {
    List list = new ArrayList(collection.size());
    for (Iterator it = collection.iterator(); it.hasNext(); ) {
        Object crl = it.next();
        if (crl instanceof X509CRL) {
            try {
                list.add(new X509CRLHolder(((X509CRL) crl).getEncoded()));
            } catch (IOException e) {
                throw new CRLException("cannot read encoding: " + e.getMessage());
            }
        } else {
            list.add((X509CRLHolder) crl);
        }
    }
    return list;
}
Example 22
Project: teiid-designer-master  File: CompositorBasedBuilderStrategy.java View source code
@Override
protected boolean shouldContainMappingClass(EObject node) {
    boolean result = false;
    if (mapper.allowsMappingClass(node)) {
        // see if the structure is similar to that of a complex type
        Collection children = tree.getChildren(node);
        for (Iterator iter = children.iterator(); iter.hasNext(); ) {
            EObject child = (EObject) iter.next();
            if (mapper.isContainerNode(child)) {
                result = true;
                break;
            }
        }
        if (!result) {
            // see if the node is directly under a choice
            EObject parent = tree.getParent(node);
            result = tree.isChoiceNode(parent);
        }
    }
    return result;
}
Example 23
Project: SmartAndroidSource-master  File: Verifi.java View source code
public boolean isValid(String value) {
    boolean result = true;
    this._message = new String();
    Iterator<AbstractVerifior> it = this._validators.iterator();
    while (it.hasNext()) {
        AbstractVerifior validator = it.next();
        try {
            if (!validator.isValid(value)) {
                this._message = validator.getMessage();
                result = false;
                break;
            }
        } catch (VerifiorException e) {
            System.err.println(e.getMessage());
            System.err.println(e.getStackTrace());
            this._message = e.getMessage();
            result = false;
            break;
        }
    }
    return result;
}
Example 24
Project: speechalyzer-master  File: JudgeAllThread.java View source code
/**
	 * called by thread.start();
	 */
public void run() {
    _isRunning = true;
    for (Iterator<RecFile> iter = _afm.getAudioFiles().iterator(); iter.hasNext(); ) {
        RecFile recFile = (RecFile) iter.next();
        _extractor.extractFeatures(recFile._file.getAbsolutePath());
        ClassificationResult cr = _classifier.classify();
        //			logger.info("Modus: judge file " + filePath + " emotionally: "
        //					+ cr.toString());
        recFile.storePred(cr);
        _afm.updateAudioFile(recFile._path);
    }
    System.out.println("finished judging all files!");
    _isRunning = false;
}
Example 25
Project: cdo-master  File: SelectionHandler.java View source code
protected List<Object> getSelectedObjects(ExecutionEvent event) {
    List<Object> objects = new ArrayList<Object>();
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (@SuppressWarnings("unchecked") Iterator<Object> iterator = structuredSelection.iterator(); iterator.hasNext(); ) {
            Object element = iterator.next();
            objects.add(element);
        }
    }
    return objects;
}