Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

In this page you can find the example usage for java.util ListIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java

/**
 * Removes all fingers after {@code id} (does not remove {@code id} itself).
 * @param id id of which all fingers after it will be removed
 * @return number of fingers that were cleared
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if {@code id} has a different limit bit size than base pointer's id
 *///from   w  w  w  .  ja  v  a 2  s. co  m
public int clearAfter(Id id) {
    Validate.notNull(id);
    Validate.isTrue(IdUtils.getBitLength(id) == bitCount);

    Id baseId = basePtr.getId();

    ListIterator<InternalEntry> lit = table.listIterator();
    while (lit.hasNext()) {
        InternalEntry ie = lit.next();
        Pointer testPtr = ie.pointer;
        Id testId = testPtr.getId();

        if (Id.comparePosition(baseId, id, testId) < 0) {
            int position = lit.nextIndex() - 1;
            clearAfter(position);
            return bitCount - position;
        }
    }

    return 0;
}

From source file:lcn.module.batch.web.guide.support.StagingItemWriter.java

/**
 * BATCH_STAGING? write/*  w ww  .j a  v a2s  . c o m*/
 */
public void write(final List<? extends T> items) {

    final ListIterator<? extends T> itemIterator = items.listIterator();
    getJdbcTemplate().batchUpdate("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
            new BatchPreparedStatementSetter() {

                public int getBatchSize() {
                    return items.size();
                }

                public void setValues(PreparedStatement ps, int i) throws SQLException {

                    long id = incrementer.nextLongValue();
                    long jobId = stepExecution.getJobExecution().getJobId();

                    Assert.state(itemIterator.nextIndex() == i,
                            "Item ordering must be preserved in batch sql update");

                    byte[] blob = SerializationUtils.serialize((Serializable) itemIterator.next());

                    ps.setLong(1, id);
                    ps.setLong(2, jobId);
                    ps.setBytes(3, blob);
                    ps.setString(4, NEW);
                }
            });

}

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 ww w .j a  v a  2s  .  co m*/
    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:com.polyvi.xface.extension.contact.XContactsExt.java

/**
 * JSONObjectchildren???Hash//from   w w w  . j  av  a  2s  . c om
 *
 * @param jsonObj
 *            ??json
 * @param contactData
 *            ??hash
 * @param logicParentField
 *            ??
 */
private void transferMultipleValueFields(JSONObject jsonObj, HashMap<String, Object> contactData,
        String logicParentField) {
    try {
        JSONArray childrenJson = jsonObj.optJSONArray(logicParentField);
        if (null == childrenJson) {
            return;
        }

        int len = childrenJson.length();
        for (int i = 0; i < len; i++) {
            JSONObject childJson = (JSONObject) childrenJson.get(i);

            ListIterator<String> logicSubFieldItor = mContactAccessor
                    .getLogicContactSubFieldsOf(logicParentField).listIterator();

            while (logicSubFieldItor.hasNext()) {
                String logicSubField = logicSubFieldItor.next();
                String key = mContactAccessor.generateSubFieldKey(logicParentField, i, logicSubField);
                putValueToMap(contactData, key, getJSONString(childJson, logicSubField));
            }

            // photosvalue
            if (XContactAccessor.LOGIC_FIELD_PHOTOS.equals(logicParentField)) {
                byte[] bytes = getPhotoBytes(getJSONString(jsonObj, XContactAccessor.LOGIC_FIELD_COMMON_VALUE));
                String key = mContactAccessor.generateSubFieldKey(logicParentField, i,
                        XContactAccessor.LOGIC_FIELD_COMMON_VALUE);
                contactData.put(key, bytes);
            }
        }

        String quantity = mContactAccessor.generateQuantityFieldOf(logicParentField);
        contactData.put(quantity, len);
    } catch (JSONException e) {
        e.printStackTrace();
        XLog.d(CLASS_NAME, "Could not read field [" + logicParentField + "] from json object");
    }
}

From source file:com.netflix.config.ConcurrentCompositeConfiguration.java

