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:de.suse.swamp.core.container.SecurityManager.java

/**
 * Load user which have a variable that matches @regex set in their permstorage (preferences)
 *//*from   ww w.j  a  va  2 s  .  c o m*/
public static List loadUsersWithPerm(String regex) throws StorageException, UnknownElementException {
    List dbUsers = SecurityStorage.loadUsersWithPerm(regex);
    List users = new ArrayList();
    for (Iterator it = dbUsers.iterator(); it.hasNext();) {
        SWAMPUser user = (SWAMPUser) it.next();
        users.add(getUser(user.getUserName()));
    }
    return users;
}

From source file:com.orchestra.portale.externalauth.FbAuthenticationManager.java

/**
 * Retrieves a collection of {@link GrantedAuthority}
 *//* w  w w.  j av a 2 s  . co  m*/
private static Collection<? extends GrantedAuthority> getAuthorities(List<Role> roles_obj) {

    Iterator<Role> roles_iter = roles_obj.iterator();

    List<String> roles = new ArrayList<String>();
    while (roles_iter.hasNext()) {
        Role r = roles_iter.next();
        roles.add(r.getRole());
    }

    roles.add("ROLE_FB");

    List<GrantedAuthority> authList = getGrantedAuthorities(roles);
    return authList;
}

From source file:Util.java

/**
 * Returns a sorted iterator from an unsorted one. Use this method as a last resort,
 * since it is much less efficient then just sorting a collection that backs the
 * original iterator./*from   w  w w  . j a  va2s.c  o m*/
 */
public static Iterator sortedIterator(Iterator it, Comparator comparator) {
    List list = new ArrayList();
    while (it.hasNext()) {
        list.add(it.next());
    }

    Collections.sort(list, comparator);
    return list.iterator();
}

From source file:com.thruzero.common.core.utils.StringUtilsExt.java

/** Return iterator across all lines of a {@code String}. */
public static Iterator<String> createLineIterator(final String str) {
    String[] array = StringUtils.split(str, EnvironmentHelper.NEWLINE);
    List<String> result = Arrays.asList(array);

    return result.iterator();
}

From source file:com.networknt.mask.Mask.java

private static void maskList(DocumentContext ctx, String jsonPath, String expression) {
    ctx.configuration().addOptions(Option.AS_PATH_LIST);
    Configuration conf = Configuration.builder().options(Option.AS_PATH_LIST).build();
    DocumentContext context = JsonPath.using(conf).parse(ctx.jsonString());
    List<String> pathList = context.read(jsonPath);
    for (Iterator iterator = pathList.iterator(); iterator.hasNext();) {
        String path = (String) iterator.next();
        Object value = ctx.read(path);
        ctx.set(path, replaceWithMask(value.toString(), MASK_REPLACEMENT_CHAR.charAt(0), expression));
    }/*from www .ja v  a  2s  .c o m*/
}

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

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

    Grouping groupProperties = FenixFramework.getDomainObject(groupPropertiesId);

    if (groupProperties == null) {
        throw new ExistingServiceException();
    }//from   w w  w  . j  av a2 s.co m

    List infoSiteStudentsAndGroupsList = new ArrayList();
    List studentGroups = getStudentGroupsWithoutShiftByGroupProperties(groupProperties);
    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.setUsername(attend.getRegistration().getPerson().getUsername());

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

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

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

            infoSiteStudentAndGroup.setInfoSiteStudentInformation(infoSiteStudentInformation);

            infoSiteStudentsAndGroupsList.add(infoSiteStudentAndGroup);
        }
    }
    Collections.sort(infoSiteStudentsAndGroupsList, new BeanComparator("infoSiteStudentInformation.number"));

    infoSiteStudentsAndGroups.setInfoSiteStudentsAndGroupsList(infoSiteStudentsAndGroupsList);

    return infoSiteStudentsAndGroups;
}

From source file:Main.java

/**
 * Get the optimal preview size for the given screen size.
 * @param sizes/*from  w  w  w  . j  av a 2s.c o  m*/
 * @param screenWidth
 * @param screenHeight
 * @return
 */
