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.zving.platform.SysInfo.java

public static void uploadDB(HttpServletRequest request, HttpServletResponse response) {
    try {//  www.  j av  a  2  s.co m
        DiskFileItemFactory fileFactory = new DiskFileItemFactory();
        ServletFileUpload fu = new ServletFileUpload(fileFactory);
        List fileItems = fu.parseRequest(request);
        fu.setHeaderEncoding("UTF-8");
        Iterator iter = fileItems.iterator();

        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (!(item.isFormField())) {
                String OldFileName = item.getName();
                System.out.println("Upload DB FileName:" + OldFileName);
                long size = item.getSize();
                if ((((OldFileName == null) || (OldFileName.equals("")))) && (size == 0L)) {
                    continue;
                }
                OldFileName = OldFileName.substring(OldFileName.lastIndexOf("\\") + 1);
                String ext = OldFileName.substring(OldFileName.lastIndexOf("."));
                if (!(ext.toLowerCase().equals(".dat"))) {
                    response.sendRedirect("DBUpload.jsp?Error=?dat?");
                    return;
                }
                final String FileName = Config.getContextRealPath() + "WEB-INF/data/backup/DBUpload_"
                        + DateUtil.getCurrentDate("yyyyMMddHHmmss") + ".dat";
                item.write(new File(FileName));

                LongTimeTask ltt = LongTimeTask.getInstanceByType("Install");
                if (ltt != null) {
                    response.sendRedirect("DBUpload.jsp?Error=??");
                    return;
                }
                SessionListener.forceExit();
                Config.isAllowLogin = false;

                ltt = new LongTimeTask() {
                    public void execute() {
                        DBImport di = new DBImport();
                        di.setTask(this);
                        di.importDB(FileName, "Default");
                        setPercent(100);
                        Config.loadConfig();
                        CronManager.getInstance().init();
                    }
                };
                ltt.setType("Install");
                ltt.setUser(User.getCurrent());
                ltt.start();
                response.sendRedirect("DBUpload.jsp?TaskID=" + ltt.getTaskID());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Config.isAllowLogin = true;
    }
}

From source file:com.comphenix.protocol.events.PacketMetadata.java

public static <T> Optional<T> remove(Object packet, String key) {
    Validate.notNull(key, "Null keys are not permitted!");

    if (META_CACHE == null) {
        return Optional.empty();
    }//from   w  ww  .java 2 s.  c  om

    List<MetaObject> packetMeta = META_CACHE.getIfPresent(packet);
    if (packetMeta == null) {
        return Optional.empty();
    }

    Optional<T> value = Optional.empty();
    Iterator<MetaObject> iter = packetMeta.iterator();
    while (iter.hasNext()) {
        MetaObject meta = iter.next();
        if (meta.key.equals(key)) {
            value = Optional.of((T) meta.value);
            iter.remove();
        }
    }

    return value;
}

From source file:com.cognifide.cq.cqsm.core.utils.MessagingUtils.java

public static String unknownPermissions(List<String> permissions) {
    if (permissions.size() == 1) {
        return "Unknown permission: " + permissions.get(0);
    }//  ww  w .j  a  va 2 s .  c  o  m
    StringBuilder result = new StringBuilder();
    result.append("Unknown permissions: ");
    Iterator<String> it = permissions.iterator();

    while (it.hasNext()) {
        result.append(it.next());
        if (it.hasNext()) {
            result.append(", ");
        }
    }

    return result.toString();
}

From source file:com.sun.socialsite.web.ui.admin.menu.MenuHelper.java

/**
 * Unmarshall the given input stream into our defined
 * set of Java objects./*from w  ww.  j  a  v a 2  s . co  m*/
 **/
private static ParsedMenu unmarshall(InputStream instream) throws IOException, JDOMException {

    if (instream == null)
        throw new IOException("InputStream is null!");

    ParsedMenu config = new ParsedMenu();

    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(instream);

    Element root = doc.getRootElement();
    List<?> menus = root.getChildren("menu");
    Iterator<?> iter = menus.iterator();
    while (iter.hasNext()) {
        Element e = (Element) iter.next();
        config.addTab(elementToParsedTab(e));
    }

    return config;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step7bConvArgRankProducer.java

@SuppressWarnings("unchecked")
public static void prepareData(String[] args) throws Exception {
    String inputDir = args[0];//from  ww  w . java  2 s  .  c o  m
    File outputDir = new File(args[1]);

    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }

    List<File> files = IOHelper.listXmlFiles(new File(inputDir));

    // take only the gold data for this task
    String prefix = "all_DescendingScoreArgumentPairListSorter";
    Iterator<File> iterator = files.iterator();
    while (iterator.hasNext()) {
        File file = iterator.next();

        if (!file.getName().startsWith(prefix)) {
            iterator.remove();
        }
    }

    int totalArgumentsCounter = 0;

    DescriptiveStatistics statsPerTopic = new DescriptiveStatistics();

    for (File file : files) {
        List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream()
                .fromXML(file);

        String name = file.getName().replaceAll(prefix, "").replaceAll("\\.xml", "");

        PrintWriter pw = new PrintWriter(new File(outputDir, name + ".csv"), "utf-8");
        pw.println("#id\trank\targument");

        Graph graph = buildGraphFromPairs(argumentPairs);

        Map<String, Argument> arguments = collectArguments(argumentPairs);

        int argumentsPerTopicCounter = arguments.size();

        PageRank pageRank = new PageRank();
        pageRank.setVerbose(true);
        pageRank.init(graph);

        for (Node node : graph) {
            String id = node.getId();
            double rank = pageRank.getRank(node);

            System.out.println(id);

            Argument argument = arguments.get(id);

            String text = Step7aLearningDataProducer.multipleParagraphsToSingleLine(argument.getText());

            pw.printf(Locale.ENGLISH, "%s\t%.5f\t%s%n", argument.getId(), rank, text);
        }

        totalArgumentsCounter += argumentsPerTopicCounter;
        statsPerTopic.addValue(argumentsPerTopicCounter);

        pw.close();
    }

    System.out.println("Total gold arguments: " + totalArgumentsCounter);
    System.out.println(statsPerTopic);
}

From source file:ch.qos.logback.audit.client.ImprovedAuditorFactory.java

public static int getHighestLevel(long threshold, StatusManager sm) {
    List filteredList = StatusUtil.filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
    int maxLevel = 0;
    Iterator i$ = filteredList.iterator();

    while (i$.hasNext()) {
        Status s = (Status) i$.next();/*from   w  w  w .ja  v  a  2s  .  co m*/
        if (s.getLevel() > maxLevel) {
            maxLevel = s.getLevel();
        }
    }

    return maxLevel;
}

From source file:ca.sfu.federation.utils.IContextUtils.java

public static void logUpdateOrder(INamed Parent, List<INamed> Elements) {
    if (Parent != null && Elements != null) {
        Iterator en = Elements.iterator();
        StringBuilder sb = new StringBuilder();
        sb.append(Parent.getName());/*from  w w  w.  j a  va 2  s. c  om*/
        sb.append(" update event. Update sequence is: ");
        while (en.hasNext()) {
            INamed named = (INamed) en.next();
            sb.append(named.getName());
            sb.append(" ");
        }
        logger.log(Level.FINE, sb.toString());
    }
}

From source file:Main.java

public static Map<String, Integer> sortByValue(Map<String, Integer> map) {
    List list = new LinkedList(map.entrySet());
    Collections.sort(list, new Comparator() {

        @Override//from w  w w.j a  v  a  2 s. co  m
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o2)).getValue()).compareTo(((Map.Entry) (o1)).getValue());
        }
    });

    Map result = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.clustercontrol.infra.factory.UpdateInfraCheckResult.java

