Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

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

Usage

From source file:com.arantius.tivocommander.Utils.java

public static final String join(String glue, List<String> strings) {
    Iterator<String> it = strings.iterator();
    StringBuilder out = new StringBuilder();
    String s;//from www .j  a  va  2 s.c  o  m
    while (it.hasNext()) {
        s = it.next();
        if (s == null || s == "") {
            continue;
        }
        out.append(s);
        if (it.hasNext()) {
            out.append(glue);
        }
    }

    return out.toString();
}

From source file:com.etime.ETimeUtils.java

/**
 * return a long of the milliseconds since epoch the user should clock out at to log exactly 8 hours.
 *
 * @param punches A list of punches logged today by a given user.
 * @return A long of the milliseconds since epoch the user should clock out at to log exactly 8 hours.
 *///from ww  w.  jav  a  2 s . c o m
protected static long clockOutAt(List<Punch> punches) {
    Iterator<Punch> iterPunches = punches.iterator();
    long clockOutTime = 0;
    int index = 1;
    while (iterPunches.hasNext()) {
        long punch = iterPunches.next().getCalendar().getTimeInMillis();
        if (index == 1)
            punch = RoundingRules.getRoundedTime(punch);
        else if (index == 2 || index % 2 == 0)
            punch *= -1;

        clockOutTime += punch;
        index++;
    }
    clockOutTime += 8 * 1000 * 60 * 60;
    clockOutTime = RoundingRules.getRoundedTime(clockOutTime);

    return clockOutTime;
}

From source file:be.ff.gui.web.struts.action.ActionPlugInChain.java

/**
 * This static method initializes the action plug-in chain, by instantiating and initializing all configured
 * <code>ActionPlugIn</code> classes. This method must be called before the action plug-in mechanism comes into
 * action. Therefore it will be called in the <code>ActionPlugInPlugIn</code> class, which executes at application
 * start-up./*from  w  ww.  j a  v a 2  s .  c o  m*/
 *
 * @param chainDef the <code>ActionPlugInChainDefinition</code> instance that is used to initialize the chain and
 *        the configured action plug-ins
 * @param context the <code>ServletContext</code> instance used to initialize the configured action plug-ins
 */
protected static void init(ActionPlugInChainDefinition chainDef, ServletContext context) {
    if (inicializado) {
        if (log.isDebugEnabled()) {
            log.debug("O ActionPlugInChain j foi inicializado anteriormente. Ignorando.");
        }
        return;
    }

    if (log.isDebugEnabled()) {
        log.debug("[ActionPlugInChain::init] Intializing the action plug-in chain ...");
    }
    activeActionPlugInRegister = new ArrayList();
    activeActionPlugInDefinitionRegister = new ArrayList();

    // loop through all configured action plug-ins
    List plugInDefs = chainDef.getActionPlugInDefintions();
    Iterator iter = plugInDefs.iterator();
    while (iter.hasNext()) {
        ActionPlugInDefinition def = (ActionPlugInDefinition) iter.next();

        try {
            // create an instance of the action plug-in class
            if (log.isDebugEnabled()) {
                log.debug("[ActionPlugInChain::init] Instantiating '" + def.getClassName()
                        + "' action plug-in ...");
            }
            ActionPlugIn actionPlugIn = null;
            actionPlugIn = (ActionPlugIn) Class.forName(def.getClassName()).newInstance();

            try {
                // initialize action plug-in instance
                if (log.isDebugEnabled()) {
                    log.debug("[ActionPlugInChain::init] Initializing '" + def.getClassName()
                            + "' action plug-in ...");
                }
                ActionPlugInConfig config = new ActionPlugInConfig(def, context);
                actionPlugIn.init(config);

                // add this action plug-in to the list of active plug-ins
                addActivePlugIn(actionPlugIn, def);
            } catch (ActionPlugInException e) {
                String errorMsg = "[ActionPlugInChain::init] The initialization of the '" + def.getClassName()
                        + "' action plug-in failed. This action plug-in it will not be placed into service.";
                Throwable cause = (e.getRootCause() != null) ? e.getRootCause() : e;
                log.error(errorMsg, cause);
            }
        } catch (Exception e) {
            // InstantiationException, IllegalAccessException, ClassNotFoundException
            String errorMsg = "[ActionPlugInChain::init] The instantiation of the '" + def.getClassName()
                    + "' action plug-in failed. This action plug-in it will not be placed into service.";
            log.error(errorMsg, e);
        }
    }
    inicializado = true;
}

