List of usage examples for java.util Iterator remove
default void remove()
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test(expected = IllegalStateException.class) public void iteratorRemove() { memberCriteria.membersOfType(Field.class); memberCriteria.withAccess(AccessType.PRIVATE); memberCriteria.withModifiers(Modifier.STATIC); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); Iterator<Member> iterator = memberIterable.iterator(); assertTrue(iterator.hasNext());/*from w ww . jav a2 s . c o m*/ iterator.remove(); }
From source file:fr.ortolang.diffusion.referential.indexing.ReferentialEntityIndexableContent.java
public ReferentialEntityIndexableContent(ReferentialEntity entity) throws IndexableContentParsingException { super(ReferentialService.SERVICE_NAME, entity.getType().name().toLowerCase(), entity.getObjectKey()); // entityType = entity.getType(); content = new HashMap<>(); // Copies referential to content JSONObject jsonObject = new JSONObject(entity.getContent()); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); Object value = jsonObject.get(key); if (value instanceof String && value.toString().isEmpty()) { LOGGER.log(Level.WARNING, "Found empty property [" + key + "] in referential entity [" + entity.getKey() + "]"); iterator.remove(); } else {/* w w w. ja v a 2 s .c o m*/ content.put(key, value); } } // Encodes referential to content String referentialEntityContent = entity.getContent(); try { content.put("content", URLEncoder.encode(referentialEntityContent, "UTF-8")); } catch (JSONException | UnsupportedEncodingException e) { LOGGER.log(Level.WARNING, "Unable to encode content", e); } content.put("key", entity.getKey()); content.put("boost", entity.getBoost()); setContent(content); }
From source file:org.loklak.data.DAO.java
public static Set<Number> getNewUserIdsChunk() { if (newUserIds.size() < 100) return null; Set<Number> chunk = new HashSet<>(); Iterator<Number> i = newUserIds.iterator(); for (int j = 0; j < 100; j++) { chunk.add(i.next());/* ww w . j a v a 2 s .c o m*/ i.remove(); } return chunk; }
From source file:com.dotweblabs.twirl.gae.GaeMarshaller.java
/** * Process <code>EmbeddedEntity</code> and inner <code>EmbeddedEntity</code> * of this entity./*from w w w . ja va2 s . co m*/ * * @param ee {@code EmbeddedEntity} to unmarshall into map * @return unmarshalled */ public static Map<String, Object> createMapFromEmbeddedEntity(final EmbeddedEntity ee) { Map<String, Object> map = null; try { map = new HashMap<String, Object>(); map.putAll(ee.getProperties()); Map<String, Object> newMap = new HashMap<String, Object>(); Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Object> entry = it.next(); if (entry.getValue() instanceof EmbeddedEntity) { LOG.debug("Inner embedded entity found with keyType=" + entry.getKey()); // newMap.put(entry.getKey(), createMapFromEmbeddedEntity( (EmbeddedEntity) entry.getValue())); newMap.put(entry.getKey(), getMapOrList((EmbeddedEntity) entry.getValue())); it.remove(); } } map.putAll(newMap); } catch (Exception e) { // TODO Handle exception e.printStackTrace(); LOG.error("Error when processing EmbeddedEntity to Map"); } return map; }
From source file:me.waltster.Fantasy.command.CommandStats.java
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender instanceof Player) { if (args.length > 0) { List<StatType> types = new LinkedList<StatType>(Arrays.asList(StatType.values())); Iterator<StatType> iterator = types.iterator(); while (iterator.hasNext()) { StatType type = iterator.next(); boolean keep = false; for (String arg : args) { if (type.name().toLowerCase().contains(arg.toLowerCase())) keep = true;//from ww w . j a v a 2 s. c o m } if (!keep) iterator.remove(); } listStats((Player) sender, types.toArray(new StatType[types.size()])); } else { listStats((Player) sender); } } else { sender.sendMessage(ChatColor.RED + "Only a player can use that command!"); } return true; }
From source file:com.liato.bankdroid.banking.banks.Nordea.Nordea.java
@Override public Urllib login() throws LoginException, BankException { try {// w w w . j a v a 2s .co m LoginPackage lp = preLogin(); String response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("felaktiga uppgifter")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } else if (response.contains("nloggningar med ditt personnummer idag")) { Matcher matcher = reCSRF.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " CSRF token."); } String csrftoken = matcher.group(1); Iterator<NameValuePair> it = lp.getPostData().iterator(); while (it.hasNext()) { NameValuePair nv = it.next(); if (nv.getName().equals("_csrf_token")) { it.remove(); break; } } lp.getPostData().add(new BasicNameValuePair("_csrf_token", csrftoken)); //Too many logins, we need to solve a captcha. Bitmap bm = BitmapFactory.decodeStream( urlopen.openStream("https://mobil.nordea.se/banking-nordea/nordea-c3/captcha.png")); String captcha = CaptchaBreaker.iMustBreakYou(bm); bm.recycle(); bm = null; lp.getPostData().add(new BasicNameValuePair("captcha", captcha)); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("felaktiga uppgifter")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:org.callimachusproject.auth.FacebookAuthReader.java
private AccessToken verify(String parameters, String[] via) { String code = getValueAfter(parameters, "code="); String error_description = getValueAfter(parameters, "error_description="); String state = getValueAfter(parameters, "state="); boolean verified = verifyState(state, via); if (error_description != null && error_description.length() > 0) { logger.warn("Facebook says: {}", error_description); return null; } else if (!verified) { logger.error("Invalid facebook manager state"); return null; } else if (code == null) { logger.error("Could not login facebook user"); return null; }/*from w ww .j a v a 2s.c o m*/ long now = System.currentTimeMillis(); synchronized (tokens) { Iterator<AccessToken> iter = tokens.values().iterator(); while (iter.hasNext()) { AccessToken token = iter.next(); if (token.isExpired(now)) { iter.remove(); } } if (tokens.containsKey(parameters)) return tokens.get(parameters); } String redirect_uri = getValueAfter(parameters, "redirect_uri="); String url = ACCESS_URL + "?client_id=" + encode(getFacebookAppId()) + "&redirect_uri=" + encode(redirect_uri) + "&client_secret=" + encode(getFacebookSecret()) + "&code=" + encode(code); try { HttpEntity entity = client.getEntity(url, "application/x-www-form-urlencoded"); try { Scanner scanner = new Scanner(entity.getContent(), "UTF-8"); String content = scanner.useDelimiter("\\A").next(); AccessToken token = new AccessToken(now, content); synchronized (tokens) { tokens.put(parameters, token); return token; } } finally { EntityUtils.consume(entity); } } catch (Exception e) { logger.error(url, e); return null; } }
From source file:com.evolveum.midpoint.web.component.form.multivalue.MultiValueChoosePanel.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 ww .j a v a2s .c om if (object.equals(item.getModelObject())) { iterator.remove(); break; } } if (objects.size() == 0) { objects.add(createNewEmptyItem()); } target.add(this); }
From source file:com.tgn.ProjectApex.DestroyTheMonument.commands.StatsCommand.java
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender instanceof Player) { if (args.length > 0) { List<StatType> types = new LinkedList<StatType>(Arrays.asList(StatType.values())); Iterator<StatType> iterator = types.iterator(); while (iterator.hasNext()) { StatType type = iterator.next(); boolean keep = false; for (String arg : args) { if (type.name().toLowerCase().contains(arg.toLowerCase())) keep = true;/*from ww w . ja v a 2 s. co m*/ } if (!keep) iterator.remove(); } listStats((Player) sender, types.toArray(new StatType[types.size()])); } else { listStats((Player) sender); } } else { sender.sendMessage(ChatColor.RED + _("ERROR_CONSOLE_PLAYERCOMMAND")); } return true; }
From source file:com.alta189.cyborg.api.plugin.CommonPluginManager.java
public synchronized Plugin[] loadPlugins(File paramFile) { if (!paramFile.isDirectory()) { throw new IllegalArgumentException("File parameter was not a Directory!"); }//from w w w.java2 s. c o m if (cyborg.getUpdateFolder() != null) { updateDir = cyborg.getUpdateFolder(); } 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) { CyborgLogger.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) { CyborgLogger.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) { CyborgLogger.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()]); }