Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

In this page you can find the example usage for java.util Iterator remove.

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:com.linkedin.pinot.tools.StarTreeIndexViewer.java

private int build(StarTreeIndexNodeInterf indexNode, StarTreeJsonNode json) {
    Iterator<? extends StarTreeIndexNodeInterf> childrenIterator = indexNode.getChildrenIterator();
    if (!childrenIterator.hasNext()) {
        return 0;
    }//from   www .j a  v  a 2 s .  com
    int childDimensionId = indexNode.getChildDimensionName();
    String childDimensionName = dimensionNameToIndexMap.inverse().get(childDimensionId);
    Dictionary dictionary = dictionaries.get(childDimensionName);
    int totalChildNodes = indexNode.getNumChildren();

    Comparator<Pair<String, Integer>> comparator = new Comparator<Pair<String, Integer>>() {

        @Override
        public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
            return -1 * Integer.compare(o1.getRight(), o2.getRight());
        }
    };
    MinMaxPriorityQueue<Pair<String, Integer>> queue = MinMaxPriorityQueue.orderedBy(comparator)
            .maximumSize(MAX_CHILDREN).create();
    StarTreeJsonNode allNode = null;

    while (childrenIterator.hasNext()) {
        StarTreeIndexNodeInterf childIndexNode = childrenIterator.next();
        int childDimensionValueId = childIndexNode.getDimensionValue();
        String childDimensionValue = "ALL";
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            childDimensionValue = dictionary.get(childDimensionValueId).toString();
        }
        StarTreeJsonNode childJson = new StarTreeJsonNode(childDimensionValue);
        totalChildNodes += build(childIndexNode, childJson);
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            json.addChild(childJson);
            queue.add(ImmutablePair.of(childDimensionValue, totalChildNodes));
        } else {
            allNode = childJson;
        }
    }
    //put ALL node at the end
    if (allNode != null) {
        json.addChild(allNode);
    }
    if (totalChildNodes > MAX_CHILDREN) {
        Iterator<Pair<String, Integer>> qIterator = queue.iterator();
        Set<String> topKDimensions = new HashSet<>();
        topKDimensions.add("ALL");
        while (qIterator.hasNext()) {
            topKDimensions.add(qIterator.next().getKey());
        }
        Iterator<StarTreeJsonNode> iterator = json.getChildren().iterator();
        while (iterator.hasNext()) {
            StarTreeJsonNode next = iterator.next();
            if (!topKDimensions.contains(next.getName())) {
                iterator.remove();
            }
        }
    }
    return totalChildNodes;
}

From source file:pe.gob.mef.gescon.web.ui.ParametroMB.java

public void cleanAttributes() {
    this.setId(BigDecimal.ZERO);
    this.setDescripcion(StringUtils.EMPTY);
    this.setNombre(StringUtils.EMPTY);
    this.setValor(StringUtils.EMPTY);
    this.setActivo(BigDecimal.ONE);
    this.setSelectedParametro(null);
    Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
    if (iter.hasNext() == true) {
        iter.remove();
        FacesContext.getCurrentInstance().renderResponse();
    }/*from ww  w .  ja v a 2s . c o m*/
}

From source file:com.aw.swing.mvp.binding.component.support.table.JTableModel.java

public void removeAllRows() {
    Iterator iterator = values.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        iterator.remove();
    }/*  w ww .jav  a 2s .c  o  m*/
    fireTableDataChanged();
}

From source file:com.datatorrent.contrib.frauddetect.CreditCardAmountSamplerOperator.java

@Override
public void endWindow() {

    for (CreditCardAlertData data : alerts) {
        try {/*from  w  w  w .j a  v  a2s .  c  o  m*/
            ccAlertOutputPort.emit(JsonUtils.toJson(data));
        } catch (IOException e) {
            logger.warn("Exception while converting object to JSON", e);
        }
    }

    //for (CreditCardAlertData data: userAlerts) {
    /*for (CreditCardAlertData data: alerts) {
    ccAlertNotificationPort.emit(getOutputData(data));
    }*/

    long ctime = System.currentTimeMillis();
    Iterator<Map.Entry<String, CreditCardInfo>> iterator = ccTxnMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, CreditCardInfo> entry = iterator.next();
        long time = entry.getValue().time;
        if ((ctime - time) > 60000) {
            iterator.remove();
        }
    }

    //ccTxnMap.clear();
    alerts.clear();

    //ccQueryTxnMap.clear();
    //userAlerts.clear();
}

From source file:com.amazon.alexa.avs.NotificationManager.java

