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.salesmanager.core.util.StringUtil.java

/**
 * Build a ; delimited line with the values contained in the list
 * //from  ww  w  . ja  v  a2  s  . c  o m
 * @param list
 * @return
 */
public static String buildMultipleValueLine(List list) {

    if (list != null & list.size() > 0) {

        Iterator i = list.iterator();
        StringBuffer linebuffer = new StringBuffer();
        int icount = 0;
        while (i.hasNext()) {
            String value = (String) i.next();
            linebuffer.append(value);
            if (icount < list.size() - 1)
                linebuffer.append(";");
            icount++;
        }
        return linebuffer.toString();
    } else {
        return null;
    }
}

From source file:com.elogiclab.vosao.plugin.FlickrUtils.java

public static String buildQueryString(Map<String, String> params, String apiSecret) {
    StringBuilder result = new StringBuilder();
    StringBuffer unencoded = new StringBuffer(apiSecret);
    List keyList = new ArrayList(params.keySet());
    Collections.sort(keyList);//ww  w.  j  av a2  s  .c  om
    Iterator it = keyList.iterator();
    while (it.hasNext()) {
        if (result.length() > 0) {
            result.append("&");
        }
        String key = it.next().toString();
        result.append(key);
        result.append("=");
        result.append(params.get(key));
        unencoded.append(key);
        unencoded.append(params.get(key));
    }
    System.out.println(unencoded);

    String sig = digest(unencoded.toString());
    result.append("&api_sig=");
    result.append(sig);
    return result.toString();

}

From source file:com.astamuse.asta4d.web.form.flow.base.StepAwaredValidationFormHelper.java

