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.alta189.chavabot.plugin.CommonPluginManager.java

public synchronized Plugin[] loadPlugins(File paramFile) {

    if (!paramFile.isDirectory())
        throw new IllegalArgumentException("File parameter was not a Directory!");

    if (chavamanager.getUpdateFolder() != null) {
        updateDir = chavamanager.getUpdateFolder();
    }/*from   ww  w.  j av  a2  s  . c om*/

    List<Plugin> result = new ArrayList<Plugin>();
    LinkedList<File> files = new LinkedList<File>(Arrays.asList(paramFile.listFiles()));
    boolean failed = false;
    boolean lastPass = false;

    while (!failed || lastPass) {
        failed = true;
        Iterator<File> iterator = files.iterator();

        while (iterator.hasNext()) {
            File file = iterator.next();
            Plugin plugin = null;

            if (file.isDirectory()) {
                iterator.remove();
                continue;
            }

            try {
                plugin = loadPlugin(file, lastPass);
                iterator.remove();
            } catch (UnknownDependencyException e) {
                if (lastPass) {
                    chavamanager.getLogger().log(Level.SEVERE,
                            new StringBuilder().append("Unable to load '").append(file.getName())
                                    .append("' in directory '").append(paramFile.getPath()).append("': ")
                                    .append(e.getMessage()).toString(),
                            e);
                    iterator.remove();
                } else {
                    plugin = null;
                }
            } catch (InvalidDescriptionFileException e) {
                chavamanager.getLogger().log(Level.SEVERE,
                        new StringBuilder().append("Unable to load '").append(file.getName())
                                .append("' in directory '").append(paramFile.getPath()).append("': ")
                                .append(e.getMessage()).toString(),
                        e);
                iterator.remove();
            } catch (InvalidPluginException e) {
                chavamanager.getLogger().log(Level.SEVERE,
                        new StringBuilder().append("Unable to load '").append(file.getName())
                                .append("' in directory '").append(paramFile.getPath()).append("': ")
                                .append(e.getMessage()).toString(),
                        e);
                iterator.remove();
            }

            if (plugin != null) {
                result.add(plugin);
                failed = false;
                lastPass = false;
            }
        }
        if (lastPass) {
            break;
        } else if (failed) {
            lastPass = true;
        }
    }

    return result.toArray(new Plugin[result.size()]);
}

From source file:edu.amc.sakai.user.SimpleLdapCandidateAttributeMapper.java

/**
 * Completes configuration of this instance.
 * //  w w  w. j  a v  a 2 s.c  o  m
 * <p>Initializes internal mappings to a copy of 
 * {@link AttributeMappingConstants#DEFAULT_ATTR_MAPPINGS} if 
 * the current map is empty. Initializes user 
 * type mapping strategy to a 
 * {@link EmptyStringUserTypeMapper} if no strategy
 * has been specified.
 * </p>
 * 
 * <p>This defaulting enables UDP config 
 * forward-compatibility.</p>
 * 
 */
public void init() {

    log.debug("init()");

    if (getAttributeMappings() == null || getAttributeMappings().isEmpty()) {
        log.debug("init(): creating default attribute mappings");
        setAttributeMappings(AttributeMappingConstants.CANDIDATE_ATTR_MAPPINGS);
    }

    if (getUserTypeMapper() == null) {
        setUserTypeMapper(new EmptyStringUserTypeMapper());
        log.debug("init(): created default user type mapper [mapper = {}]", getUserTypeMapper());
    }
    if (getValueMappings() == null) {
        setValueMappings(Collections.EMPTY_MAP);
        log.debug("init(): created default value mapper [mapper = {}]", getValueMappings());
    } else {
        // Check we have good value mappings and throw any out that aren't (warning user).
        Iterator<Entry<String, MessageFormat>> iterator = getValueMappings().entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, MessageFormat> entry = iterator.next();
            if (entry.getValue().getFormats().length != 1) {
                iterator.remove();
                log.warn("Removed value mapping as it didn't have one format: {} -> {}", entry.getKey(),
                        entry.getValue().toPattern());
            }
        }
    }
}

From source file:de.fau.amos4.util.ZipGenerator.java