/**
 * Get a List of objects associated with the given configuration key.
 * If the key doesn't map to an existing object, the default value
 * is returned./*ww  w .  j a  va 2 s  .c o  m*/
 *
 * @param key The configuration key.
 * @param defaultValue The default value.
 * @return The associated List of value.
 * 
 */
@Override
public List getList(String key, List defaultValue) {
    List<Object> list = new ArrayList<Object>();

    // add all elements from the first configuration containing the requested key
    Iterator<AbstractConfiguration> it = configList.iterator();
    if (overrideProperties.containsKey(key)) {
        appendListProperty(list, overrideProperties, key);
    }
    while (it.hasNext() && list.isEmpty()) {
        Configuration config = it.next();
        if ((config != containerConfiguration || containerConfigurationChanged) && config.containsKey(key)) {
            appendListProperty(list, config, key);
        }
    }

    // add all elements from the in memory configuration
    if (list.isEmpty()) {
        appendListProperty(list, containerConfiguration, key);
    }

    if (list.isEmpty()) {
        return defaultValue;
    }

    ListIterator<Object> lit = list.listIterator();
    while (lit.hasNext()) {
        lit.set(interpolate(lit.next()));
    }

    return list;
}

From source file:junk.gui.HazardDataSetCalcCondorApp.java

/**
 * Returns the metadata associated with this calculation
 *
 * @returns the String containing the values selected for different parameters
 *///from   ww w . j  av a 2  s .  c  o  m
public String getParametersInfo() {
    String lf = SystemUtils.LINE_SEPARATOR;
    String metadata = "IMR Param List:" + lf + "---------------" + lf
            + this.imrGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf
            + "Region Param List: " + lf + "----------------" + lf
            + sitesGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf
            + "IMT Param List: " + lf + "---------------" + lf
            + imtGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf
            + "Forecast Param List: " + lf + "--------------------" + lf
            + erfGuiBean.getERFParameterList().getParameterListMetadataString() + lf + lf
            + "TimeSpan Param List: " + lf + "--------------------" + lf
            + erfGuiBean.getSelectedERFTimespanGuiBean().getParameterListMetadataString() + lf + lf
            + "Miscellaneous Metadata:" + lf + "--------------------" + lf + "Maximum Site Source Distance = "
            + maxDistance + lf + lf + "X Values = ";

    //getting the X values used to generate the metadata.
    ListIterator it = function.getXValuesIterator();
    String xVals = "";
    while (it.hasNext())
        xVals += (Double) it.next() + " , ";
    xVals = xVals.substring(0, xVals.lastIndexOf(","));

    //adding the X Vals used to the Metadata.
    metadata += xVals;
    return metadata;
}

From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override//w w  w  . j a v a2s.com
public void onCreate(Bundle savedInstanceState) {
    setTitle("?");
    AndroidUtil.removeStrict();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);
    faviconImageView = (ImageView) findViewById(R.id.favicon);

    urlEditText = (EditText) findViewById(R.id.url);
    progressBar = (ProgressBar) findViewById(R.id.progressbar);
    stopButton = ((Button) findViewById(R.id.stopButton));
    //favicon, deprecated since Android 4.3 but it's still necesary O_O ?
    WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

    freeQuotaSwitch = (Switch) findViewById(R.id.freeQuotaSwitch);

    leftQuotaText = (TextView) findViewById(R.id.leftQuota);

    SharedPreferences settings = getSharedPreferences("setting", 0);

    userid = settings.getString("userid", "123");
    tenantid = Integer.parseInt(settings.getString("tenantid", "3"));

    // check balance
    long balance = updateLeftQuota();

    freeQuotaSwitch.setChecked(balance > 0);
    tmMgr = new TMManager();

    // javascript and zoom
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        webview.getSettings().setPluginState(PluginState.ON);
    } else {
        //IMPORTANT!! this method is no longer available since Android 4.3
        //so the code doesn't compile anymore
        //webview.getSettings().setPluginsEnabled(true);
    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(0);
            FrameLayout progressBarLayout = (FrameLayout) findViewById(R.id.progressBarLayout);
            progressBarLayout.setVisibility(View.VISIBLE);
            WebViewDemoActivity.this.setProgress(progress * 1000);

            TextView progressStatus = (TextView) findViewById(R.id.progressStatus);
            progressStatus.setText(progress + " %");
            progressBar.incrementProgressBy(progress);

            if (progress == 100) {
                progressBarLayout.setVisibility(View.GONE);
            }
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            WebViewDemoActivity.this.setTitle(
                    getString(R.string.app_name) + " - " + WebViewDemoActivity.this.webview.getTitle());
            for (Link link : historyStack) {
                if (link.getUrl().equals(WebViewDemoActivity.this.webview.getUrl())) {
                    link.setTitle(title);
                }
            }
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {
            faviconImageView.setImageBitmap(icon);
            view.getUrl();
            boolean b = false;
            ListIterator<Link> listIterator = historyStack.listIterator();
            while (!b && listIterator.hasNext()) {
                Link link = listIterator.next();
                if (link.getUrl().equals(view.getUrl())) {
                    link.setFavicon(icon);
                    b = true;
                }
            }
        }

    });

    //http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

}

