Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

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

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

/**
 * Process Drag&Drop//from  ww w . j  a v  a2s  . c o m
 * @param data
 */
public void processDnD(Object data) {
    log.debug("Playlist DnD");
    // Looking for files to drop.
    if (data instanceof List) {
        List al = (List) data;
        if ((al != null) && (al.size() > 0)) {
            ArrayList fileList = new ArrayList();
            ArrayList folderList = new ArrayList();
            ListIterator li = al.listIterator();
            while (li.hasNext()) {
                File f = (File) li.next();
                if ((f.exists()) && (f.canRead())) {
                    if (f.isFile())
                        fileList.add(f);
                    else if (f.isDirectory())
                        folderList.add(f);
                }
            }
            addFiles(fileList);
            addDirs(folderList);
        }
    } else if (data instanceof String) {
        String files = (String) data;
        if ((files.length() > 0)) {
            ArrayList fileList = new ArrayList();
            ArrayList folderList = new ArrayList();
            StringTokenizer st = new StringTokenizer(files, System.getProperty("line.separator"));
            // Transfer files dropped.
            while (st.hasMoreTokens()) {
                String path = st.nextToken();
                if (path.startsWith("file://")) {
                    path = path.substring(7, path.length());
                    if (path.endsWith("\r"))
                        path = path.substring(0, (path.length() - 1));
                }
                File f = new File(path);
                if ((f.exists()) && (f.canRead())) {
                    if (f.isFile())
                        fileList.add(f);
                    else if (f.isDirectory())
                        folderList.add(f);
                }
            }
            addFiles(fileList);
            addDirs(folderList);
        }
    } else {
        log.info("Unknown dropped objects");
    }
}

From source file:gobblin.salesforce.SalesforceExtractor.java

public String buildUrl(String path, List<NameValuePair> qparams) throws RestApiClientException {
    URIBuilder builder = new URIBuilder();
    builder.setPath(path);/*from  www.  j av  a  2s.c  om*/
    ListIterator<NameValuePair> i = qparams.listIterator();
    while (i.hasNext()) {
        NameValuePair keyValue = i.next();
        builder.setParameter(keyValue.getName(), keyValue.getValue());
    }
    URI uri;
    try {
        uri = builder.build();
    } catch (Exception e) {
        throw new RestApiClientException("Failed to build url; error - " + e.getMessage(), e);
    }
    return new HttpGet(uri).getURI().toString();
}

From source file:org.ambraproject.article.service.BrowseServiceImpl.java

/**
 * Given a list of Article Groups with correctly ordered articles create a CSV string of article URIs. The URIs will
 * be in the order that they show up on the TOC.
 *
 * @param articleGroups the list of TOCArticleGroup to process.
 * @return a string of a comma separated list of article URIs
 *///from w  w w.  j a  va  2 s. c o  m
public String articleGrpListToCSV(List<TOCArticleGroup> articleGroups) {
    StringBuilder articleList = new StringBuilder();
    Iterator i = articleGroups.listIterator();

    // Group Loop
    while (i.hasNext()) {
        TOCArticleGroup ag = (TOCArticleGroup) i.next();
        Iterator y = ag.articles.listIterator();

        // Article Loop
        while (y.hasNext()) {
            ArticleInfo ai = (ArticleInfo) y.next();
            articleList.append(ai.doi);

            if (y.hasNext())
                articleList.append(',');
        }
        if (i.hasNext())
            articleList.append(',');
    }
    return articleList.toString();
}

From source file:TimestreamsTests.java

/**
 * Returns a HMAC for given parameters/*  w  w  w  .j a  va2  s  .c o m*/
 * 
 * @param params
 *            are all the parameters to hash
 * @return the HMAC as a String
 */
private String getSecurityString(List<String> params) {
    java.util.Collections.sort(params);
    String toHash = "";
    ListIterator<String> it = params.listIterator();
    while (it.hasNext()) {
        toHash += it.next() + "&";
    }
    System.out.println(toHash);
    return hmacString(toHash, PRIKEY, "HmacSHA256");
}

From source file:TimestreamsTests.java

/**
 * Creates a HMAC for given parameters and returns a URL with security
 * parameters//www .  j a  v  a  2s . com
 * 
 * @param url
 *            is the URL to add the security parameters to
 * @param params
 *            are all the parameters to hash
 * @param now
 *            is a UTC timestamp
 * @return the URL with security parameters
 */
private String getSecurityString(String url, List<String> params, String now) {
    java.util.Collections.sort(params);
    String toHash = "";
    ListIterator<String> it = params.listIterator();
    while (it.hasNext()) {
        toHash += it.next();
    }
    String hmac = hmacString(toHash, PRIKEY, "HmacSHA256");
    String urlStr = url + "?pubkey=" + PUBKEY + "&now=" + now;
    urlStr += "&hmac=" + hmac;
    return urlStr;
}

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

