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.ibm.watson.movieapp.dialog.fvt.config.Utils.java

/**
 * parseResp - Checks to see if the response to the question is in the expected list.
 * @param question/* w  ww. j a v  a  2  s .c om*/
 * @return boolean found in list or not.
 */
public static boolean parseResp(BaseQuestion question) {

    boolean found = false;

    String response = question.getResponse().getResponseText();

    List<String> expectedResponse = question.getExpectedResponse();

    Iterator<String> iterator = expectedResponse.iterator();
    while (iterator.hasNext()) {

        String expectResponse = iterator.next();
        logger.info("INFO: Expected response " + expectResponse);
        //if response is contained in the list of expected responses break out of loop and return found
        if (response.contains(expectResponse)) {
            found = true;
            break;
        }
    }

    return found;
}

From source file:com.googlecode.starflow.engine.xml.NodeUtil.java

/**
 * ???/*from  w  w w  .ja  v a 2 s  .co m*/
 */
@SuppressWarnings("rawtypes")
public static List<EventElement> getTriggerEvents(Element actEl) {
    List<EventElement> events = new LinkedList<EventElement>();
    List list = actEl.selectNodes("TriggerEvents/event");
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Element el = (Element) iter.next();
        EventElement event = new EventElement();
        event.setEventType(el.attributeValue("eventType"));
        event.setAction(el.attributeValue("action"));
        event.setInvokePattern(el.attributeValue("invokePattern"));
        event.setTransactionType(el.attributeValue("transactionType"));
        event.setExceptionStrategy(el.attributeValue("exceptionStrategy"));
        events.add(event);
    }
    return events;
}

From source file:com.amalto.core.storage.datasource.DataSourceFactory.java

