List of usage examples for java.util Iterator remove
default void remove()
From source file:fll.TournamentTeam.java
/** * Filter the specified list to just the teams in the specified event * division.//from www . j av a 2s . co m * * @param teams list that is modified * @param divisionStr the division to keep * @throws RuntimeException * @throws SQLException */ public static void filterTeamsToEventDivision(final List<TournamentTeam> teams, final String divisionStr) throws SQLException, RuntimeException { final Iterator<TournamentTeam> iter = teams.iterator(); while (iter.hasNext()) { final TournamentTeam t = iter.next(); final String eventDivision = t.getEventDivision(); if (!eventDivision.equals(divisionStr)) { iter.remove(); } } }
From source file:edu.uci.ics.hyracks.control.cc.partitions.PartitionMatchMaker.java
private static <T> void removeEntries(List<T> list, IEntryFilter<T> filter) { Iterator<T> j = list.iterator(); while (j.hasNext()) { T o = j.next();// w w w .jav a 2 s . c o m if (filter.matches(o)) { j.remove(); } } }
From source file:se.uu.it.cs.recsys.ruleminer.datastructure.builder.FPTreeHeaderTableBuilder.java
/** * * @param idAndCount item id and count/*from www . jav a2 s. c om*/ * @param threshold, min support * @return non-null HeaderTableItem if the input contains id meets threshold * requirement; otherwise null. */ public static List<HeaderTableItem> build(Map<Integer, Integer> idAndCount, Integer threshold) { List<HeaderTableItem> instance = new ArrayList<>(); Map<Integer, Integer> filteredIdAndCount = Util.filter(idAndCount, threshold); if (filteredIdAndCount.isEmpty()) { LOGGER.debug("Empty map after filtering. Empty list will be returned. Source: {}", idAndCount); return instance; } List<Integer> countList = new ArrayList<>(filteredIdAndCount.values()); Collections.sort(countList); Collections.reverse(countList);// now the count is in DESC order for (int i = 1; i <= filteredIdAndCount.size(); i++) { instance.add(new HeaderTableItem()); // in order to call list.set(idx,elem) } Map<Integer, Set<Integer>> forIdsHavingSameCount = new HashMap<>();//different ids may have same count filteredIdAndCount.entrySet().forEach((entry) -> { Integer courseId = entry.getKey(); Integer count = entry.getValue(); Integer countFrequence = Collections.frequency(countList, count); if (countFrequence == 1) { Integer countIdx = countList.indexOf(count); instance.set(countIdx, new HeaderTableItem(new Item(courseId, count))); } else { // different ids have same count if (!forIdsHavingSameCount.containsKey(count)) { forIdsHavingSameCount.put(count, Util.findDuplicatesIndexes(countList, count)); } Iterator<Integer> itr = forIdsHavingSameCount.get(count).iterator(); Integer idx = itr.next(); itr.remove(); instance.set(idx, new HeaderTableItem(new Item(courseId, count))); } }); // LOGGER.debug("Final built header table: {}", // instance.stream() // .map(headerItem -> headerItem.getItem()).collect(Collectors.toList())); return instance; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step7bConvArgRankProducer.java
@SuppressWarnings("unchecked") public static void prepareData(String[] args) throws Exception { String inputDir = args[0];/*from w ww . j a v a 2 s .co m*/ File outputDir = new File(args[1]); if (!outputDir.exists()) { outputDir.mkdirs(); } List<File> files = IOHelper.listXmlFiles(new File(inputDir)); // take only the gold data for this task String prefix = "all_DescendingScoreArgumentPairListSorter"; Iterator<File> iterator = files.iterator(); while (iterator.hasNext()) { File file = iterator.next(); if (!file.getName().startsWith(prefix)) { iterator.remove(); } } int totalArgumentsCounter = 0; DescriptiveStatistics statsPerTopic = new DescriptiveStatistics(); for (File file : files) { List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream() .fromXML(file); String name = file.getName().replaceAll(prefix, "").replaceAll("\\.xml", ""); PrintWriter pw = new PrintWriter(new File(outputDir, name + ".csv"), "utf-8"); pw.println("#id\trank\targument"); Graph graph = buildGraphFromPairs(argumentPairs); Map<String, Argument> arguments = collectArguments(argumentPairs); int argumentsPerTopicCounter = arguments.size(); PageRank pageRank = new PageRank(); pageRank.setVerbose(true); pageRank.init(graph); for (Node node : graph) { String id = node.getId(); double rank = pageRank.getRank(node); System.out.println(id); Argument argument = arguments.get(id); String text = Step7aLearningDataProducer.multipleParagraphsToSingleLine(argument.getText()); pw.printf(Locale.ENGLISH, "%s\t%.5f\t%s%n", argument.getId(), rank, text); } totalArgumentsCounter += argumentsPerTopicCounter; statsPerTopic.addValue(argumentsPerTopicCounter); pw.close(); } System.out.println("Total gold arguments: " + totalArgumentsCounter); System.out.println(statsPerTopic); }
From source file:com.astamuse.asta4d.web.form.flow.base.BasicFormFlowTraitHelper.java
static final List<AnnotatedPropertyInfo> retrieveRenderTargetFieldList(Object form) { List<AnnotatedPropertyInfo> list = RenderingTargetFieldsMap.get(form.getClass().getName()); if (list == null) { list = new LinkedList<AnnotatedPropertyInfo>(AnnotatedPropertyUtil.retrieveProperties(form.getClass())); Iterator<AnnotatedPropertyInfo> it = list.iterator(); while (it.hasNext()) { // remove all the non form field properties if (it.next().getAnnotation(FormField.class) == null) { it.remove(); }//from w w w. j a va2 s. c o m } RenderingTargetFieldsMap.put(form.getClass().getName(), list); } return list; }
From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java
public static Map<String, UUID> call(List<String> names) { names = new ArrayList<String>(names); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String playerName = iterator.next(); if (fetchedUUIDs.containsKey(playerName)) { iterator.remove(); }/* w ww . j a va2 s . c om*/ } if (names.size() == 0) { return readonlyFetchedUUIDs; } int count = names.size(); DebugLogger.info("get UUIDs for " + names.size() + " player(s)"); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); try { for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); count -= array.size(); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); fetchedUUIDs.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (count > 0) { MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost."); } return readonlyFetchedUUIDs; }
From source file:com.github.pmerienne.cf.testing.dataset.DatasetUtils.java
public static List<Rating> extractEval(List<Rating> ratings, double trainingPercent) { int evalSize = (int) (ratings.size() * (1.0 - trainingPercent)); List<Rating> eval = new ArrayList<>(evalSize); Set<Long> knownUsers = new HashSet<>(); Set<Long> knownItems = new HashSet<>(); Iterator<Rating> it = ratings.iterator(); while (it.hasNext() && eval.size() < evalSize) { Rating rating = it.next();/*from w w w .j a v a 2 s . c o m*/ if (knownUsers.contains(rating.i) && knownItems.contains(rating.j)) { eval.add(rating); it.remove(); } knownUsers.add(rating.i); knownItems.add(rating.j); } return eval; }
From source file:com.gm.bamboo.util.HibernateUtils.java
/** * ?ID?, ???./*from w w w . jav a 2 s. c om*/ * * ??????id,Hibernate??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update??. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ?,IdEntity? */ public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<Long> checkedIds, final Class<T> clazz) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.notNull(clazz, "clazz?"); //?, ???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?. //?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Long id = element.getId(); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (Long id : checkedIds) { T element = clazz.newInstance(); element.setId(id); srcObjects.add(element); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:com.gm.wine.util.HibernateUtils.java
/** * ?ID?, ???./*from w w w. j a v a 2 s . c o m*/ * * ??????id,Hibernate??????id?????. * ???id??,??id??. ?ID, * ??cascade-save-or-update??. * * @param srcObjects * ??,. * @param checkedIds * ?,ID. * @param clazz * ?,IdEntity? */ public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<Long> checkedIds, final Class<T> clazz) { // ? Assert.notNull(srcObjects, "scrObjects?"); Assert.notNull(clazz, "clazz?"); // ?, ???. if (checkedIds == null) { srcObjects.clear(); return; } // ????,id?ID?. // ?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Long id = element.getId(); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } // ID??id????,,id??. for (Long id : checkedIds) { T element = clazz.newInstance(); element.setId(id); srcObjects.add(element); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:com.ning.hfind.primary.ExpressionFactory.java
public static Iterator<Option> sanitizeCommandLine(Option[] options) { ArrayList<Option> optionsList = new ArrayList<Option>(Arrays.asList(options)); Iterator<Option> optionIterator = (Iterator<Option>) optionsList.iterator(); while (optionIterator.hasNext()) { Option option = optionIterator.next(); try {/* w w w .j ava 2 s . c o m*/ if (PrimaryFactory.primaryFromOption(option) == null) { optionIterator.remove(); } } catch (MalformedPatternException ignored) { } catch (IllegalArgumentException ignored) { } } return optionsList.iterator(); }