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:de.ingrid.iplug.excel.controller.AddMappingController.java

/**
 * Load all sheet of an excel file with an index. 
 * //  w  ww.  j a va2 s  .c  o m
 * @param plugDescription
 * @param sheetIndex
 * @param model
 * @return
 *       Web request "redirect:/iplug-pages/previewExcelFile.html"
 * @throws IOException
 */
@RequestMapping(value = "/iplug-pages/addMapping.html", method = RequestMethod.GET)
public String editSheet(@ModelAttribute("plugDescription") final PlugdescriptionCommandObject plugDescription,
        @RequestParam final Integer sheetIndex, final Model model) throws IOException {
    final Sheets sheets = SheetsService.loadSheets(plugDescription, sheetIndex);
    // trim sheets
    final Iterator<Sheet> it = sheets.iterator();
    while (it.hasNext()) {
        // if trim return true, remove sheet
        if (SheetFilter.trimSheet(it.next())) {
            it.remove();
        }
    }
    model.addAttribute("sheets", sheets);
    return "redirect:/iplug-pages/previewExcelFile.html";
}

From source file:io.coala.json.DynaBean.java

/**
 * @param referenceType// ww w  . j a  va  2  s.c o m
 * @param <S>
 * @param <T>
 * @return
 */
static final <S, T> JsonDeserializer<T> createJsonDeserializer(final ObjectMapper om, final Class<T> resultType,
        final Properties... imports) {
    return new JsonDeserializer<T>() {

        @Override
        public T deserializeWithType(final JsonParser jp, final DeserializationContext ctxt,
                final TypeDeserializer typeDeserializer) throws IOException, JsonProcessingException {
            return deserialize(jp, ctxt);
        }

        @Override
        public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            if (jp.getCurrentToken() == JsonToken.VALUE_NULL)
                return null;

            //            if( Wrapper.class.isAssignableFrom( resultType ) )
            //            {
            //               // FIXME
            //               LOG.trace( "deser wrapper intf of {}", jp.getText() );
            //               return (T) Wrapper.Util.valueOf( jp.getText(),
            //                     resultType.asSubclass( Wrapper.class ) );
            //            } 
            if (Config.class.isAssignableFrom(resultType)) {
                final Map<String, Object> entries = jp.readValueAs(new TypeReference<Map<String, Object>>() {
                });

                final Iterator<Entry<String, Object>> it = entries.entrySet().iterator();
                for (Entry<String, Object> next = null; it.hasNext(); next = it.next())
                    if (next != null && next.getValue() == null) {
                        LOG.trace("Ignoring null value: {}", next);
                        it.remove();
                    }
                return resultType.cast(ConfigFactory.create(resultType.asSubclass(Config.class), entries));
            }
            // else if (Config.class.isAssignableFrom(resultType))
            // throw new JsonGenerationException(
            // "Config does not extend "+Mutable.class.getName()+" required for deserialization: "
            // + Arrays.asList(resultType
            // .getInterfaces()));

            // can't parse directly to interface type
            final DynaBean bean = new DynaBean();
            final TreeNode tree = jp.readValueAsTree();

            // override attributes as defined in interface getters
            final Set<String> attributes = new HashSet<>();
            for (Method method : resultType.getMethods()) {
                if (method.getReturnType().equals(Void.TYPE) || method.getParameterTypes().length != 0)
                    continue;

                final String attribute = method.getName();
                if (attribute.equals("toString") || attribute.equals("hashCode"))
                    continue;

                attributes.add(attribute);
                final TreeNode value = tree.get(attribute);// bean.any().get(attributeName);
                if (value == null)
                    continue;

                bean.set(method.getName(),
                        om.treeToValue(value, JsonUtil.checkRegistered(om, method.getReturnType(), imports)));
            }
            if (tree.isObject()) {
                // keep superfluous properties as TreeNodes, just in case
                final Iterator<String> fieldNames = tree.fieldNames();
                while (fieldNames.hasNext()) {
                    final String fieldName = fieldNames.next();
                    if (!attributes.contains(fieldName))
                        bean.set(fieldName, tree.get(fieldName));
                }
            } else if (tree.isValueNode()) {
                for (Class<?> type : resultType.getInterfaces())
                    for (Method method : type.getDeclaredMethods()) {
                        //                     LOG.trace( "Scanning {}", method );
                        if (method.isAnnotationPresent(JsonProperty.class)) {
                            final String property = method.getAnnotation(JsonProperty.class).value();
                            //                        LOG.trace( "Setting {}: {}", property,
                            //                              ((ValueNode) tree).textValue() );
                            bean.set(property, ((ValueNode) tree).textValue());
                        }
                    }
            } else
                throw ExceptionFactory.createUnchecked("Expected {} but parsed: {}", resultType,
                        tree.getClass());

            return DynaBean.proxyOf(om, resultType, bean, imports);
        }
    };
}

