Example usage for java.util ListIterator remove

List of usage examples for java.util ListIterator remove

Introduction

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

Prototype

void remove();

Source Link

Document

Removes from the list the last element that was returned by #next or #previous (optional operation).

Usage

From source file:org.zaproxy.zap.extension.websocket.db.TableWebSocket.java

/**
 * Filter out messages according to payloadFilter
 *
 * @param payloadFilter filter payload/*ww  w. j a  va2 s  .  com*/
 * @param webSocketMessageDTOs list of messages
 * @return only valid messages according to filter payload
 */
private List<WebSocketMessageDTO> checkPayloadFilter(WebSocketMessagesPayloadFilter payloadFilter,
        List<WebSocketMessageDTO> webSocketMessageDTOs) {
    if (payloadFilter == null || payloadFilter.getPayloadPattern() == null) {
        return webSocketMessageDTOs;
    }
    ListIterator<WebSocketMessageDTO> iterator = webSocketMessageDTOs.listIterator();
    while (iterator.hasNext()) {
        if (!payloadFilter.isMessageValidWithPattern(iterator.next())) {
            iterator.remove();
        }
    }
    return webSocketMessageDTOs;
}

From source file:at.ofai.music.util.WormFileParseException.java

public void insert(Event newEvent, boolean uniqueTimes) {
    ListIterator<Event> li = l.listIterator();
    while (li.hasNext()) {
        int sgn = newEvent.compareTo(li.next());
        if (sgn < 0) {
            li.previous();/*from   w ww .  j a  v  a  2s  .  c  o m*/
            break;
        } else if (uniqueTimes && (sgn == 0)) {
            li.remove();
            break;
        }
    }
    li.add(newEvent);
}

From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java

private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes)
        throws IOException {

    /*//w w  w  .jav  a 2s.  c  o m
     * Remove NaN entries from the List
     */
    List<Double> listWithoutNaN = new ArrayList<Double>();
    for (Double d : evacuationTimes.values())
        if (!d.isNaN())
            listWithoutNaN.add(d);

    /*
     * If trip with significant to high evacuation times should be cut off
     */
    if (limitMaxEvacuationTime) {
        double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor;
        ListIterator<Double> iter = listWithoutNaN.listIterator();
        while (iter.hasNext()) {
            double value = iter.next();
            if (value > cutOffValue)
                iter.remove();
        }
    }

    double[] array = new double[listWithoutNaN.size()];
    int i = 0;
    for (double d : listWithoutNaN)
        array[i++] = d;

    JFreeChart chart = createHistogramChart(transportMode, array);
    BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT);
    BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT,
            BufferedImage.TYPE_4BYTE_ABGR);

    // clone image and set alpha value
    for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) {
        for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) {
            int rgb = chartImage.getRGB(x, y);
            Color c = new Color(rgb);
            int r = c.getRed();
            int b = c.getBlue();
            int g = c.getGreen();
            int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value
            image.setRGB(x, y, argb);
        }
    }

    byte[] imageBytes = bufferedImageToByteArray(image);
    this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM);

    ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType();
    LinkType icon = kmlObjectFactory.createLinkType();
    icon.setHref(transportMode + OVERALLHISTROGRAM);
    overlay.setIcon(icon);
    overlay.setName("Histogram " + transportMode);
    // place the image top right
    Vec2Type overlayXY = kmlObjectFactory.createVec2Type();
    overlayXY.setX(0.0);
    overlayXY.setY(1.0);
    overlayXY.setXunits(UnitsEnumType.FRACTION);
    overlayXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setOverlayXY(overlayXY);
    Vec2Type screenXY = kmlObjectFactory.createVec2Type();
    screenXY.setX(0.02);
    screenXY.setY(0.98);
    screenXY.setXunits(UnitsEnumType.FRACTION);
    screenXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setScreenXY(screenXY);
    return overlay;
}

From source file:com.t3.model.initiative.InitiativeList.java

/**
 * Updates occurred to the tokens. //from   w ww . j av  a 2 s .c  o  m
 */