From source file:cn.fql.utility.CollectionUtility.java

/**
 * Copy specified list to a new list/*from  w w  w .  j  a va2  s  .  c  om*/
 *
 * @param src source list
 * @return new list
 */
public static List copyList(List src) {
    List lstResult = new ArrayList();
    if (src != null) {
        for (Iterator it = src.iterator(); it.hasNext();) {
            lstResult.add(it.next());
        }
    }
    return lstResult;
}

From source file:com.nextep.designer.ui.helpers.UIHelper.java

/**
 * Retrieves the currently selected object model or <code>null</code> if
 * none. If several objects are selected, it will return the first element
 * of the selection.<br>//from w w w.j av  a  2s.  co  m
 * We advise you to use the List form of this method for correct multiple
 * selection handling. This is a convenience method for handlers which do
 * not support multiple selection and which should only be activated on a
 * single selection.
 * 
 * @param window
 * @return
 */
public static Object getSelectedSingleModel(IWorkbenchWindow window) {
    List<?> multiSelection = getSelectedModel(window);
    if (multiSelection != null && !multiSelection.isEmpty()) {
        return multiSelection.iterator().next();
    } else {
        return null;
    }
}

From source file:com.ctc.cockpits.cmscockpit.sitewizard.CMSSiteUtils.java

public static void createHomepage(final String uid, final String label, final CatalogVersionModel catVersion,
        final CMSSiteModel cmsSiteModel, final List<PageTemplateModel> clonedTemplates) {
    final PageTemplateModel firstTemplate = clonedTemplates.iterator().next();
    final ModelService modelService = UISessionUtils.getCurrentSession().getModelService();

    final ContentPageModel contentPage = modelService.create(CONTENT_PAGE);
    contentPage.setUid(uid);//  www  .j  a v a 2 s.  c  om
    contentPage.setName(uid);
    contentPage.setLabel(label);
    contentPage.setHomepage(true);
    contentPage.setCatalogVersion(catVersion);
    contentPage.setMasterTemplate(firstTemplate);
    contentPage.setDefaultPage(Boolean.TRUE);
    cmsSiteModel.setStartingPage(contentPage);
    adjustHomePageTemplate(contentPage, clonedTemplates);
    modelService.save(contentPage);
}

From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java

private static void awaitAll(List<Future<?>> futures) throws InterruptedException {
    Iterator<Future<?>> iter = futures.iterator();

    while (iter.hasNext()) {
        Future<?> f = iter.next();

        while (!f.isDone()) {
            TimeUnit.SECONDS.sleep(1);
        }/*from ww w.  j a  va  2s  .c  om*/
    }
}

From source file:com.evolveum.midpoint.prism.foo.EventCategoryFilterType.java

/**
 * Copies all values of property {@code Category} deeply.
 * //from   w  ww . ja va 2  s  .c  o m
 * @param source
 *     The source to copy from.
 * @param target
 *     The target to copy {@code source} to.
 * @throws NullPointerException
 *     if {@code target} is {@code null}.
 */
@SuppressWarnings("unchecked")
private static void copyCategory(final List<String> source, final List<String> target) {
    // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
    if ((source != null) && (!source.isEmpty())) {
        for (final Iterator<?> it = source.iterator(); it.hasNext();) {
            final Object next = it.next();
            if (next instanceof String) {
                // CEnumLeafInfo: com.evolveum.midpoint.xml.ns._public.common.common_3.String
                target.add(((String) next));
                continue;
            }
            // Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
            throw new AssertionError((("Unexpected instance '" + next)
                    + "' for property 'Category' of class 'com.evolveum.midpoint.xml.ns._public.common.common_3.EventCategoryFilterType'."));
        }
    }
}

From source file:com.news.util.UploadFileUtil.java