private static synchronized InputStream readDataSourcesConfiguration() {
    Properties configuration = MDMConfiguration.getConfiguration();
    String dataSourcesLocation = (String) configuration.get(DB_DATASOURCES);
    if (dataSourcesLocation == null) { // DB_DATASOURCES property is mandatory to continue.
        throw new IllegalStateException(DB_DATASOURCES + " is not defined in MDM configuration.");
    }/*  w  ww. ja  v  a2s  .  c  o  m*/
    String dataSourcesFileName = SystemPropertyUtils.resolvePlaceholders(dataSourcesLocation);
    InputStream configurationAsStream = null;
    // 1- Try from file (direct lookup)
    File file = new File(dataSourcesFileName);
    if (file.exists()) {
        LOGGER.info("Reading from datasource file at '" + file.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$
        try {
            configurationAsStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException("Unexpected state (file exists but can't create a stream from it).",
                    e);
        }
    }
    // 2- From class path
    if (configurationAsStream == null) {
        List<String> filePaths = Arrays.asList(dataSourcesFileName);
        Iterator<String> iterator = filePaths.iterator();

        String currentFilePath = StringUtils.EMPTY;
        while (configurationAsStream == null && iterator.hasNext()) {
            currentFilePath = iterator.next();
            configurationAsStream = Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream(currentFilePath);
        }
        if (configurationAsStream != null) {
            LOGGER.info("Reading from datasource file at '" + currentFilePath + "'."); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
    // 3- error: configuration was not found
    if (configurationAsStream == null) {
        throw new IllegalStateException(
                "Could not find datasources configuration file '" + dataSourcesFileName + "'.");
    }
    return configurationAsStream;
}

From source file:com.salesmanager.core.util.PaymentUtil.java

public static boolean isPaymentModuleCreditCardType(String paymentModule) throws Exception {

    PaymentService paymentService = (PaymentService) ServiceFactory.getService(ServiceFactory.PaymentService);

    List payments = paymentService.getPaymentMethods();

    if (payments != null) {
        Iterator i = payments.iterator();
        while (i.hasNext()) {
            CoreModuleService cms = (CoreModuleService) i.next();
            if (cms.getCoreModuleName().equals(paymentModule)) {
                if (cms.getCoreModuleServiceCode() == 2 && cms.getCoreModuleServiceSubtype() == 1) {
                    return true;
                }// w ww .  j  a  va  2s .c  o  m
            }
        }
    }

    return false;
}

From source file:com.googlecode.starflow.engine.xml.NodeUtil.java

/**
 * ??/* w  w  w.  ja v a 2 s  .  c  o  m*/
 */
@SuppressWarnings("rawtypes")
public static Map<String, String> getExtProperties(Element el) {
    Map<String, String> map = new HashMap<String, String>();

    List list = el.selectNodes(StarFlowNames.FLOW_EXT_PROPERTY);
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Element e = (Element) iter.next();
        map.put(e.attributeValue("key"), e.attributeValue("value"));
    }
    return map;
}

From source file:com.googlecode.starflow.engine.xml.NodeUtil.java

/**
 * ---//ww w. j  a  v a 2s . co m
 */
@SuppressWarnings("rawtypes")
public static List<FreeActElement> getActFreeActs(Element actEl) {
    List<FreeActElement> events = new CopyOnWriteArrayList<FreeActElement>();
    List list = actEl.selectNodes(StarFlowNames.ACT_FREE_ACT);
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Element el = (Element) iter.next();
        FreeActElement e = new FreeActElement();
        e.setId(el.attributeValue(StarFlowNames.ACT_FREE_ACT_ID));
        e.setName(el.attributeValue(StarFlowNames.ACT_FREE_ACT_NAME));
        e.setType(el.attributeValue(StarFlowNames.ACT_FREE_ACT_TYPE));
        events.add(e);
    }
    return events;
}

From source file:br.ufpb.dicomflow.integrationAPI.tools.ReadService.java

private static void saveMessages(List<MessageIF> messages, File destDir) throws JAXBException, IOException {
    Iterator<MessageIF> it = messages.iterator();
    while (it.hasNext()) {
        MessageIF messageIF = (MessageIF) it.next();
        ServiceIF service = messageIF.getService();
        Logger.v(rb.getString("loaded-service") + service.getName() + " - " + service.getAction() + " - "
                + service.getMessageID());

        JAXBContext jaxbContext = JAXBContext.newInstance(messageIF.getService().getClass());
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        FileOutputStream fos = new FileOutputStream(destDir.getAbsolutePath() + File.pathSeparator
                + service.getName() + "_" + service.getAction() + "_" + service.getMessageID());
        jaxbMarshaller.marshal(messageIF.getService(), fos);

        if (messageIF.getAttach() != null && messageIF.getAttach().length > 0) {
            fos = new FileOutputStream(destDir.getAbsolutePath() + File.pathSeparator + service.getName() + "_"
                    + service.getAction() + "_" + service.getMessageID() + "_attach");
            fos.write(messageIF.getAttach());
            fos.close();//w  ww .j ava  2  s  .  c o m
        }

    }
}

From source file:com.bstek.dorado.data.model.TestDataHolder.java

public static void updateDomainTestData2(List<Employee> employees)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (Iterator<Employee> it = employees.iterator(); it.hasNext();) {
        Employee employee = it.next();/*from   w  w  w.  j  a  v  a  2s . c  om*/
        EntityState state = EntityUtils.getState(employee);
        if (state == EntityState.DELETED) {
            demainTestData2.remove(employee.getId());
            it.remove();
        } else if (state == EntityState.MODIFIED) {
            Employee e = demainTestData2.get(employee.getId());
            employee.setSalary(employee.getSalary() + 1);
            if (e != null) {
                PropertyUtils.copyProperties(e, employee);
            }
            EntityUtils.setState(employee, EntityState.NONE);
        } else if (state == EntityState.NEW) {
            Employee e = new Employee();
            PropertyUtils.copyProperties(e, employee);
            demainTestData2.put(e.getId(), e);
            EntityUtils.setState(employee, EntityState.NONE);
        }
    }
}

From source file:com.googlecode.starflow.engine.xml.NodeUtil.java

/**
 * ???/*  www  . j ava2 s .com*/
 */
@SuppressWarnings("rawtypes")
public static List<OperationElement> getOperations(Element actEl) {
    List<OperationElement> operationXmls = new LinkedList<OperationElement>();
    List list = actEl.selectNodes(StarFlowNames.ACT_OPERATION);
    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Element el = (Element) iter.next();
        OperationElement opXml = new OperationElement();
        opXml.setId(el.attributeValue(StarFlowNames.ACT_OPERATION_ID));
        opXml.setName(el.attributeValue(StarFlowNames.ACT_OPERATION_NAME));
        opXml.setCode(el.attributeValue(StarFlowNames.ACT_OPERATION_CODE));
        opXml.setAction(el.attributeValue(StarFlowNames.ACT_OPERATION_ACTION));
        operationXmls.add(opXml);
    }
    return operationXmls;
}

From source file:Main.java

private static Map sortByComparator(Map unsortMap) {
    List list = new LinkedList(unsortMap.entrySet());
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
        }/*  w  ww  .  ja v a  2  s.c o  m*/
    });
    Map sortedMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;
}