public void update() {

    // No zone, no tokens
    if (getZone() == null) {
        clearModel();
        return;
    } // endif

    // Remove deleted tokens
    startUnitOfWork();
    boolean updateNeeded = false;
    ListIterator<TokenInitiative> i = tokens.listIterator();
    while (i.hasNext()) {
        TokenInitiative ti = i.next();
        if (!ti.tokenExists()) {
            int index = tokens.indexOf(ti);
            if (index <= current)
                setCurrent(current - 1);
            i.remove();
            updateNeeded = true;
            getPCS().fireIndexedPropertyChange(TOKENS_PROP, index, ti, null);
        } // endif
    } // endwhile
    if (updateNeeded) {
        finishUnitOfWork();
    } else if (holdUpdate == 1) {
        holdUpdate -= 1; // Do no updates.
        LOGGER.debug("finishUnitOfWork() - no update");
    } // endif
}

From source file:org.jboss.forge.roaster.model.impl.AnnotationImpl.java

@Override
public AnnotationSource<O> setAnnotationValue(String name) {
    if (!isNormal() && DEFAULT_VALUE.equals(name)) {
        return setAnnotationValue();
    }/* w  w w  . ja  v a  2s .c  o m*/
    if (!isNormal()) {
        convertTo(AnnotationType.NORMAL);
    }
    AnnotationSource<O> result = new Nested(this);

    String stub = "@" + getName() + "(" + name + "= 0 ) public class Stub { }";
    JavaClass<?> temp = Roaster.parse(JavaClass.class, stub);

    NormalAnnotation anno = (NormalAnnotation) temp.getAnnotations().get(0).getInternal();
    MemberValuePair pair = (MemberValuePair) anno.values().get(0);

    @SuppressWarnings("unchecked")
    List<MemberValuePair> values = ((NormalAnnotation) annotation).values();
    ListIterator<MemberValuePair> iter = values.listIterator();
    while (iter.hasNext()) {
        if (iter.next().getName().getIdentifier().equals(name)) {
            iter.remove();
            break;
        }
    }
    MemberValuePair mvpCopy = (MemberValuePair) ASTNode.copySubtree(annotation.getAST(), pair);
    mvpCopy.setValue((Expression) result.getInternal());
    iter.add(mvpCopy);

    return result;
}

From source file:org.jboss.forge.roaster.model.impl.AnnotationImpl.java

@Override
@SuppressWarnings("unchecked")
public AnnotationSource<O> setLiteralValue(final String name, final String value) {
    requireNonNull(value);/*from  ww  w. j  a  v a2  s. co  m*/

    if (!isNormal() && !DEFAULT_VALUE.equals(name)) {
        convertTo(AnnotationType.NORMAL);
    } else if (!isSingleValue() && !isNormal() && DEFAULT_VALUE.equals(name)) {
        convertTo(AnnotationType.SINGLE);
    }
    if (isSingleValue() && DEFAULT_VALUE.equals(name)) {
        return setLiteralValue(value);
    }

    NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;

    String stub = "@" + getName() + "(" + name + "=" + value + " ) public class Stub { }";
    JavaClass<?> temp = Roaster.parse(JavaClass.class, stub);

    NormalAnnotation anno = (NormalAnnotation) temp.getAnnotations().get(0).getInternal();
    MemberValuePair pair = (MemberValuePair) anno.values().get(0);

    List<MemberValuePair> values = normalAnnotation.values();
    ListIterator<MemberValuePair> iter = values.listIterator();
    while (iter.hasNext()) {
        if (iter.next().getName().getIdentifier().equals(name)) {
            iter.remove();
            break;
        }
    }
    iter.add((MemberValuePair) ASTNode.copySubtree(annotation.getAST(), pair));

    return this;
}

From source file:mp.teardrop.SongTimeline.java

/**
 * Remove the song with the given id from the timeline.
 *
 * @param id The MediaStore id of the song to remove.
 *///www .j ava  2  s . c o m
