List of usage examples for java.util Iterator remove
default void remove()
From source file:forge.card.BoosterGenerator.java
/** * This method also modifies passed parameter *///from w ww .j av a 2 s .c o m private static Predicate<PaperCard> buildExtraPredicate(List<String> operators) { List<Predicate<PaperCard>> conditions = new ArrayList<>(); Iterator<String> itOp = operators.iterator(); while (itOp.hasNext()) { String operator = itOp.next(); if (StringUtils.isEmpty(operator)) { itOp.remove(); continue; } if (operator.endsWith("s")) { operator = operator.substring(0, operator.length() - 1); } boolean invert = operator.charAt(0) == '!'; if (invert) { operator = operator.substring(1); } Predicate<PaperCard> toAdd = null; if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) { toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform), PaperCard.FN_GET_RULES); } else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard.FN_GET_RULES); } else if (operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) { toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND; } else if (operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL; } else if (operator.equalsIgnoreCase(BoosterSlots.SPECIAL)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL; } else if (operator.equalsIgnoreCase(BoosterSlots.MYTHIC)) { toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE; } else if (operator.equalsIgnoreCase(BoosterSlots.RARE)) { toAdd = IPaperCard.Predicates.Presets.IS_RARE; } else if (operator.equalsIgnoreCase(BoosterSlots.UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON; } else if (operator.equalsIgnoreCase(BoosterSlots.COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON; } else if (operator.startsWith("name(")) { operator = StringUtils.strip(operator.substring(4), "() "); String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"'); toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames)); } else if (operator.startsWith("color(")) { operator = StringUtils.strip(operator.substring("color(".length() + 1), "()\" "); switch (operator.toLowerCase()) { case "black": toAdd = Presets.IS_BLACK; break; case "blue": toAdd = Presets.IS_BLUE; break; case "green": toAdd = Presets.IS_GREEN; break; case "red": toAdd = Presets.IS_RED; break; case "white": toAdd = Presets.IS_WHITE; break; case "colorless": toAdd = Presets.IS_COLORLESS; break; } } else if (operator.startsWith("fromSets(")) { operator = StringUtils.strip(operator.substring("fromSets(".length() + 1), "()\" "); String[] sets = operator.split(","); toAdd = IPaperCard.Predicates.printedInSets(sets); } else if (operator.startsWith("fromSheet(") && invert) { String sheetName = StringUtils.strip(operator.substring(9), "()\" "); Iterable<PaperCard> src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); List<String> cardNames = Lists.newArrayList(); for (PaperCard card : src) { cardNames.add(card.getName()); } toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames)); } if (toAdd == null) { continue; } else { itOp.remove(); } if (invert) { toAdd = Predicates.not(toAdd); } conditions.add(toAdd); } if (conditions.isEmpty()) { return Predicates.alwaysTrue(); } return Predicates.and(conditions); }
From source file:com.silverpeas.jcrutil.BasicDaoFactory.java
/** * Remove a reference from an array of javax.jcr.Value. If the reference is not found no change is * done to the array./*from w w w . j a v a 2s . c o m*/ * * @param values the array of references * @param uuid the reference to be removed * @return the updated arry of references. * @throws ValueFormatException * @throws IllegalStateException * @throws RepositoryException */ public static Value[] removeReference(Value[] values, String uuid) throws ValueFormatException, IllegalStateException, RepositoryException { List<Value> references = new ArrayList<Value>(Arrays.asList(values)); Iterator<Value> iter = references.iterator(); while (iter.hasNext()) { Value value = iter.next(); if (uuid.equals(value.getString())) { iter.remove(); return references.toArray(new Value[values.length - 1]); } } return values; }
From source file:de.xwic.appkit.core.util.CollectionUtil.java
/** * Used to filter a collection of <b>objects</b><br> * Only the values that return true are kept<br> * <b>It is your responsibility to make sure that the element is not null, consider {@link NotNullFilter}</b><br> * @param objects the collection from which we create the collection * @param filter the filter//from ww w . j a va2 s . c o m * @return the filtered collection passed as the parameter. <b>the original collection is also altered.</b> */ public static <C extends Collection<O>, O> C filter(final C objects, final IFilter<O> filter) { if (objects != null) { final Iterator<O> iterator = objects.iterator(); while (iterator.hasNext()) { if (!filter.keep(iterator.next())) { iterator.remove(); } } } return objects; }
From source file:models.NotificationMail.java
/** * Sends notification mails for the given event. * * @param event/* w w w . j av a 2 s.co m*/ * @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> */ private static void sendNotification(NotificationEvent event) { Set<User> receivers = event.receivers; // Remove inactive users. Iterator<User> iterator = receivers.iterator(); while (iterator.hasNext()) { User user = iterator.next(); if (user.state != UserState.ACTIVE) { iterator.remove(); } } receivers.remove(User.anonymous); if (receivers.isEmpty()) { return; } HashMap<String, List<User>> usersByLang = new HashMap<>(); for (User receiver : receivers) { String lang = receiver.lang; if (lang == null) { lang = Locale.getDefault().getLanguage(); } if (usersByLang.containsKey(lang)) { usersByLang.get(lang).add(receiver); } else { usersByLang.put(lang, new ArrayList<>(Arrays.asList(receiver))); } } for (String langCode : usersByLang.keySet()) { final EventEmail email = new EventEmail(event); try { if (hideAddress) { email.setFrom(Config.getEmailFromSmtp(), event.getSender().name); email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName()); } else { email.setFrom(event.getSender().email, event.getSender().name); } for (User receiver : usersByLang.get(langCode)) { if (hideAddress) { email.addBcc(receiver.email, receiver.name); } else { email.addTo(receiver.email, receiver.name); } } if (email.getToAddresses().isEmpty()) { continue; } Lang lang = Lang.apply(langCode); String message = event.getMessage(lang); String urlToView = event.getUrlToView(); String reference = Url.removeFragment(event.getUrlToView()); email.setSubject(event.title); Resource resource = event.getResource(); if (resource.getType() == ResourceType.ISSUE_COMMENT) { IssueComment issueComment = IssueComment.find.byId(Long.valueOf(resource.getId())); resource = issueComment.issue.asResource(); } email.setHtmlMsg(getHtmlMessage(lang, message, urlToView, resource)); email.setTextMsg(getPlainMessage(lang, message, Url.create(urlToView))); email.setCharset("utf-8"); email.addReferences(); email.setSentDate(event.created); Mailer.send(email); String escapedTitle = email.getSubject().replace("\"", "\\\""); String logEntry = String.format("\"%s\" %s", escapedTitle, email.getBccAddresses()); play.Logger.of("mail").info(logEntry); } catch (Exception e) { Logger.warn("Failed to send a notification: " + email + "\n" + ExceptionUtils.getStackTrace(e)); } } }
From source file:imperial.modaclouds.monitoring.sda.weka.CreateArff.java
/** * Create arff file given the data// ww w.j a va2 s. c o m * * @param timestamps_str the timestamps data * @param data the values of the metrics * @param metricName the metric name * @param fileName the file name to keep the arff file */ public static void create(ArrayList<ArrayList<String>> timestamps_str, ArrayList<ArrayList<String>> data, ArrayList<String> metricName, String fileName) { System.out.println("data: " + data.get(0)); long min_timestamp = Long.valueOf(Collections.min(timestamps_str.get(0))); long max_timestamp = Long.valueOf(Collections.max(timestamps_str.get(0))); for (int i = 1; i < timestamps_str.size(); i++) { long min_temp = Long.valueOf(Collections.min(timestamps_str.get(i))); long max_temp = Long.valueOf(Collections.max(timestamps_str.get(i))); if (max_temp < max_timestamp) { max_timestamp = max_temp; } if (min_temp > min_timestamp) { min_timestamp = min_temp; } } for (int i = 0; i < timestamps_str.size(); i++) { Iterator<String> iter_time = timestamps_str.get(i).iterator(); Iterator<String> iter_data = data.get(i).iterator(); while (iter_time.hasNext()) { long temp_timestamps = Long.valueOf(iter_time.next()); if (temp_timestamps < min_timestamp || temp_timestamps > max_timestamp) { iter_time.remove(); iter_data.next(); iter_data.remove(); } } } double[] timestamps = convertDoubles(timestamps_str.get(0)); double[] targetData = convertDoubles(data.get(0)); double[][] otherData = new double[data.size() - 1][timestamps.length]; for (int i = 0; i < data.size() - 1; i++) { double[] timestamps_temp = convertDoubles(timestamps_str.get(i)); double[] targetData_temp = convertDoubles(data.get(i)); SplineInterpolator spline = new SplineInterpolator(); Map<Double, Integer> map = new TreeMap<Double, Integer>(); for (int j = 0; j < timestamps_temp.length; j++) { map.put(timestamps_temp[j], j); } Collection<Integer> indices = map.values(); int[] indices_int = ArrayUtils.toPrimitive(indices.toArray(new Integer[indices.size()])); double[] timestamps_temp_new = new double[indices_int.length]; double[] targetData_temp_new = new double[indices_int.length]; for (int j = 0; j < indices_int.length; j++) { timestamps_temp_new[j] = timestamps_temp[indices_int[j]]; targetData_temp_new[j] = targetData_temp[indices_int[j]]; } PolynomialSplineFunction polynomical = spline.interpolate(timestamps_temp_new, targetData_temp_new); for (int j = 0; j < timestamps.length; j++) { try { otherData[i][j] = polynomical.value(timestamps[j]); } catch (Exception ex) { otherData[i][j] = targetData_temp_new[j]; } } } ArrayList<Attribute> attributes; Instances dataSet; attributes = new ArrayList<Attribute>(); for (String metric : metricName) { attributes.add(new Attribute(metric)); } dataSet = new Instances("data", attributes, 0); for (int i = 0; i < timestamps.length; i++) { double[] instanceValue1 = new double[dataSet.numAttributes()]; instanceValue1[0] = timestamps[i]; instanceValue1[1] = targetData[i]; for (int j = 0; j < data.size() - 1; j++) { instanceValue1[2 + j] = otherData[j][i]; } DenseInstance denseInstance1 = new DenseInstance(1.0, instanceValue1); dataSet.add(denseInstance1); } ArffSaver saver = new ArffSaver(); saver.setInstances(dataSet); try { String workingDir = System.getProperty("user.dir"); System.out.println("workingDir: " + workingDir); saver.setFile(new File(workingDir + "/" + fileName)); saver.writeBatch(); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java
static void removeDestroyObjectCall(List calls) { Iterator iter = calls.iterator(); while (iter.hasNext()) { MethodCall call = (MethodCall) iter.next(); if ("destroyObject".equals(call.getName())) { iter.remove(); }//from ww w . j ava 2 s. co m } }
From source file:gaffer.rest.service.SimpleGraphConfigurationService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); while (itr.hasNext()) { final Class clazz = itr.next(); if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove(); }//from www . ja va 2s. c o m } } } }
From source file:net.sourceforge.atunes.kernel.modules.player.PlayerHandler.java
/** * Gets the single instance of PlayerHandler. This method returns player * engine configured by user or default if it's available on the system * //from ww w . j a v a 2 s.c o m * @return single instance of PlayerHandler */ public static final synchronized PlayerHandler getInstance() { if (instance == null) { instance = new PlayerHandler(); // Get engines list List<PlayerEngine> engines = getEngines(); // Remove unsupported engines Iterator<PlayerEngine> it = engines.iterator(); while (it.hasNext()) { if (!it.next().isEngineAvailable()) { it.remove(); } } // Update engine names engineNames = new String[engines.size()]; for (int i = 0; i < engines.size(); i++) { engineNames[i] = engines.get(i).getEngineName(); } Arrays.sort(engineNames); getLogger().info(LogCategories.PLAYER, "List of availables engines : " + ArrayUtils.toString(engineNames)); if (engines.isEmpty()) { handlePlayerError(new IllegalStateException(LanguageTool.getString("NO_PLAYER_ENGINE"))); } else { // Get engine of application state (default or selected by user) String selectedEngine = ApplicationState.getInstance().getPlayerEngine(); // If selected engine is not available then try default engine or another one if (!ArrayUtils.contains(engineNames, selectedEngine)) { getLogger().info(LogCategories.PLAYER, selectedEngine + " is not availaible"); if (ArrayUtils.contains(engineNames, DEFAULT_ENGINE)) { selectedEngine = DEFAULT_ENGINE; } else { // If default engine is not available, then get the first engine of map returned selectedEngine = engines.iterator().next().getEngineName(); } // Update application state with this engine ApplicationState.getInstance().setPlayerEngine(selectedEngine); } for (PlayerEngine engine : engines) { if (engine.getEngineName().equals(selectedEngine)) { instance.playerEngine = engine; getLogger().info(LogCategories.PLAYER, "Engine initialized : " + selectedEngine); } } if (instance.playerEngine == null) { handlePlayerError(new IllegalStateException(LanguageTool.getString("NO_PLAYER_ENGINE"))); } // Init engine instance.playerEngine.initializePlayerEngine(); Kernel.getInstance().addFinishListener(instance); // Add core playback listeners instance.playerEngine.addPlaybackStateListener(instance.playerEngine); instance.playerEngine.addPlaybackStateListener(VisualHandler.getInstance()); instance.playerEngine.addPlaybackStateListener(NotifyHandler.getInstance()); } // Add a shutdown hook to perform some actions before killing the JVM Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { getLogger().debug(LogCategories.SHUTDOWN_HOOK, "Final check for Zombie player engines"); instance.playerEngine.killPlayer(); getLogger().debug(LogCategories.SHUTDOWN_HOOK, "Closing player ..."); } })); } return instance; }
From source file:com.wolvencraft.yasp.util.Util.java
/** * Parses the specified string, replacing variables with corresponding values.<br /> * Borrows the variables and values from ServerTotals. * * @param str String to parse/*from www. ja v a2s . c o m*/ * @return Parsed string */ public static String parseVars(String str) { if (str == null) return ""; Map<ServerVariable, Object> values = Statistics.getServerTotals().getValues(); Iterator<Entry<ServerVariable, Object>> it = values.entrySet().iterator(); while (it.hasNext()) { Map.Entry<ServerVariable, Object> pairs = (Map.Entry<ServerVariable, Object>) it.next(); str = str.replace("<" + pairs.getKey().getAlias() + ">", pairs.getValue() + ""); it.remove(); } str = str.replace("<Y>", ""); return parseChatColors(str); }
From source file:com.clustercontrol.infra.factory.UpdateInfraCheckResult.java
/** * @throws InfraManagementNotFound /* w w w . ja va 2s . co m*/ */ public static void update(String managementId, String moduleId, List<ModuleNodeResult> resultList) { m_log.debug("update() : start"); m_log.debug(String.format("update() : managementId = %s", managementId)); // ??? try { new SelectInfraManagement().get(managementId, ObjectPrivilegeMode.READ); } catch (InfraManagementNotFound | InvalidRole | HinemosUnknown e) { m_log.warn("update " + e.getClass().getName() + ", " + e.getMessage()); } List<InfraCheckResult> entities = QueryUtil.getInfraCheckResultFindByModuleId(managementId, moduleId); List<ModuleNodeResult> newResultList = new ArrayList<>(resultList); List<InfraCheckResult> oldResultList = new ArrayList<>(entities); m_log.info("newResult.size=" + newResultList.size() + ", oldResult.size=" + oldResultList.size()); // update Iterator<InfraCheckResult> oldItr = oldResultList.iterator(); while (oldItr.hasNext()) { InfraCheckResult oldResult = oldItr.next(); Iterator<ModuleNodeResult> newItr = newResultList.iterator(); while (newItr.hasNext()) { ModuleNodeResult newResult = newItr.next(); if (oldResult.getId().getManagementId().equals(managementId) && oldResult.getId().getModuleId().equals(moduleId) && oldResult.getId().getNodeId().equals(newResult.getFacilityId())) { oldResult.setResult(newResult.getResult()); newItr.remove(); oldItr.remove(); break; } } } m_log.info("newResult.size=" + newResultList.size() + ", oldResult.size=" + oldResultList.size()); // insert for (ModuleNodeResult newResult : newResultList) { InfraCheckResult resultEntity = new InfraCheckResult(managementId, moduleId, newResult.getFacilityId()); HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); em.persist(resultEntity); resultEntity.setResult(newResult.getResult()); } // delete for (InfraCheckResult oldResult : oldResultList) { oldResult.removeSelf(); } m_log.debug("update() : end"); }