Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

From source file:com.adobe.acs.commons.httpcache.config.impl.GroupHttpCacheConfigExtension.java

@Activate
@Modified/*from  w w w  .j  a  v  a  2  s. c om*/
protected void activate(Map<String, Object> configs) {

    // User groups after removing empty strings.
    userGroups = new ArrayList(
            Arrays.asList(PropertiesUtil.toStringArray(configs.get(PROP_USER_GROUPS), new String[] {})));
    ListIterator<String> listIterator = userGroups.listIterator();
    while (listIterator.hasNext()) {
        String value = listIterator.next();
        if (StringUtils.isBlank(value)) {
            listIterator.remove();
        }
    }

    log.info("GroupHttpCacheConfigExtension activated/modified.");
}

From source file:edu.harvard.i2b2.pm.util.PMUtil.java

public void convertToUppercaseStrings(List<String> list) {
    ListIterator<String> iterator = list.listIterator();

    while (iterator.hasNext()) {
        String color = iterator.next(); // get item                 
        iterator.set(color.toUpperCase()); // convert to upper case
    } // end while
}

From source file:net.relet.freimap.LinkInfo.java

public void setLinkProfile(LinkedList<LinkData> lp) {

    XYSeries data = new XYSeries("etx");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);/* ww  w  .  j  a va2 s  .co m*/
    linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx",
            datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkChart);

    long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan
            maxCount = 0; //max idem
    long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkData> li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();
        count++;
        if (ld.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = ld.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();

        sum += ld.quality;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (ld.time - lastClock > aggregate) {
            for (long i = lastClock; i < ld.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = ld.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:org.wikimedia.analytics.kraken.pageview.PageviewCanonical.java

/**
 * Enter one or more keys to search for, this list of keys is
 * interpreted as key1 or key2; this function is not intended
 * to retrieve the values of multiple keys. In that case,
 * call this function multiple times.//from  w  w  w  .j  a v a  2 s .c  om
 * @param keys
 * @return
 */
private String searchQueryAction(final String[] keys) {
    try {
        URL pURL = fixApacheHttpComponentBug(url);

        List<NameValuePair> qparams = URLEncodedUtils.parse(pURL.toURI(), "utf-8");
        ListIterator<NameValuePair> it = qparams.listIterator();
        while (it.hasNext()) {
            NameValuePair nvp = it.next();
            for (String key : keys) {
                if (nvp.getName().equals(key)) {
                    return nvp.getValue();
                }
            }
        }
    } catch (URISyntaxException e) {
        return "key.not.found";
    } catch (MalformedURLException e) {
        return "malformed.url";
    }
    return "key.not.found";
}

From source file:com.att.aro.ui.view.diagnostictab.plot.AlarmPlot.java

private List<ScheduledAlarmInfo> getHasFiredAlarms(Map<String, List<ScheduledAlarmInfo>> pendingAlarms) {
    List<ScheduledAlarmInfo> result = new ArrayList<ScheduledAlarmInfo>();
    for (Map.Entry<String, List<ScheduledAlarmInfo>> entry : pendingAlarms.entrySet()) {
        List<ScheduledAlarmInfo> alarms = entry.getValue();
        @SuppressWarnings("rawtypes")
        ListIterator itrAlarms = alarms.listIterator();
        while (itrAlarms.hasNext()) {
            ScheduledAlarmInfo alarm = (ScheduledAlarmInfo) itrAlarms.next();
            if (alarm.getHasFired() > 0) {
                result.add(alarm);// ww  w .  j  a  va2  s.co  m
            }
        }
    }
    return result;
}

From source file:com.activecq.experiments.pageimage.impl.PageImageServletImpl.java

/**
 * Retrieves the Width and Height from the Sling Selectors on the requested URI
 *
 * @param key/* w w w.  j  a  v  a 2 s. c  om*/
 * @param request
 * @return
 */
private String getDimension(final String key, final SlingHttpServletRequest request) {
    final RequestPathInfo rpi = request.getRequestPathInfo();
    final ListIterator<String> iterator = Arrays.asList(rpi.getSelectors()).listIterator();

    while (iterator.hasNext()) {
        final String selector = iterator.next();

        if (key.equals(selector)) {
            return iterator.next();
        }
    }

    return "0";
}

From source file:com.offbynull.voip.kademlia.model.NodeMostRecentSet.java

public ActivityChangeSet touch(Instant time, Node node, boolean allowLinkMismatch) {
    Validate.notNull(time);//from  w w w .  j  a v  a  2s.c  om
    Validate.notNull(node);

    Id nodeId = node.getId();

    InternalValidate.matchesLength(baseId.getBitLength(), nodeId);
    //        Validate.isTrue(!nodeId.equals(baseId)); // Don't reject adding self

    // TODO: You can make this way more efficient if you used something like MultiTreeSet (guava) and sorted based on entry time

    // Remove existing entry
    Activity oldEntry = null;
    ListIterator<Activity> it = entries.listIterator();
    while (it.hasNext()) {
        Activity entry = it.next();

        Id entryId = entry.getNode().getId();

        if (entryId.equals(nodeId)) {
            if (!allowLinkMismatch) {
                InternalValidate.matchesLink(entry.getNode(), node);
            }

            // remove
            it.remove();
            oldEntry = entry;
            break;
        }
    }

    // Add entry
    Activity newEntry = new Activity(node, time);
    it = entries.listIterator(entries.size());
    boolean added = false;
    while (it.hasPrevious()) {
        Activity entry = it.previous();

        if (entry.getTime().isBefore(time)) {
            it.next(); // move forward 1 space, we want to add to element just after entry
            it.add(newEntry);
            added = true;
            break;
        }
    }

    if (!added) { // special case where newEntry needs to be added at the end of entries, not handled by loop above
        entries.addFirst(newEntry);
    }

    // Set has become too large, remove the item with the earliest time
    Activity discardedEntry = null;
    if (entries.size() > maxSize) {
        // if the node removed with the earliest time is the one we just added, then report that node couldn't be added
        discardedEntry = entries.removeFirst();
        if (discardedEntry.equals(newEntry)) {
            return ActivityChangeSet.NO_CHANGE;
        }
    }

    // Add successful
    if (oldEntry != null) {
        Validate.validState(discardedEntry == null); // sanity check, must not have discarded anything

        // updated existing node
        return ActivityChangeSet.updated(newEntry);
    } else {
        // if block above ensures oldEntry is null if we're in this else block, so sanity check below isn't nessecary
        // Validate.validState(oldEntry == null); // sanity check, node being touched must not have already existed

        // added new node
        Collection<Activity> addedEntries = singletonList(newEntry);
        Collection<Activity> removedEntries = discardedEntry == null ? emptyList()
                : singletonList(discardedEntry);
        Collection<Activity> updatedEntries = emptyList();
        return new ActivityChangeSet(addedEntries, removedEntries, updatedEntries);
    }
}

From source file:com.collective.celos.ci.testing.fixtures.compare.FixTableComparer.java

private Map<String, FixObjectCompareResult> compareRespectOrder(FixTable expected, FixTable actual) {
    Map<String, FixObjectCompareResult> fails = Maps.newLinkedHashMap();
    ListIterator<FixTable.FixRow> expIter = expected.getRows().listIterator();
    ListIterator<FixTable.FixRow> actIter = actual.getRows().listIterator();
    while (expIter.hasNext()) {
        FixTable.FixRow expRow = expIter.next();
        FixTable.FixRow actRow = actIter.next();

        FixObjectCompareResult result = compareFixRows(expected.getColumnNames(), expRow, actRow);
        if (result.getStatus() == FixObjectCompareResult.Status.FAIL) {
            fails.put("Row #" + expIter.previousIndex(), result);
        }/*from  w  ww. j  av  a  2s .c o  m*/
    }
    return fails;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.PropertyGroupDaoJena.java

public int removeUnpopulatedGroups(List<PropertyGroup> groups) {
    if (groups == null || groups.size() == 0)
        return 0;
    int removedGroupsCount = 0;
    ListIterator<PropertyGroup> it = groups.listIterator();
    while (it.hasNext()) {
        PropertyGroup group = it.next();
        List properties = group.getPropertyList();
        if (properties == null || properties.size() < 1) {
            removedGroupsCount++;/*from  www  .j  a  v  a 2 s  .c o m*/
            it.remove();
        }
    }
    return removedGroupsCount;
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.MoveFreeVariableOperatorOutOfSubplanRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    /*/*from w ww.  j a  v a 2s  . c o m*/
     * This rule looks for an assign within a subplan that uses only 
     * variables from outside of the subplan
     * 
     * It moves this assign outside of the subplan
     * 
     */
    AbstractLogicalOperator op0 = (AbstractLogicalOperator) opRef.getValue();
    if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
        return false;
    }
    SubplanOperator subplan = (SubplanOperator) op0;

    Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
    if (((AbstractLogicalOperator) leftRef.getValue())
            .getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
        return false;
    }

    ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
    ILogicalPlan p = null;
    while (plansIter.hasNext()) {
        p = plansIter.next();
    }
    if (p == null) {
        return false;
    }
    if (p.getRoots().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);

    //The root operator will not be movable. Start with the second op
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
    if (op1.getInputs().size() != 1) {
        return false;
    }
    Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);

    //Get all variables that come from outside of the loop
    Set<LogicalVariable> free = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free);

    while (op2Ref != null) {
        //Get the operator that we want to look at
        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();

        //Make sure we are looking at subplan with a scan/join
        if (op2.getInputs().size() != 1 || !descOrSelfIsScanOrJoin(op2)) {
            return false;
        }
        boolean notApplicable = false;

        //Get its used variables
        Set<LogicalVariable> used = new HashSet<LogicalVariable>();
        VariableUtilities.getUsedVariables(op2, used);

        //not movable if the operator is not an assign
        //Might be helpful in the future for other operations in the future
        if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
            notApplicable = true;
        }

        //Make sure that all of its used variables come from outside
        for (LogicalVariable var : used) {
            if (!free.contains(var)) {
                notApplicable = true;
            }
        }

        if (notApplicable) {
            op2Ref = op2.getInputs().get(0);
        } else {
            //Make the input of op2 be the input of op1
            op2Ref.setValue(op2.getInputs().get(0).getValue());

            //Make the outside of the subplan the input of op2
            Mutable<ILogicalOperator> outsideRef = op2.getInputs().get(0);
            outsideRef.setValue(op0.getInputs().get(0).getValue());

            //Make op2 the input of the subplan
            Mutable<ILogicalOperator> op2OutsideRef = op0.getInputs().get(0);
            op2OutsideRef.setValue(op2);

            return true;
        }

    }
    return false;
}