/**
 * @throws InfraManagementNotFound /* w  w  w .j  a v  a2 s.  c  o m*/
 */
public static void update(String managementId, String moduleId, List<ModuleNodeResult> resultList) {
    m_log.debug("update() : start");

    m_log.debug(String.format("update() : managementId = %s", managementId));

    // ???
    try {
        new SelectInfraManagement().get(managementId, ObjectPrivilegeMode.READ);
    } catch (InfraManagementNotFound | InvalidRole | HinemosUnknown e) {
        m_log.warn("update " + e.getClass().getName() + ", " + e.getMessage());
    }

    List<InfraCheckResult> entities = QueryUtil.getInfraCheckResultFindByModuleId(managementId, moduleId);

    List<ModuleNodeResult> newResultList = new ArrayList<>(resultList);
    List<InfraCheckResult> oldResultList = new ArrayList<>(entities);

    m_log.info("newResult.size=" + newResultList.size() + ", oldResult.size=" + oldResultList.size());

    // update
    Iterator<InfraCheckResult> oldItr = oldResultList.iterator();
    while (oldItr.hasNext()) {
        InfraCheckResult oldResult = oldItr.next();
        Iterator<ModuleNodeResult> newItr = newResultList.iterator();
        while (newItr.hasNext()) {
            ModuleNodeResult newResult = newItr.next();
            if (oldResult.getId().getManagementId().equals(managementId)
                    && oldResult.getId().getModuleId().equals(moduleId)
                    && oldResult.getId().getNodeId().equals(newResult.getFacilityId())) {
                oldResult.setResult(newResult.getResult());

                newItr.remove();
                oldItr.remove();
                break;
            }
        }
    }

    m_log.info("newResult.size=" + newResultList.size() + ", oldResult.size=" + oldResultList.size());

    // insert
    for (ModuleNodeResult newResult : newResultList) {
        InfraCheckResult resultEntity = new InfraCheckResult(managementId, moduleId, newResult.getFacilityId());
        HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
        em.persist(resultEntity);
        resultEntity.setResult(newResult.getResult());
    }

    // delete
    for (InfraCheckResult oldResult : oldResultList) {
        oldResult.removeSelf();
    }

    m_log.debug("update() : end");
}

From source file:eu.stratosphere.pact.test.util.minicluster.NepheleMiniCluster.java

private static InterfaceAddress getIPInterfaceAddress(boolean preferIPv4) throws Exception, SocketException {
    final List<InterfaceAddress> interfaces = getNetworkInterface().getInterfaceAddresses();
    final Iterator<InterfaceAddress> it = interfaces.iterator();
    final List<InterfaceAddress> matchesIPv4 = new ArrayList<InterfaceAddress>();
    final List<InterfaceAddress> matchesIPv6 = new ArrayList<InterfaceAddress>();

    while (it.hasNext()) {
        final InterfaceAddress ia = it.next();
        if (ia.getBroadcast() != null) {
            if (ia.getAddress() instanceof Inet4Address) {
                matchesIPv4.add(ia);/*ww  w. j  ava  2  s . c  o  m*/
            } else {
                matchesIPv6.add(ia);
            }
        }
    }

    if (matchesIPv4.isEmpty() && matchesIPv6.isEmpty()) {
        throw new Exception(
                "Interface " + getNetworkInterface().getName() + " has no interface address attached.");
    }

    if (preferIPv4 && !matchesIPv4.isEmpty()) {
        for (InterfaceAddress ia : matchesIPv4) {
            if ((ia.getAddress().toString().contains("192") || ia.getAddress().toString().contains("10"))) {
                return ia;
            }
        }
        return matchesIPv4.get(0);
    }

    return !matchesIPv6.isEmpty() ? matchesIPv6.get(0) : matchesIPv4.get(0);
}