public void removeSong(long id) {
    synchronized (this) {
        saveActiveSongs();

        ArrayList<Song> songs = mSongs;
        ListIterator<Song> it = songs.listIterator();
        while (it.hasNext()) {
            int i = it.nextIndex();
            if (Song.getId(it.next()) == id) {
                if (i < mCurrentPos)
                    --mCurrentPos;
                it.remove();
            }
        }

        broadcastChangedSongs();
    }

    changed();
}

From source file:phex.download.DownloadDataWriter.java

private void writeDownloadData() {
    if (!swarmingMgr.isDownloadActive() && !isWriteCycleRequested) {
        return;//  ww  w . j av a 2s  . co m
    }

    long bufferedDataWritten = 0;
    long totalBufferedSize = 0;
    boolean performCompleteWrite = false;
    if (isShutingDown || isWriteCycleRequested
            || lastCompleteWrite + DateUtils.MILLIS_PER_MINUTE < System.currentTimeMillis()) {
        //NLogger.debug(DownloadDataWriter.class, "Time for complete write cycle." );
        isWriteCycleRequested = false;
        performCompleteWrite = true;
    }

    // write limit is 90% of configured max.
    int maxPerDownloadBuffer = DownloadPrefs.MaxWriteBufferPerDownload.get().intValue();
    maxPerDownloadBuffer = (int) (maxPerDownloadBuffer * 0.9);

    List<SWDownloadFile> downloadList = swarmingMgr.getDownloadFileListCopy();
    ListIterator<SWDownloadFile> iterator = downloadList.listIterator();
    while (iterator.hasNext()) {
        SWDownloadFile downloadFile = iterator.next();
        MemoryFile memoryFile = downloadFile.getMemoryFile();
        long bufferedSize = memoryFile.getBufferedDataLength();
        totalBufferedSize += bufferedSize;

        if (performCompleteWrite || memoryFile.isBufferWritingRequested()
                || bufferedSize >= maxPerDownloadBuffer) {
            //NLogger.debug(DownloadDataWriter.class,
            //   "Trigger buffer write for " + downloadFile + 
            //   ", amount: " + bufferedSize );
            memoryFile.writeBuffersToDisk();
            bufferedDataWritten += bufferedSize;
            // remove from buffer since not needed anymore in possible
            // following complete write cycle
            iterator.remove();
        }
    }

    //NLogger.debug(DownloadDataWriter.class,
    //   "Total buffered data was: " + totalBufferedSize );

    // write limit is 90% of configured max.
    int maxTotalBuffer = DownloadPrefs.MaxTotalDownloadWriteBuffer.get().intValue();
    maxTotalBuffer = (int) (maxTotalBuffer * 0.9);

    // if we have not already written everything but have a high total buffer
    // size, we write down the complete remaining download buffers to disk.
    if (!performCompleteWrite && totalBufferedSize >= maxTotalBuffer) {
        performCompleteWrite = true;
        iterator = downloadList.listIterator();
        while (iterator.hasNext()) {
            SWDownloadFile downloadFile = iterator.next();
            MemoryFile memoryFile = downloadFile.getMemoryFile();
            long bufferedSize = memoryFile.getBufferedDataLength();
            //NLogger.debug(DownloadDataWriter.class,
            //                    "Trigger buffer write for " + downloadFile + 
            //                    ", amount: " + bufferedSize );
            memoryFile.writeBuffersToDisk();
            bufferedDataWritten += bufferedSize;
        }
    }
    if (performCompleteWrite) {
        lastCompleteWrite = System.currentTimeMillis();
    }
    if (bufferedDataWritten > 0) {
        swarmingMgr.notifyDownloadListChange();
    }
}

From source file:org.broadleafcommerce.openadmin.server.service.AdminEntityServiceImpl.java