public static String upload(HttpServletRequest request, String paramName, String fileName) {
    String result = "";
    File file;// w  w w.j av a 2 s .  co m
    int maxFileSize = 5000 * 1024;
    int maxMemSize = 5000 * 1024;
    String filePath = "";
    ///opt/apache-tomcat-7.0.59/webapps/noithat
    //filePath = getServletContext().getRealPath("") + File.separator + "test-upload" + File.separator;
    filePath = File.separator + File.separator + "opt" + File.separator + File.separator;
    filePath += "apache-tomcat-7.0.59" + File.separator + File.separator + "webapps";
    filePath += File.separator + File.separator + "noithat";
    filePath += File.separator + File.separator + "upload" + File.separator + File.separator;
    filePath += "images" + File.separator;

    //filePath = "E:" + File.separator;

    // Verify the content type
    String contentType = request.getContentType();
    System.out.println("contentType=" + contentType);
    if (contentType != null && (contentType.indexOf("multipart/form-data") >= 0)) {

        DiskFileItemFactory factory = new DiskFileItemFactory();
        // maximum size that will be stored in memory
        factory.setSizeThreshold(maxMemSize);
        // Location to save data that is larger than maxMemSize.
        factory.setRepository(new File("c:\\temp"));

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);
        // maximum file size to be uploaded.
        upload.setSizeMax(maxFileSize);
        try {
            // Parse the request to get file items.
            List fileItems = upload.parseRequest(request);
            System.out.println("fileItems.size()=" + fileItems.size());
            // Process the uploaded file items
            Iterator i = fileItems.iterator();

            while (i.hasNext()) {
                FileItem fi = (FileItem) i.next();
                if (!fi.isFormField() && fi.getFieldName().equals(paramName)) {
                    // Get the uploaded file parameters
                    String fieldName = fi.getFieldName();
                    int dotPos = fi.getName().lastIndexOf(".");
                    if (dotPos < 0) {
                        fileName += ".jpg";
                    } else {
                        fileName += fi.getName().substring(dotPos);
                    }
                    boolean isInMemory = fi.isInMemory();
                    long sizeInBytes = fi.getSize();
                    // Write the file
                    if (fileName.lastIndexOf("\\") >= 0) {
                        file = new File(filePath + fileName.substring(fileName.lastIndexOf("\\")));
                    } else {
                        file = new File(filePath + fileName.substring(fileName.lastIndexOf("\\") + 1));
                    }
                    fi.write(file);
                    System.out.println("Uploaded Filename: " + filePath + fileName + "<br>");
                    result = fileName;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return result;
}

From source file:com.omicronware.streamlet.Main.java

public static void loadFactories() {
    //register/*from w  ww.  j  a va 2  s  .  c om*/
    ObjectFactory.register(User.class, Category.class, FileDownload.class, File.class, FilePacket.class,
            FileSearchTerm.class, Packet.class);

    //fill 
    ObjectFactory.fill(DATABASE);

    //map filled in factories to the right objects.
    ObjectFactory.map(User.class, FileSearchTerm.class);
    ObjectFactory.map(File.class, FileSearchTerm.class);

    //this is one to one map -> 
    ObjectFactory.map(User.class, File.class);
    ObjectFactory.map(Category.class, File.class);
    ObjectFactory.map(User.class, FileDownload.class);
    ObjectFactory.map(File.class, FilePacket.class);
    ObjectFactory.map(User.class, FilePacket.class);
    ObjectFactory.map(User.class, Packet.class);
    //end of one to one map <-

    ObjectFactory.setAutoRemove(true);
    ObjectFactory.map(File.class, FileDownload.class);

    //and the one and only many to many with table manual map...
    ObjectFactory.list(Packet.class).stream().forEach(packet -> {

        List<FilePacket> collect = ObjectFactory.list(FilePacket.class).stream()
                .filter(filepacket -> filepacket.getPacketId() == packet.getId()).collect(Collectors.toList());

        for (Iterator<FilePacket> fpacket = collect.iterator(); fpacket.hasNext();) {
            packet.getFiles().add(fpacket.next().getFile());
            fpacket.remove();
        }
        //.forEach(rightFilePacket -> packet.getFiles().add(rightFilePacket.getFile()));
    });

}