public static Size getOptimalPreviewSize(List<Size> sizes, int screenWidth, int screenHeight) {
    double aspectRatio = ((double) screenWidth) / screenHeight;
    Size optimalSize = null;
    for (Iterator<Size> iterator = sizes.iterator(); iterator.hasNext();) {
        Size currSize = iterator.next();
        double curAspectRatio = ((double) currSize.width) / currSize.height;
        //do the aspect ratios equal?
        if (Math.abs(aspectRatio - curAspectRatio) < epsilon) {
            //they do
            if (optimalSize != null) {
                //is the current size smaller than the one before
                if (optimalSize.height > currSize.height && optimalSize.width > currSize.width) {
                    optimalSize = currSize;
                }
            } else {
                optimalSize = currSize;
            }
        }
    }
    if (optimalSize == null) {
        //did not find a size with the correct aspect ratio.. let's choose the smallest instead
        for (Iterator<Size> iterator = sizes.iterator(); iterator.hasNext();) {
            Size currSize = iterator.next();
            if (optimalSize != null) {
                //is the current size smaller than the one before
                if (optimalSize.height > currSize.height && optimalSize.width > currSize.width) {
                    optimalSize = currSize;
                } else {
                    optimalSize = currSize;
                }
            } else {
                optimalSize = currSize;
            }

        }
    }
    return optimalSize;
}

From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java

public static Map<String, UUID> call(List<String> names) {
    names = new ArrayList<String>(names);
    Iterator<String> iterator = names.iterator();
    while (iterator.hasNext()) {
        String playerName = iterator.next();
        if (fetchedUUIDs.containsKey(playerName)) {
            iterator.remove();/*from  www  .ja  va2  s  . c  o m*/
        }
    }
    if (names.size() == 0) {
        return readonlyFetchedUUIDs;
    }

    int count = names.size();

    DebugLogger.info("get UUIDs for " + names.size() + " player(s)");
    int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
    try {
        for (int i = 0; i < requests; i++) {
            HttpURLConnection connection = createConnection();
            String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
            writeBody(connection, body);
            JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
            count -= array.size();
            for (Object profile : array) {
                JSONObject jsonProfile = (JSONObject) profile;
                String id = (String) jsonProfile.get("id");
                String name = (String) jsonProfile.get("name");
                UUID uuid = UUIDFetcher.getUUID(id);
                fetchedUUIDs.put(name, uuid);
            }
            if (rateLimiting && i != requests - 1) {
                Thread.sleep(100L);
            }
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (count > 0) {
        MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost.");
    }
    return readonlyFetchedUUIDs;
}

From source file:Main.java

/**
 * Return an iterator for the subelements.
 * @return java.util.Iterator// www.ja  va 2s .c o m
 * @param element org.w3c.dom.Element
 * @param name java.lang.String
 */
public static Iterator getNodeIterator(Element element, String name) {
    List<Node> list = new ArrayList<Node>();
    NodeList nodeList = element.getElementsByTagName(name);

    int length = nodeList.getLength();
    for (int i = 0; i < length; i++)
        list.add(nodeList.item(i));

    return list.iterator();
}

From source file:beans.service.FileUploadTool.java

static public String FileUpload(Map<String, String> fields, List<String> filesOnServer,
        HttpServletRequest request, HttpServletResponse response) {

    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    DiskFileItemFactory factory = new DiskFileItemFactory();
    int MaxMemorySize = 10000000;
    int MaxRequestSize = MaxMemorySize;
    String tmpDir = System.getProperty("TMP", "/tmp");
    System.out.printf("temporary directory:%s", tmpDir);

    factory.setSizeThreshold(MaxMemorySize);
    factory.setRepository(new File(tmpDir));

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    // Set overall request size constraint
    upload.setSizeMax(MaxRequestSize);//from   w ww. ja  v  a 2  s .  c o m

    // Parse the request
    try {
        List<FileItem> items = upload.parseRequest(request);
        // Process the uploaded items
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();
            if (item.isFormField()) {//k -v
                String name = item.getFieldName();
                String value = item.getString();
                fields.put(name, value);
            } else {

                String fieldName = item.getFieldName();
                String fileName = item.getName();
                if (fileName == null || fileName.length() < 1) {
                    return "file name is empty.";
                }
                String localFileName = ServletConfig.fileServerRootDir + File.separator + "tmp" + File.separator
                        + fileName;
                System.out.printf("upload file:%s", localFileName);
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                File uploadedFile = new File(localFileName);
                item.write(uploadedFile);
                filesOnServer.add(localFileName);
            }

        }
        return "success";
    } catch (FileUploadException e) {
        e.printStackTrace();
        return e.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }

}