From source file:com.adobe.acs.commons.reports.models.ReferencesModel.java

@PostConstruct
public void init() {
    referenceList = aggregator.createReferenceList(resource);
    Iterator<Reference> references = referenceList.iterator();
    while (references.hasNext()) {
        if (references.next().getTarget().getPath().equals(resource.getPath())) {
            references.remove();
        }/*from w w  w.  ja  v a 2  s .c  o  m*/
    }
}

From source file:net.lmxm.ute.gui.components.MavenArtifactsTableModel.java

/**
 * Clean row data.//from   w  w  w.j  a v a 2 s.co m
 */
private void cleanRowData() {
    final Iterator<MavenArtifact> iterator = artifacts.iterator();
    while (iterator.hasNext()) {
        if (iterator.next().isEmpty()) {
            iterator.remove();
        }
    }

    artifacts.add(new MavenArtifact());
}

From source file:net.lmxm.ute.gui.components.FindReplacePatternsTableModel.java

/**
 * Clean row data.//  www. j ava2s.  co m
 */
private void cleanRowData() {
    final Iterator<FindReplacePattern> iterator = rowData.iterator();
    while (iterator.hasNext()) {
        if (iterator.next().isEmpty()) {
            iterator.remove();
        }
    }

    rowData.add(new FindReplacePattern());
}

From source file:org.openmrs.module.providermanagement.fragment.controller.PersonSearchFragmentController.java

public List<SimpleObject> getPeople(@RequestParam(value = "searchValue", required = true) String searchValue,
        @RequestParam(value = "resultFields[]", required = true) String[] resultFields, UiUtils ui) {

    if (resultFields == null || resultFields.length == 0) {
        resultFields = new String[] { "personName" };
    }/*from ww w.jav a 2 s .co m*/

    // always want to return the id of the result objects
    resultFields = ArrayUtils.add(resultFields, "id");

    // now fetch the results
    List<Person> people = Context.getPersonService().getPeople(searchValue, false);

    // exclude anyone who is already a provider
    Iterator<Person> i = people.iterator();
    while (i.hasNext()) {
        Person p = i.next();
        if (Context.getService(ProviderManagementService.class).isProvider(p)) {
            i.remove();
        }
    }

    // the get people search doesn't appear to sort by name, so we do that here
    Collections.sort(people, new PersonByFirstNameComparator());

    return SimpleObject.fromCollection(people, ui, resultFields);
}

From source file:edu.internet2.middleware.shibboleth.common.util.EventingMapBasedStorageServiceTest.java