From source file:au.edu.ausstage.networks.LookupManager.java

/**
 * A method to take a group of collaborators and output XML encoded text
 *
 * @param collaborators the list of collaborators
 * @return              the HTML encoded string
 *///from   ww w. j  a va  2s  . c  o  m
private String createXMLOutput(java.util.LinkedList<Collaborator> collaborators) {

    // assume that all sorting and ordering has already been carried out
    // loop through the list of collaborators build the XML
    ListIterator iterator = collaborators.listIterator(0);

    // declare helper variables
    StringBuilder xmlMarkup = new StringBuilder("<?xml version=\"1.0\"?><collaborators>");
    Collaborator collaborator = null;
    int count = 0;

    while (iterator.hasNext()) {

        // get the collaborator
        collaborator = (Collaborator) iterator.next();

        xmlMarkup.append("<collaborator id=\"" + collaborator.getId() + "\">");

        xmlMarkup.append("<url>" + StringEscapeUtils.escapeXml(collaborator.getUrl()) + "</url>");
        xmlMarkup.append("<givenName>" + collaborator.getGivenName() + "</givenName>");
        xmlMarkup.append("<familyName>" + collaborator.getFamilyName() + "</familyName>");
        xmlMarkup.append("<name>" + collaborator.getName() + "</name>");
        xmlMarkup.append("<function>" + collaborator.getFunction() + "</function>");
        xmlMarkup.append("<firstDate>" + collaborator.getFirstDate() + "</firstDate>");
        xmlMarkup.append("<lastDate>" + collaborator.getLastDate() + "</lastDate>");
        xmlMarkup.append("<collaborations>" + collaborator.getCollaborations() + "</collaborations>");
        xmlMarkup.append("</collaborator>");

        // increment the count
        count++;
    }

    // add a comment
    xmlMarkup.append("<!-- Contributors listed: " + count + " -->");

    // end the table
    xmlMarkup.append("</collaborators>");

    return xmlMarkup.toString();

}

From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java

/*********************************************
 * /*from ww w.ja  v a2 s.co m*/
 * insertElementInFullList
 * 
 *********************************************/
public void insertElementInFullList(ArtistEvent artistEvent) {
    /*
     * First Element
     */
    if (artistEventList.isEmpty())
        artistEventList.add(artistEvent);
    else {
        Log.i("STARTCMP", "starting");
        ArtistEvent artistEventItem;
        ListIterator<ArtistEvent> artistEventListIterator = artistEventList.listIterator();
        while (artistEventListIterator.hasNext()) {
            artistEventItem = artistEventListIterator.next();
            Log.i("CMPTIME", artistEvent.dateInMillis + "<" + artistEventItem.dateInMillis);
            if (artistEvent.dateInMillis < artistEventItem.dateInMillis) {
                artistEventList.add(artistEventListIterator.nextIndex() - 1, artistEvent);
                return;
            }
        }
        artistEventList.add(artistEventList.size(), artistEvent);
    }
}

From source file:TimestreamsTests.java

/**
 * Returns a HMAC for given parameters/*from w w  w .  ja  v  a2 s .co 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");
}