public void generate(OutputStream out, Locale locale, float height, Employee employee, int fontSize,
        String zipPassword) throws ZipException, NoSuchMessageException, IOException, COSVisitorException,
        CloneNotSupportedException {
    final ZipOutputStream zout = new ZipOutputStream(out);

    if (zipPassword == null) {
        // Use default password if none is set.
        zipPassword = "fragebogen";
    }/*from  w  ww  . ja  v  a 2s.  c  o  m*/

    ZipParameters params = new ZipParameters();
    params.setFileNameInZip("employee.txt");
    params.setCompressionLevel(Zip4jConstants.COMP_DEFLATE);
    params.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
    params.setEncryptFiles(true);
    params.setReadHiddenFiles(false);
    params.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
    params.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
    params.setPassword(zipPassword);
    params.setSourceExternalStream(true);

    zout.putNextEntry(null, params);
    zout.write((AppContext.getApplicationContext().getMessage("HEADER", null, locale) + "\n\n").getBytes());

    zout.write(
            (AppContext.getApplicationContext().getMessage("print.section.personalData", null, locale) + "\n\n")
                    .getBytes());

    Iterator it = employee.getPersonalDataFields().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        zout.write((pair.getKey() + ": " + pair.getValue() + '\n').getBytes());
        it.remove(); // avoids a ConcurrentModificationException
    }

    zout.write(("\n\n" + AppContext.getApplicationContext().getMessage("print.section.taxes", null, locale)
            + "\n\n").getBytes());

    it = employee.getTaxesFields().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        zout.write((pair.getKey() + ": " + pair.getValue() + '\n').getBytes());
        it.remove(); // avoids a ConcurrentModificationException
    }
    zout.closeEntry();

    // Create a document and add a page to it
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    float y = -1;
    int margin = 100;

    // Create a new font object selecting one of the PDF base fonts
    PDFont font = PDType1Font.TIMES_ROMAN;

    // Start a new content stream which will "hold" the to be created content
    PDPageContentStream contentStream = new PDPageContentStream(document, page);

    // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
    contentStream.beginText();

    y = page.getMediaBox().getHeight() - margin + height;
    contentStream.moveTextPositionByAmount(margin, y);
    /*
    List<String> list = StringUtils.splitEqually(fileContent, 90);
    for (String e : list) {
        contentStream.moveTextPositionByAmount(0, -15);
        contentStream.drawString(e);
    }
    */

    contentStream.setFont(PDType1Font.TIMES_BOLD, 36);
    contentStream.drawString(AppContext.getApplicationContext().getMessage("HEADER", null, locale));
    contentStream.setFont(PDType1Font.TIMES_BOLD, 14);
    contentStream.moveTextPositionByAmount(0, -4 * height);
    contentStream.drawString(
            AppContext.getApplicationContext().getMessage("print.section.personalData", null, locale));
    contentStream.moveTextPositionByAmount(0, -2 * height);
    contentStream.setFont(font, fontSize);

    it = employee.getPersonalDataFields().entrySet().iterator();
    while (it.hasNext()) {
        StringBuffer nextLineToDraw = new StringBuffer();
        Map.Entry pair = (Map.Entry) it.next();
        nextLineToDraw.append(pair.getKey());
        nextLineToDraw.append(": ");
        nextLineToDraw.append(pair.getValue());

        contentStream.drawString(nextLineToDraw.toString());
        contentStream.moveTextPositionByAmount(0, -height);
        it.remove(); // avoids a ConcurrentModificationException
    }
    contentStream.setFont(PDType1Font.TIMES_BOLD, 14);
    contentStream.moveTextPositionByAmount(0, -2 * height);
    contentStream
            .drawString(AppContext.getApplicationContext().getMessage("print.section.taxes", null, locale));
    contentStream.moveTextPositionByAmount(0, -2 * height);
    contentStream.setFont(font, fontSize);
    it = employee.getTaxesFields().entrySet().iterator();
    while (it.hasNext()) {
        StringBuffer nextLineToDraw = new StringBuffer();
        Map.Entry pair = (Map.Entry) it.next();
        nextLineToDraw.append(pair.getKey());
        nextLineToDraw.append(": ");
        nextLineToDraw.append(pair.getValue());

        contentStream.drawString(nextLineToDraw.toString());
        contentStream.moveTextPositionByAmount(0, -height);
        it.remove(); // avoids a ConcurrentModificationException
    }
    contentStream.endText();

    // Make sure that the content stream is closed:
    contentStream.close();

    // Save the results and ensure that the document is properly closed:
    ByteArrayOutputStream pdfout = new ByteArrayOutputStream();
    document.save(pdfout);
    document.close();

    ZipParameters params2 = (ZipParameters) params.clone();
    params2.setFileNameInZip("employee.pdf");

    zout.putNextEntry(null, params2);
    zout.write(pdfout.toByteArray());
    zout.closeEntry();

    // Write the zip to client
    zout.finish();
    zout.flush();
    zout.close();
}