private void cleanUpIndicatorFutures() {
    synchronized (indicatorFutures) {
        Iterator<Future<?>> it = indicatorFutures.iterator();
        while (it.hasNext()) {
            Future<?> f = it.next();
            if (f.isDone() || f.isCancelled()) {
                it.remove();
            }/* w w  w. j  a v  a  2 s.c  o  m*/
        }
    }
}

From source file:org.motechproject.server.omod.sdsched.ScheduleMaintSynchronization.java

/**
 * Called before the commit, it is responsible for patch-up the schedules
 * for patients affected during the transaction.
 *//*from   w ww.  j a v a 2s.  c o  m*/
public void beforeCommit(boolean readOnly) {

    if (!readOnly) {

        log.debug("running schedule sync");

        AffectedPatients patients = schedService.getAffectedPatients(false);

        if (patients != null) {

            if (log.isDebugEnabled())
                log.debug(patients.getAffectedIds().size() + " affected patients, updating schedules");

            // Update each patient's schedule in turn (stubbed for now)
            Iterator<Integer> patientIter = patients.getAffectedIds().iterator();
            while (patientIter.hasNext()) {
                Integer patientId = patientIter.next();
                if (log.isDebugEnabled())
                    log.debug("updating schedule for patientId: " + patientId);

                schedService.updateSchedule(patientId);

                patientIter.remove(); // Ensure we don't re-process
            }

        } else
            log.debug("null affected patients, no schedules updated");
    } else
        log.debug("skipping schedule sync: read-only transaction");
}

From source file:com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel.java

protected void removeValuePerformed(AjaxRequestTarget target, ListItem<T> item) {
    List<T> objects = getModelObject();
    Iterator<T> iterator = objects.iterator();
    while (iterator.hasNext()) {
        T object = iterator.next();/*  w  w w.j  a v  a2s .co m*/

        if (object.equals(item.getModelObject())) {
            iterator.remove();
            break;
        }
    }

    target.add(this);
}

From source file:com.thomasjensen.sercoll.SerializableUnmodifiableHashMapUTest.java

@Test
public void testUnsupportedOps() {
    final SerializableMap<String, String> mapUnderTest = buildNewTestMap();

    try {/*from  w  w  w  .  j a v  a2  s  .c  om*/
        mapUnderTest.clear();
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.put("D", "value");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.putAll(new HashMap<String, String>());
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.remove("A");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().remove("B");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().add("E");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().clear();
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().removeAll(Collections.singleton("A"));
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().addAll(Arrays.asList("E", "F"));
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.keySet().retainAll(Collections.singleton("A"));
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.values().remove("B");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    Map.Entry<String, String> entry1 = mapUnderTest.entrySet().iterator().next();
    Assert.assertNotNull(entry1);
    try {
        mapUnderTest.entrySet().remove(entry1);
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        entry1.setValue("poison");
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        mapUnderTest.entrySet().clear();
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        Iterator<Entry<String, String>> iter = mapUnderTest.entrySet().iterator();
        Assert.assertNotNull(iter.next());
        iter.remove();
        Assert.fail("expected exception was not thrown");
    } catch (UnsupportedOperationException e) {
        // expected
    }
}

From source file:com.yahoo.sql4d.query.select.SelectQueryMeta.java

/**
 * This method must be called prior to calling {@link SelectQueryMeta#getJsonMap() }.
 * Essentially splits columns into Dimensions and Metrics.
 * @param <T>//from   w  w w  .  ja va 2  s.  c o  m
 * @param anyContext
 */
@Override
public <T> void postProcess(T anyContext) {
    Tuple2<List<String>, List<String>> dimsAndMetrics = (Tuple2<List<String>, List<String>>) anyContext;
    List<String> dims = dimsAndMetrics._1();
    List<String> metrics = dimsAndMetrics._2();
    Iterator<Map.Entry<String, String>> colIter = fetchDimensions.entrySet().iterator();
    while (colIter.hasNext()) {
        Map.Entry<String, String> entry = colIter.next();
        if (dims.contains(entry.getKey())) {
            //No action.
        } else if (metrics.contains(entry.getKey())) {
            fetchMetrics.add(entry.getKey());
            colIter.remove();
        } else {//TODO: Handle error

        }
    }
}

From source file:edu.byu.softwareDist.manager.impl.LicenseCountChecker.java

@Override
public void run() {
    while (true) {
        try {/*from w w  w  .  j  a  v  a 2 s  .  c  o m*/
            final Iterator<Product> iter = TO_CHECK.iterator();
            while (iter.hasNext()) {
                final Product p = iter.next();
                try {
                    actuallyCheckingLicenseLeft(p);
                } catch (final Throwable t) {
                    LOG.error("Error checking for licenses for product " + p, t);
                }
                iter.remove();
            }
        } catch (final Throwable t) {
            LOG.error("Error checking for no licenses left.", t);
        }
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
    }
}