public void testStorageService() {
    AddEntryListener addListener = new AddEntryListener();
    RemoveEntryListener removeListener = new RemoveEntryListener();

    GenericApplicationContext appCtx = new GenericApplicationContext();
    EventingMapBasedStorageService<String, String> storageService = new EventingMapBasedStorageService<String, String>();
    storageService.setApplicationContext(appCtx);
    appCtx.addApplicationListener(addListener);
    appCtx.addApplicationListener(removeListener);
    appCtx.refresh();//  w  w  w . j  ava2 s.  c  o m

    String partition = "partition";
    String value = "value";

    String key1 = "string1";
    storageService.put(partition, key1, value);

    String key2 = "string2";
    storageService.put(partition, key2, value);

    String key3 = "string3";
    storageService.put(partition, key3, value);

    String key4 = "string4";
    storageService.put(partition, key4, value);

    String key5 = "string5";
    storageService.put(partition, key5, value);

    assertEquals(5, addListener.getCount());
    assertEquals(0, removeListener.getCount());
    assertEquals(true, storageService.contains(partition, key1));
    assertEquals(true, storageService.contains(partition, key2));
    assertEquals(true, storageService.contains(partition, key3));
    assertEquals(true, storageService.contains(partition, key4));
    assertEquals(true, storageService.contains(partition, key5));

    storageService.remove(partition, key1);
    assertEquals(5, addListener.getCount());
    assertEquals(1, removeListener.getCount());
    assertEquals(false, storageService.contains(partition, key1));
    assertEquals(true, storageService.contains(partition, key2));
    assertEquals(true, storageService.contains(partition, key3));
    assertEquals(true, storageService.contains(partition, key4));
    assertEquals(true, storageService.contains(partition, key5));

    Iterator<String> keysItr = storageService.getKeys(partition);
    keysItr.next();
    keysItr.remove();
    assertEquals(5, addListener.getCount());
    assertEquals(2, removeListener.getCount());

    Iterator<String> partiationsItr = storageService.getPartitions();
    partiationsItr.next();
    partiationsItr.remove();
    assertEquals(5, addListener.getCount());
    assertEquals(5, removeListener.getCount());
    assertEquals(false, storageService.contains(partition, key1));
    assertEquals(false, storageService.contains(partition, key2));
    assertEquals(false, storageService.contains(partition, key3));
    assertEquals(false, storageService.contains(partition, key4));
    assertEquals(false, storageService.contains(partition, key5));
}

From source file:org.pdfgal.pdfgal.utils.impl.ConverterUtilsImpl.java

@Override
public void deleteNonSelectedPositions(final List<?> objectsList, final List<Integer> positionsList) {

    if (CollectionUtils.isNotEmpty(objectsList) && CollectionUtils.isNotEmpty(positionsList)) {
        Integer position = 1;//  w ww  .j av  a 2  s . c  om
        final Iterator<?> iterator = objectsList.iterator();
        while (iterator.hasNext()) {
            iterator.next();
            if (!positionsList.contains(position)) {
                iterator.remove();
            }
            position++;
        }
    }
}

From source file:lodsve.core.condition.OnClassCondition.java

private List<String> getMatchingClasses(MultiValueMap<String, Object> attributes, MatchType matchType,
        ConditionContext context) {//from   w w w . java  2  s  . c o m
    List<String> matches = new LinkedList<String>();
    addAll(matches, attributes.get("value"));
    addAll(matches, attributes.get("name"));
    Iterator<String> iterator = matches.iterator();
    while (iterator.hasNext()) {
        if (!matchType.matches(iterator.next(), context)) {
            iterator.remove();
        }
    }
    return matches;
}

From source file:de.ingrid.iplug.excel.controller.UploadController.java

/**
 *    Upload excel file.//  w w w.jav  a  2s .  c o m
 * 
 * @param uploadBean
 * @param model
 * @return
 *       Web request "redirect:/iplug-pages/previewExcelFile.html"
 * @throws IOException
 */
@RequestMapping(method = RequestMethod.POST)
public String upload(@ModelAttribute("uploadBean") final UploadBean uploadBean, final Model model)
        throws IOException {
    // create sheets
    final Sheets sheets = SheetsService.createSheets(uploadBean.getFile());
    // trim sheets
    final Iterator<Sheet> it = sheets.iterator();
    while (it.hasNext()) {
        // if trim return true, remove sheet
        if (SheetFilter.trimSheet(it.next())) {
            it.remove();
        }
    }
    model.addAttribute("sheets", sheets);
    return "redirect:/iplug-pages/previewExcelFile.html";
}