private void LoadAstrid() {
    // Look for a zip file in the proper location
    String loc = Environment.getExternalStorageDirectory() + "/AstridImport/";
    AlertDialog.Builder errorBuilder = new AlertDialog.Builder(this);
    errorBuilder.setTitle("Error reading Astrid Import!");
    ZipInputStream zipStream = null;
    InputStream stream = null;//from  ww  w.j a v  a2 s .  c  om
    try {
        // Try to safely open the file
        String errText = "Cannot find Astrid file in " + loc;
        File astridDir = new File(loc);
        if (!astridDir.isDirectory()) {
            throw new Exception(errText);
        }

        File[] files = astridDir.listFiles();
        if (files.length != 1) {
            throw new Exception(errText);
        }

        File astridFile = files[0];
        if (!astridFile.isFile()) {
            throw new Exception(errText);
        }

        // Try to unzip the file and unpack the tasks
        errText = "Could not unzip file " + astridFile.getAbsolutePath();
        stream = new FileInputStream(astridFile);
        zipStream = new ZipInputStream(stream);

        ZipEntry tasksEntry = null;
        while ((tasksEntry = zipStream.getNextEntry()) != null) {
            if (tasksEntry.getName().equals("tasks.csv")) {
                break;
            }
        }
        if (tasksEntry == null) {
            throw new Exception(errText);
        }

        int size = (int) tasksEntry.getSize();
        byte tasksContent[] = new byte[size];
        int offset = 0;
        while (size != 0) {
            int read = zipStream.read(tasksContent, offset, size);
            if (read == 0) {
                throw new Exception(errText);
            }
            offset += read;
            size -= read;
        }

        String tasksString = new String(tasksContent, "UTF-8");

        // Parse the tasks in the task list
        errText = "Could not parse task list";
        List<String> taskLines = new LinkedList<String>(Arrays.asList(tasksString.split("\n")));
        // Remove the header row
        taskLines.remove(0);
        // Some tasks have newlines in quotes, so we have to adjust for that.
        ListIterator<String> it = taskLines.listIterator();
        while (it.hasNext()) {
            String task = it.next();
            while (CountQuotes(task) % 2 == 1) {
                it.remove();
                task += it.next();
            }
            it.set(task);
        }
        for (String taskLine : taskLines) {
            List<String> taskFields = new LinkedList<String>(Arrays.asList(taskLine.split(",", -1)));
            // Some tasks have commas in quotes, so we have to adjust for that.
            it = taskFields.listIterator();
            while (it.hasNext()) {
                String field = it.next();
                while (CountQuotes(field) % 2 == 1) {
                    it.remove();
                    field += it.next();
                }
                it.set(field);
            }

            Task taskElement = new Task();
            taskElement.mName = taskFields.get(0);
            taskElement.mDescription = taskFields.get(8);

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);

            taskElement.mDueDate = Calendar.getInstance();
            taskElement.mDueDate.setTime(dateFormat.parse(taskFields.get(4)));
            String completedString = taskFields.get(9);
            taskElement.mCompletedDate = Calendar.getInstance();
            if (completedString.equals("")) {
                taskElement.mCompletedDate.setTimeInMillis(0);
            } else {
                taskElement.mCompletedDate.setTime(dateFormat.parse(completedString));
            }
            taskElement.mRepeatUnit = Task.RepeatUnit.NONE;
            taskElement.mRepeatTime = 0;
            taskElement.mRepeatFromComplete = false;
            String repeatString = taskFields.get(6);
            String repeatFields[] = repeatString.split(":");
            if (repeatFields[0].equals("RRULE")) {
                repeatFields = repeatFields[1].split(";");
                String freqFields[] = repeatFields[0].split("=");
                if (freqFields[0].equals("FREQ")) {
                    if (freqFields[1].equals("YEARLY")) {
                        taskElement.mRepeatUnit = Task.RepeatUnit.YEARS;
                    } else if (freqFields[1].equals("MONTHLY")) {
                        taskElement.mRepeatUnit = Task.RepeatUnit.MONTHS;
                    } else if (freqFields[1].equals("WEEKLY")) {
                        taskElement.mRepeatUnit = Task.RepeatUnit.WEEKS;
                    } else if (freqFields[1].equals("DAILY")) {
                        taskElement.mRepeatUnit = Task.RepeatUnit.DAYS;
                    }
                }
                freqFields = repeatFields[1].split("=");
                if (freqFields[0].equals("INTERVAL")) {
                    taskElement.mRepeatTime = Integer.valueOf(freqFields[1]);
                }
                if (repeatFields.length > 2 && repeatFields[2] != null) {
                    freqFields = repeatFields[2].split("=");
                    if (freqFields[0].equals("FROM") && freqFields[1].equals("COMPLETION")) {
                        taskElement.mRepeatFromComplete = true;
                    }
                }
            }
            mDB.AddTask(taskElement);
        }

        RefreshView();
    } catch (Exception e) {
        AlertDialog dlg = errorBuilder.setMessage(e.getMessage()).create();
        dlg.show();
    } finally {

        try {
            if (zipStream != null) {
                zipStream.close();
            }
            if (stream != null) {
                stream.close();
            }
        } catch (Exception e) {
            AlertDialog dlg = errorBuilder.setMessage(e.getMessage()).create();
            dlg.show();
        }
    }
}