static final Object getValidationTargetByAnnotation(Object form, String step) {
    String cacheKey = step + "@" + form.getClass().getName();
    Optional<Field> oField = ValidationTargetFieldCache.get(cacheKey);

    if (oField == null) {
        List<Field> list = new ArrayList<>(ClassUtil.retrieveAllFieldsIncludeAllSuperClasses(form.getClass()));
        Iterator<Field> it = list.iterator();
        while (it.hasNext()) {
            Field f = it.next();// w w w  .  ja  v  a  2s  .  com
            StepAwaredValidationTarget vtAnno = f.getAnnotation(StepAwaredValidationTarget.class);
            if (vtAnno == null) {
                continue;
            }
            String representingStep = vtAnno.value();
            if (step.equals(representingStep)) {
                oField = Optional.of(f);
                break;
            }
        }
        if (oField == null) {
            oField = Optional.empty();
        }
        if (Configuration.getConfiguration().isCacheEnable()) {
            Map<String, Optional<Field>> newCache = new HashMap<>(ValidationTargetFieldCache);
            newCache.put(cacheKey, oField);
            ValidationTargetFieldCache = newCache;
        }
    }

    if (oField.isPresent()) {
        try {
            return FieldUtils.readField(oField.get(), form, true);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    } else {
        return form;
    }
}

From source file:Main.java

public static List<Map<String, Object>> setFirstMapFromList(List<Map<String, Object>> list, String field,
        String value) {//from w  w w  .  j  a v  a  2 s . c o m

    List<Map<String, Object>> collection = new ArrayList<Map<String, Object>>();
    for (Iterator<Map<String, Object>> iter = list.iterator(); iter.hasNext();) {

        Map<String, Object> map = iter.next();
        String deField = map.get(field).toString();
        if (deField.equalsIgnoreCase(value)) {
            collection.add(map);
            collection.addAll(list);

            list.clear();
            list.addAll(collection);
            break;
        }
    }
    return list;
}

From source file:FileUtils.java

static public boolean patternMatches(List patterns, String name) {
    if (patterns == null)
        return false;

    for (Iterator it = patterns.iterator(); it.hasNext();) {
        String pat = (String) it.next();

        if (patternMatches(pat, name))
            return true;
    }/*w  ww.  j a va  2  s  . c o m*/

    return false;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.ReadAllStudentsAndGroups.java

@Atomic
public static InfoSiteStudentsAndGroups run(String groupingId) throws FenixServiceException {
    InfoSiteStudentsAndGroups infoSiteStudentsAndGroups = new InfoSiteStudentsAndGroups();

    Grouping grouping = FenixFramework.getDomainObject(groupingId);

    if (grouping == null) {
        throw new ExistingServiceException();
    }/* w  w w  .j a  va 2  s. co m*/

    List infoSiteStudentsAndGroupsList = new ArrayList();
    List studentGroups = getAllStudentGroups(grouping);
    Iterator iterStudentGroups = studentGroups.iterator();
    while (iterStudentGroups.hasNext()) {

        Collection studentGroupAttendList;
        StudentGroup studentGroup = (StudentGroup) iterStudentGroups.next();

        studentGroupAttendList = studentGroup.getAttendsSet();

        Iterator iterStudentGroupAttendList = studentGroupAttendList.iterator();
        InfoSiteStudentInformation infoSiteStudentInformation = null;
        InfoSiteStudentAndGroup infoSiteStudentAndGroup = null;
        Attends attend = null;

        while (iterStudentGroupAttendList.hasNext()) {
            infoSiteStudentInformation = new InfoSiteStudentInformation();
            infoSiteStudentAndGroup = new InfoSiteStudentAndGroup();

            attend = (Attends) iterStudentGroupAttendList.next();

            infoSiteStudentAndGroup.setInfoStudentGroup(InfoStudentGroup.newInfoFromDomain(studentGroup));

            infoSiteStudentInformation.setNumber(attend.getRegistration().getNumber());

            infoSiteStudentInformation.setName(attend.getRegistration().getPerson().getName());

            infoSiteStudentInformation.setUsername((attend.getRegistration().getPerson().getUsername()));

            infoSiteStudentInformation.setEmail(attend.getRegistration().getPerson().getEmail());

            infoSiteStudentInformation.setPersonID(attend.getRegistration().getPerson().getExternalId());

            infoSiteStudentAndGroup.setInfoSiteStudentInformation(infoSiteStudentInformation);

            infoSiteStudentsAndGroupsList.add(infoSiteStudentAndGroup);
        }
    }

    Collections.sort(infoSiteStudentsAndGroupsList, new BeanComparator("infoStudentGroup.groupNumber"));

    infoSiteStudentsAndGroups.setInfoSiteStudentsAndGroupsList(infoSiteStudentsAndGroupsList);
    infoSiteStudentsAndGroups.setInfoGrouping(InfoGrouping.newInfoFromDomain(grouping));

    return infoSiteStudentsAndGroups;
}

From source file:com.mrmq.uyoutube.data.MyUploads.java

public static List<Video> getChannelVideos(YouTube youtube, Channel channel) throws IOException {
    List<Video> lstVideo = Lists.newArrayList();

    List<PlaylistItem> playList = getPlaylistItems(youtube, channel);
    if (playList != null) {
        Iterator<PlaylistItem> iter = playList.iterator();
        while (iter.hasNext()) {
            PlaylistItem playlistItem = iter.next();
            lstVideo.add(Converter.convert(playlistItem));
        }/*w w w  .  ja  va  2s  . co m*/
    }

    return lstVideo;
}

From source file:com.mirth.connect.client.ui.util.VariableListUtil.java

public static void getStepVariables(Set<String> targetSet, Transformer transformer, boolean includeLocalVars,
        int row) {

    // add only the global variables
    List<Step> connectorSteps = transformer.getSteps();
    Iterator<Step> stepIterator = connectorSteps.iterator();
    String varPattern = GLOBAL_AND_CHANNEL_VARIABLE_PATTERN;
    if (includeLocalVars) {
        varPattern = LOCAL_VARIABLE_PATTERN;
    }//from w  w w  .  j a va2  s . c om
    int currentRow = 0;
    while (stepIterator.hasNext()) {
        if (row > -1 && row <= currentRow) {
            break;
        }
        Pattern pattern = Pattern.compile(varPattern);
        String scriptWithoutComments = getScriptWithoutComments(stepIterator.next().getScript());

        Matcher matcher = pattern.matcher(scriptWithoutComments);
        while (matcher.find()) {
            targetSet.add(getMapKey(matcher));
        }
        currentRow++;
    }
}

From source file:Main.java

public static double readHashTopValue(HashMap<String, Integer> scores, int k) {
    List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(scores.entrySet());
    int count = 0;
    int value = 0;
    double res = 0;
    for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); count < k && it.hasNext();) {
        Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next();
        value = (Integer) entry.getValue();
        res += (double) value * Math.log(2) / Math.log(count + 2);
        // res += (Integer) entry.getValue();
        count++;/*from  ww  w . ja v a  2 s. c  o  m*/
    }
    return res;
}

From source file:com.eatnumber1.util.io.FileUtils.java

/**
 * Checks if f2 is in a subdirectory of f1.
 *
 * @param f2 The file to check if it is in a subdir of f1.
 * @param f1 The file which may be in a superdir of f2.
 * @return Whether f2 is in a subdirectory of f1.
 *//*from   w  ww .j  a  v  a  2 s  . com*/
public static boolean isSubdirOf(@NotNull File f2, @NotNull File f1) {
    if (!f1.isDirectory())
        return false;
    List<File> f1_dirs = getFileElements(f1), f2_dirs = getFileElements(f2);
    Iterator<File> f1_iter = f1_dirs.iterator(), f2_iter = f2_dirs.iterator();
    while (f1_iter.hasNext() && f2_iter.hasNext()) {
        if (!f1_iter.next().equals(f2_iter.next()))
            return false;
    }
    return true;
}