@Override
public PersistenceResponse addSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata,
        Property field, Entity parentEntity, List<SectionCrumb> sectionCrumbs)
        throws ServiceException, ClassNotFoundException {
    // Assemble the properties from the entity form
    List<Property> properties = new ArrayList<Property>();
    for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
        Property p = new Property();
        p.setName(entry.getKey());/* www.j  a  v  a2  s  . c om*/
        p.setValue(entry.getValue().getValue());
        properties.add(p);
    }

    FieldMetadata md = field.getMetadata();

    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs)
            .withEntity(new Entity());

    if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });

        // If we're looking up an entity instead of trying to create one on the fly, let's make sure 
        // that we're not changing the target entity at all and only creating the association to the id
        if (fmd.getAddMethodType().equals(AddMethodType.LOOKUP)
                || fmd.getAddMethodType().equals(AddMethodType.LOOKUP_FOR_UPDATE)) {
            List<String> fieldsToRemove = new ArrayList<String>();

            String idProp = getIdProperty(mainMetadata);
            for (String key : entityForm.getFields().keySet()) {
                if (!idProp.equals(key)) {
                    fieldsToRemove.add(key);
                }
            }

            for (String key : fieldsToRemove) {
                ListIterator<Property> li = properties.listIterator();
                while (li.hasNext()) {
                    if (li.next().getName().equals(key)) {
                        li.remove();
                    }
                }
            }

            ppr.setValidateUnsubmittedProperties(false);
        }

        if (fmd.getAddMethodType().equals(AddMethodType.LOOKUP_FOR_UPDATE)) {
            ppr.setUpdateLookupType(true);
        }

        Property fp = new Property();
        fp.setName(ppr.getForeignKey().getManyToField());
        fp.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(fp);
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        ppr.getEntity().setType(new String[] { ppr.getAdornedList().getAdornedTargetEntityClassname() });

        String[] maintainedFields = ((AdornedTargetCollectionMetadata) md).getMaintainedAdornedTargetFields();
        if (maintainedFields == null || maintainedFields.length == 0) {
            ppr.setValidateUnsubmittedProperties(false);
        }
    } else if (md instanceof MapMetadata) {
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });

        Property p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
    } else {
        throw new IllegalArgumentException(
                String.format("The specified field [%s] for class [%s] was" + " not a collection field.",
                        field.getName(), mainMetadata.getCeilingType()));
    }

    ppr.setCeilingEntityClassname(ppr.getEntity().getType()[0]);
    String sectionField = field.getName();
    if (sectionField.contains(".")) {
        sectionField = sectionField.substring(0, sectionField.lastIndexOf("."));
    }
    ppr.setSectionEntityField(sectionField);

    Property parentNameProp = parentEntity.getPMap().get(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
    if (parentNameProp != null) {
        ppr.setRequestingEntityName(parentNameProp.getValue());
    }

    Property[] propArr = new Property[properties.size()];
    properties.toArray(propArr);
    ppr.getEntity().setProperties(propArr);

    return add(ppr);
}

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

private boolean factorRedundantRhsVars(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> veList,
        Mutable<ILogicalOperator> opRef, Map<LogicalVariable, LogicalVariable> varRhsToLhs,
        IOptimizationContext context) throws AlgebricksException {
    varRhsToLhs.clear();//from w w w. j  av a2  s.co m
    ListIterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> iter = veList.listIterator();
    boolean changed = false;
    while (iter.hasNext()) {
        Pair<LogicalVariable, Mutable<ILogicalExpression>> p = iter.next();
        if (p.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
            continue;
        }
        LogicalVariable v = GroupByOperator.getDecorVariable(p);
        LogicalVariable lhs = varRhsToLhs.get(v);
        if (lhs != null) {
            if (p.first != null) {
                AssignOperator assign = new AssignOperator(p.first,
                        new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lhs)));
                ILogicalOperator op = opRef.getValue();
                assign.getInputs().add(new MutableObject<ILogicalOperator>(op));
                opRef.setValue(assign);
                context.computeAndSetTypeEnvironmentForOperator(assign);
            }
            iter.remove();
            changed = true;
        } else {
            varRhsToLhs.put(v, p.first);
        }
    }
    return changed;
}