Example usage for java.util ArrayList iterator

List of usage examples for java.util ArrayList iterator

Introduction

In this page you can find the example usage for java.util ArrayList iterator.

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:AppSpringLayout.java

protected ArrayList<String> checkLinks(ArrayList<Urls> originalValue) {

    // here we convert our Data arrayList to a String arrayList
    ArrayList<String> stringArray = new ArrayList<String>();

    for (Urls currentData : originalValue) {
        stringArray.add(currentData.getContentUrl());
    }/* www. j  av  a  2s.  c o  m*/

    // get an iterator
    Iterator iter = stringArray.iterator();
    String strElement = "";
    URL linkAsUrl = null;

    foundLinks = 0;
    while (iter.hasNext()) {
        strElement = (String) iter.next();
        // System.out.println("============");
        // System.out.println("CHECKING: " + strElement);
        try {
            linkAsUrl = new URL(strElement);
            imageResponses = ImageIO.read(linkAsUrl);
            displayImage(strElement, labelTryLinks);
            foundLinks++;
            // System.out.println("OK");
            lblFoundLinks.setText("images found: " + foundLinks);
        } catch (MalformedURLException e) {
            System.out.println("malformed exception with url " + strElement);
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.out.println("NullPointerException: element to be removed - " + strElement);
            iter.remove();
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IIOException \nLink to be removed: " + strElement);
            iter.remove();
            e.printStackTrace();
        }
    }
    return stringArray;
}

From source file:com.tremolosecurity.config.util.UnisonConfigManagerImpl.java

@Override
public void loadFilters() {
    Iterator<ArrayList<UrlHolder>> itl = this.byHost.values().iterator();
    while (itl.hasNext()) {
        ArrayList<UrlHolder> lst = itl.next();
        Iterator<UrlHolder> it = lst.iterator();
        while (it.hasNext()) {
            try {
                it.next().init();// w  ww .  j  a  v  a  2s . com
            } catch (Exception e) {
                logger.error("Could not initialize filter", e);
            }
        }
    }
}

From source file:de.nec.nle.siafu.model.World.java

/**
 * Creates a place for each black pixel in the images contained in the
 * simulation data. The place type is the name of the image.
 * /*from   w  ww .j  av a 2s  .  c  o m*/
 * @return a list of places generated from the images in the simulation
 *         data.
 */
protected ArrayList<Place> createPlacesFromImages() {
    Place.initialize(this);
    ArrayList<Place> placesFromImg = new ArrayList<Place>();
    Map<String, InputStream> fileList = simData.getPlaceFiles();
    Iterator<String> listIt = fileList.keySet().iterator();

    //int total = 0;

    while (listIt.hasNext()) {
        String type = (String) listIt.next();
        ArrayList<Position> placePoints = readPlacePoints(fileList.get(type));
        Iterator<Position> it = placePoints.iterator();
        //total += placePoints.size();
        Controller.getProgress().reportPlacesFound(type, placePoints.size());

        while (it.hasNext()) {
            Position pos = (Position) it.next();
            Place place;
            try {
                place = new Place(type, pos, this);
            } catch (PositionOnAWallException e) {
                throw new RuntimeException("One of your \"" + type + "\" places, at " + pos + " is on a wall");
            }
            Controller.getProgress().reportPlaceCreated(type);
            placesFromImg.add(place);
        }
    }

    return placesFromImg;
}

From source file:jp.or.openid.eiwg.scim.operation.Operation.java

/**
 * /*  www  . j av a 2 s.c o m*/
 *
 * @param context
 * @param request
 * @param attributes
 * @param requestJson
 */