From source file:com.google.uzaygezen.core.BoundedRollup.java

/**
 * Removes all the remaining elements of the iterator, including the current
 * element./*from   ww  w. j  a  v  a2  s  .c  o  m*/
 */
private void removeTail(Iterator<TreeNode> iterator, TreeNode currentNode) {
    TreeNode previousToLast = iterator.hasNext() ? currentNode : null;
    iterator.remove();
    while (iterator.hasNext()) {
        TreeNode node = iterator.next();
        if (iterator.hasNext()) {
            previousToLast = node;
        }
        iterator.remove();
    }
    if (previousToLast != null && previousToLast.allChildrenOfThisInternalNodeAreLeaves()) {
        Preconditions.checkState(minHeap.offer(new ComparableTreeNode(previousToLast)));
    }
}

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

private boolean removeUnusedVarsAndExprs(Set<LogicalVariable> toRemove, List<LogicalVariable> varList,
        List<Mutable<ILogicalExpression>> exprList) {
    boolean changed = false;
    Iterator<LogicalVariable> varIter = varList.iterator();
    Iterator<Mutable<ILogicalExpression>> exprIter = exprList.iterator();
    while (varIter.hasNext()) {
        LogicalVariable v = varIter.next();
        exprIter.next();//from w w w.j a  v  a2  s  .com
        if (toRemove.contains(v)) {
            varIter.remove();
            exprIter.remove();
            changed = true;
        }
    }
    return changed;
}

From source file:com.netflix.discovery.shared.Application.java

private void _shuffleAndStoreInstances(boolean filterUpInstances, boolean indexByRemoteRegions,
        @Nullable Map<String, Applications> remoteRegionsRegistry, @Nullable EurekaClientConfig clientConfig,
        @Nullable InstanceRegionChecker instanceRegionChecker) {
    List<InstanceInfo> instanceInfoList;
    synchronized (instances) {
        instanceInfoList = new ArrayList<InstanceInfo>(instances);
    }//from  www  . j ava2s .c om
    if (indexByRemoteRegions || filterUpInstances) {
        Iterator<InstanceInfo> it = instanceInfoList.iterator();
        while (it.hasNext()) {
            InstanceInfo instanceInfo = it.next();
            if (filterUpInstances && !InstanceStatus.UP.equals(instanceInfo.getStatus())) {
                it.remove();
            } else if (indexByRemoteRegions && null != instanceRegionChecker && null != clientConfig
                    && null != remoteRegionsRegistry) {
                String instanceRegion = instanceRegionChecker.getInstanceRegion(instanceInfo);
                if (!instanceRegionChecker.isLocalRegion(instanceRegion)) {
                    Applications appsForRemoteRegion = remoteRegionsRegistry.get(instanceRegion);
                    if (null == appsForRemoteRegion) {
                        appsForRemoteRegion = new Applications();
                        remoteRegionsRegistry.put(instanceRegion, appsForRemoteRegion);
                    }

                    Application remoteApp = appsForRemoteRegion
                            .getRegisteredApplications(instanceInfo.getAppName());
                    if (null == remoteApp) {
                        remoteApp = new Application(instanceInfo.getAppName());
                        appsForRemoteRegion.addApplication(remoteApp);
                    }

                    remoteApp.addInstance(instanceInfo);
                    this.removeInstance(instanceInfo, false);
                    it.remove();
                }
            }
        }

    }
    Collections.shuffle(instanceInfoList);
    this.shuffledInstances.set(instanceInfoList);
}

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

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

From source file:at.beris.virtualfile.FileContext.java

private void disposeFileTypeToFileOperationProviderMap(Map<FileType, FileOperationProvider> map) {
    Iterator<Map.Entry<FileType, FileOperationProvider>> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<FileType, FileOperationProvider> next = it.next();
        next.getValue().dispose();/*from w  w  w  .ja v  a 2  s  . co  m*/
        it.remove();
    }
}

From source file:com.gmail.tracebachi.DeltaSkins.Shared.MojangApi.java

private String convertUuidRequestsToStringPayload() {
    synchronized (uuidRequestLock) {
        Iterator<String> iterator = uuidRequests.iterator();
        JsonArray array = new JsonArray();

        for (int i = 0; i < 100 && iterator.hasNext(); ++i) {
            String next = iterator.next();

            if (next != null && !next.isEmpty()) {
                array.add(new JsonPrimitive(next));
            }/*from   w  ww  . j a  v a 2  s .  c  o  m*/

            iterator.remove();
        }

        return gson.toJson(array);
    }
}