From source file:org.apache.hadoop.registry.client.impl.zk.RegistrySecurity.java

/**
 * Split up a list of the form//w ww  . jav  a 2s.c  om
 * <code>sasl:mapred@,digest:5f55d66, sasl@yarn@EXAMPLE.COM</code>
 * into a list of possible ACL values, trimming as needed
 *
 * The supplied realm is added to entries where
 * <ol>
 *   <li>the string begins "sasl:"</li>
 *   <li>the string ends with "@"</li>
 * </ol>
 * No attempt is made to validate any of the acl patterns.
 *
 * @param aclString list of 0 or more ACLs
 * @param realm realm to add
 * @return a list of split and potentially patched ACL pairs.
 *
 */
public List<String> splitAclPairs(String aclString, String realm) {
    List<String> list = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(aclString));
    ListIterator<String> listIterator = list.listIterator();
    while (listIterator.hasNext()) {
        String next = listIterator.next();
        if (next.startsWith(SCHEME_SASL + ":") && next.endsWith("@")) {
            listIterator.set(next + realm);
        }
    }
    return list;
}

From source file:org.apache.hadoop.hbase.regionserver.transactional.TrxTransactionState.java

public synchronized void applyDeletes(final List<Cell> input, final long minTime, final long maxTime) {
    if (deletes.isEmpty()) {
        return;/* w w w.  j a va 2s.c om*/
    }
    for (ListIterator<Cell> itr = input.listIterator(); itr.hasNext();) {
        Cell included = applyDeletes(itr.next(), minTime, maxTime);
        if (null == included) {
            itr.remove();
        }
    }
}

From source file:es.uvigo.ei.sing.adops.operations.running.ExecuteExperimentBySteps.java

private void replaceSequenceNamesAln(File inputFile, File outputFile) throws IOException {
    final Map<String, String> names = this.experiment.getNames();
    final List<String> lines = FileUtils.readLines(inputFile);

    int maxLength = Integer.MIN_VALUE;
    for (Map.Entry<String, String> name : names.entrySet()) {
        maxLength = Math.max(maxLength, name.getValue().length());
    }/*w  ww .  jav  a2  s  .  com*/

    for (Map.Entry<String, String> name : names.entrySet()) {
        String newName = name.getValue();

        while (newName.length() < maxLength) {
            newName += ' ';
        }

        name.setValue(newName);
    }

    final ListIterator<String> itLines = lines.listIterator();
    if (itLines.hasNext())
        itLines.next();

    // TODO Review parsing
    while (itLines.hasNext()) {
        itLines.next(); // White line

        String line = null;
        // Sequences
        while (itLines.hasNext()) {
            line = itLines.next();
            if (line.isEmpty())
                break;
            final String[] lineSplit = line.split("\\s+");
            final String name = lineSplit.length == 0 ? "" : lineSplit[0];

            if (names.get(name) == null)
                break;

            itLines.set(names.get(name) + "   " + lineSplit[1]);
        }

        // Marks line
        if (line != null && !line.isEmpty() && line.startsWith(" ")) {
            String newLine = line;

            if (maxLength < 13)
                newLine = newLine.substring(13 - maxLength);
            else
                for (int i = 16; i < maxLength + 3; i++) {
                    newLine = ' ' + newLine;
                }

            itLines.set(newLine);
        }
    }

    FileUtils.writeLines(outputFile, lines);
}

From source file:org.ambraproject.service.article.BrowseServiceImpl.java

/**
 * Given a list of Article Groups with correctly ordered articles create a CSV string of article URIs. The URIs will
 * be in the order that they show up on the TOC.
 *
 * @param articleGroups the list of TOCArticleGroup to process.
 * @return a string of a comma separated list of article URIs
 *//*from w w w  .  j a  v  a 2  s .co  m*/
public String articleGrpListToCSV(List<TOCArticleGroup> articleGroups) {
    StringBuilder articleList = new StringBuilder();
    Iterator i = articleGroups.listIterator();

    // Group Loop
    while (i.hasNext()) {
        TOCArticleGroup ag = (TOCArticleGroup) i.next();
        Iterator y = ag.articles.listIterator();

        // Article Loop
        while (y.hasNext()) {
            TOCArticle ai = (TOCArticle) y.next();
            articleList.append(ai.getDoi());

            if (y.hasNext())
                articleList.append(',');
        }
        if (i.hasNext())
            articleList.append(',');
    }
    return articleList.toString();
}