public boolean deleteUserInfo(ServletContext context, HttpServletRequest request, String targetId) {

    // ?
    setError(0, null, null);

    // id?
    LinkedHashMap<String, Object> targetInfo = null;

    @SuppressWarnings("unchecked")
    ArrayList<LinkedHashMap<String, Object>> users = (ArrayList<LinkedHashMap<String, Object>>) context
            .getAttribute("Users");
    Iterator<LinkedHashMap<String, Object>> usersIt = null;
    if (users != null && !users.isEmpty()) {
        usersIt = users.iterator();
        while (usersIt.hasNext()) {
            LinkedHashMap<String, Object> userInfo = usersIt.next();
            Object id = SCIMUtil.getAttribute(userInfo, "id");
            if (id != null && id instanceof String) {
                if (targetId.equals(id.toString())) {
                    targetInfo = userInfo;
                    break;
                }
            }
        }
    }

    if (targetInfo == null) {
        // ???
        setError(HttpServletResponse.SC_NOT_FOUND, null, MessageConstants.ERROR_NOT_FOUND);
        return false;
    }

    // (??)
    usersIt.remove();
    context.setAttribute("Users", users);

    return true;
}

From source file:com.amalto.core.server.DefaultItem.java

/**
 * Search ordered Items through a view in a cluster and specifying a condition
 *
 * @param dataClusterPOJOPK The Data Cluster where to run the query
 * @param viewPOJOPK The View/*w  w w .  j  av a2  s . c om*/
 * @param searchValue The value searched. If empty, null or equals to "*", this method is equivalent to a view search
 * with no filter.
 * @param matchWholeSentence If <code>false</code>, the searchValue is separated into keywords using " " (white space) as
 * separator. Match will be done with a OR condition on each field. If <code>true</code>, the keyword is considered
 * as a whole sentence and matching is done on the whole sentence (not each word).
 * @param spellThreshold The condition spell checking threshold. A negative value de-activates spell
 * @param orderBy An optional full path of the item used to order results.
 * @param direction One of {@link com.amalto.xmlserver.interfaces.IXmlServerSLWrapper#ORDER_ASCENDING} or
 * {@link com.amalto.xmlserver.interfaces.IXmlServerSLWrapper#ORDER_DESCENDING}
 * @param start The first item index (starts at zero)
 * @param limit The maximum number of items to return
 * @return The ordered list of results
 * @throws com.amalto.core.util.XtentisException In case of error in MDM code.
 */
@Override
public ArrayList<String> quickSearch(DataClusterPOJOPK dataClusterPOJOPK, ViewPOJOPK viewPOJOPK,
        String searchValue, boolean matchWholeSentence, int spellThreshold, String orderBy, String direction,
        int start, int limit) throws XtentisException {
    try {
        // check if there actually is a search value
        if ((searchValue == null) || "".equals(searchValue) || "*".equals(searchValue)) { // $NON-NLS-1$ // $NON-NLS-2$
            return viewSearch(dataClusterPOJOPK, viewPOJOPK, null, spellThreshold, orderBy, direction, start,
                    limit);
        } else {
            ViewPOJO view = Util.getViewCtrlLocal().getView(viewPOJOPK);
            ArrayList<String> searchableFields = view.getSearchableBusinessElements().getList();
            Iterator<String> iterator = searchableFields.iterator();
            while (iterator.hasNext()) {
                String searchableField = iterator.next();
                // Exclude searchable elements that don't include a '/' since we are generating XPath expressions
                // (exclude 'Entity' elements but keep 'Entity/Id').
                if (!searchableField.contains("/")) {
                    iterator.remove();
                }
            }

            List<String> keywords;
            if (!matchWholeSentence) { // Match on each word.
                keywords = new ArrayList<String>();
                String[] allKeywords = searchValue.split("\\p{Space}+");
                Collections.addAll(keywords, allKeywords);
            } else { // Match on whole sentence
                keywords = Collections.singletonList(searchValue);
            }
            IWhereItem searchItem;
            if (searchableFields.isEmpty()) {
                return new ArrayList<String>(0);
            } else {
                WhereOr whereOr = new WhereOr();
                for (String fieldName : searchableFields) {
                    WhereOr nestedOr = new WhereOr();
                    for (String keyword : keywords) {
                        WhereCondition nestedCondition = new WhereCondition(fieldName, WhereCondition.CONTAINS,
                                keyword.trim(), WhereCondition.PRE_OR, false);
                        nestedOr.add(nestedCondition);
                    }
                    whereOr.add(nestedOr);
                }
                searchItem = whereOr;
            }

            return viewSearch(dataClusterPOJOPK, viewPOJOPK, searchItem, spellThreshold, orderBy, direction,
                    start, limit);
        }
    } catch (XtentisException e) {
        throw (e);
    } catch (Exception e) {
        String err = "Unable to quick search  " + searchValue + ": " + e.getClass().getName() + ": "
                + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:com.microsoft.tfs.core.ws.runtime.transport.IdleHTTPConnectionCloser.java

@Override
public void run() {
    try {/*from   ww  w  .  j ava2  s  . c om*/
        while (true) {
            /*
             * Determine which clients we must service, removing any old
             * references as we iterate.
             */
            ArrayList clients = new ArrayList();
            synchronized (clientWeakReferences) {
                for (final Iterator i = clientWeakReferences.iterator(); i.hasNext();) {
                    final WeakReference reference = (WeakReference) i.next();
                    final HttpClient client = (HttpClient) reference.get();

                    // If the reference is now null, remove it from the set.
                    if (client == null) {
                        log.debug("client reference went null, removing"); //$NON-NLS-1$
                        i.remove();
                        continue;
                    }

                    clients.add(client);
                }
            }

            if (clients.size() == 0) {
                log.trace("no active clients"); //$NON-NLS-1$
            } else {
                for (final Iterator i = clients.iterator(); i.hasNext();) {
                    HttpClient client = (HttpClient) i.next();
                    Check.notNull(client, "client"); //$NON-NLS-1$

                    final String messageFormat = "closing connections for {0} idle longer than {1} ms"; //$NON-NLS-1$
                    final String message = MessageFormat.format(messageFormat, client.toString(),
                            IDLE_CONNECTION_CLOSE_TIMEOUT_MILLISECONDS);
                    log.trace(message);

                    client.getHttpConnectionManager()
                            .closeIdleConnections(IDLE_CONNECTION_CLOSE_TIMEOUT_MILLISECONDS);

                    // Make sure the client is out of scope before we enter
                    // sleep.
                    client = null;
                }
            }

            // Remove client references before sleeping.
            clients = null;

            // Sleep for a while.
            final String messageFormat = "sleeping {0} ms"; //$NON-NLS-1$
            final String message = MessageFormat.format(messageFormat, THREAD_IDLE_CHECK_PERIOD_MILLISECONDS);
            log.trace(message);
            Thread.sleep(THREAD_IDLE_CHECK_PERIOD_MILLISECONDS);
        }
    } catch (final InterruptedException e) {
        /*
         * If we were interrupted, we should log and quit.
         */
        log.warn("interrupted; exiting thread", e); //$NON-NLS-1$
    } catch (final Throwable t) {
        log.error("unexpected error", t); //$NON-NLS-1$
    }
}

From source file:br.gov.lexml.oaicat.LexMLOAICatalog.java

/**
 * Purge tokens that are older than the time-to-live.
 * <p/>//from   w w w . j a v  a 2s .com
 * <b>LEXML ready</b>
 */
private void purge() {
    ArrayList old = new ArrayList();
    Date then, now = new Date();
    Iterator keySet = resumptionTokens.keySet().iterator();
    String key;

    while (keySet.hasNext()) {
        key = (String) keySet.next();
        then = new Date(Long.parseLong(key) + getMillisecondsToLive());
        if (now.after(then)) {
            old.add(key);
        }
    }
    Iterator iterator = old.iterator();
    while (iterator.hasNext()) {
        key = (String) iterator.next();
        resumptionTokens.remove(key);
    }
}

From source file:de.nec.nle.siafu.model.World.java

/**
 * Create the simulation overlays out of the overlay images provided, and
 * then asking the ContextModel to modify them as suitable.
 * /*  w w  w .  ja v  a 2s. co m*/
 */
private void createOverlays() {
    overlays = new TreeMap<String, Overlay>();

    try {
        contextModel = (BaseContextModel) simData.getContextModelClass()
                .getConstructor(new Class[] { this.getClass() }).newInstance(new Object[] { this });
    } catch (Exception e) {
        throw new RuntimeException("Can't instantiate the context model", e);
    }

    ArrayList<Overlay> olList = createOverlaysFromImages();
    contextModel.createOverlays(olList);

    Iterator<Overlay> olListIt = olList.iterator();

    while (olListIt.hasNext()) {
        Overlay ol = olListIt.next();
        overlays.put(ol.getName(), ol);
    }
}

From source file:it.eng.spagobi.profiling.dao.SbiUserDAOHibImpl.java

public void deleteSbiUserById(Integer id) throws EMFUserError {
    logger.debug("IN");

    Session aSession = null;/*from   w w w  .  ja v  a2  s .  co m*/
    Transaction tx = null;
    try {
        aSession = getSession();
        tx = aSession.beginTransaction();

        String q = " from SbiUserAttributes x where x.id.id = :id ";
        Query query = aSession.createQuery(q);
        query.setInteger("id", id);

        ArrayList<SbiUserAttributes> userAttributes = (ArrayList<SbiUserAttributes>) query.list();

        //deletes attributes associations
        if (userAttributes != null) {
            Iterator attrsIt = userAttributes.iterator();
            while (attrsIt.hasNext()) {
                SbiUserAttributes temp = (SbiUserAttributes) attrsIt.next();
                attrsIt.remove();

                aSession.delete(temp);
                aSession.flush();
            }
        }

        String qr = " from SbiExtUserRoles x where x.id.id = :id ";
        Query queryR = aSession.createQuery(qr);
        queryR.setInteger("id", id);

        ArrayList<SbiExtUserRoles> userRoles = (ArrayList<SbiExtUserRoles>) queryR.list();
        if (userRoles != null) {
            Iterator rolesIt = userRoles.iterator();
            while (rolesIt.hasNext()) {
                SbiExtUserRoles temp = (SbiExtUserRoles) rolesIt.next();
                rolesIt.remove();
                aSession.delete(temp);
                aSession.flush();
            }
        }
        SbiUser userToDelete = (SbiUser) aSession.load(SbiUser.class, id);

        aSession.delete(userToDelete);
        aSession.flush();
        tx.commit();
    } catch (HibernateException he) {
        logger.error(he.getMessage(), he);
        if (tx != null)
            tx.rollback();
        throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
    } finally {
        logger.debug("OUT");
        if (aSession != null) {
            if (aSession.isOpen())
                aSession.close();
        }
    }
}

From source file:com.justone.android.main.MainActivity.java

private void setDataToView(View targetView, ArrayList<ArrayList<String>> dataList) {
    Iterator<ArrayList<String>> it = dataList.iterator();

    while (it.hasNext()) {
        ArrayList<String> tempArray = it.next();
        int targetViewId = Integer.parseInt(tempArray.get(0));
        String content = tempArray.get(1);
        String type = tempArray.get(2);

        if (type.equals("text")) {

            TextView textView = (TextView) targetView.findViewById(targetViewId);
            textView.setText(content);//from w  ww . ja v  a 2  s .c om

        } else if (type.equals("image")) {
            ImageView imageView = (ImageView) targetView.findViewById(targetViewId);

            asynImageLoader.showImageAsyn(imageView, content, findViewById(R.id.homeloadingLayout), null, null);

        } else if (type.equals("shareUrl")) {
            TextView textView = (TextView) targetView.findViewById(targetViewId);
            textView.setText(content);
        }

        //Log.i("setDataToView", content+"_"+type);
    }
}