List of usage examples for java.util Iterator remove
default void remove()
From source file:net.femtoparsec.jnlmin.utils.PropertySetter.java
private static void cleanCache() { Iterator<Map.Entry<Class<?>, Reference<PropertySetter>>> iterator = CACHE.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Class<?>, Reference<PropertySetter>> entry = iterator.next(); if (entry.getValue().get() == null) { iterator.remove(); }/* w w w . ja va 2 s .c o m*/ } }
From source file:com.sixt.service.framework.protobuf.ProtobufUtil.java
private static void cleanJsonArray(JsonArray array) { Iterator<JsonElement> iter = array.iterator(); while (iter.hasNext()) { JsonElement ele = iter.next();/*from www . ja v a2s . c o m*/ if (ele.isJsonNull()) { iter.remove(); continue; } else { cleanJsonElement(ele); } } }
From source file:com.hihframework.core.utils.CollectionUtils.java
/** * ?ID?,???.//from w w w .ja v a2 s . c o m * http?????idhibernate??????? * ? * ???ID?,ID?ID??. * * @param collection * ?? * @param checkedIds * ? * @param idName * ID?? * @param clazz * ? */ public static <T, ID> void mergeByCheckedIds(Collection<T> collection, Collection<ID> checkedIds, String idName, Class<T> clazz) throws Exception { if (checkedIds == null) { collection.clear(); return; } Iterator<T> it = collection.iterator(); while (it.hasNext()) { T obj = it.next(); if (checkedIds.contains(PropertyUtils.getProperty(obj, idName))) { checkedIds.remove(PropertyUtils.getProperty(obj, idName)); } else { it.remove(); } } for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); collection.add(obj); } }
From source file:net.sourceforge.fenixedu.util.InquiriesUtil.java
/** * @return Returns the list containing with only the first occurrence of the * elementes based on the equals method the result list is ordered * by the externalId//from w ww. j a va 2s .c o m */ public static void removeDuplicates(final List beanList) { if (beanList.isEmpty()) { return; } Collections.sort(beanList, new BeanComparator("externalId")); final Iterator iter = beanList.iterator(); InfoObject prev = (InfoObject) iter.next(); while (iter.hasNext()) { final InfoObject curr = (InfoObject) iter.next(); if (curr.equals(prev)) { iter.remove(); } prev = curr; } }
From source file:com.app.util.SearchResultUtil.java
private static void _removePreviouslyNotifiedResults(int searchQueryId, List<SearchResult> newSearchResults) throws DatabaseConnectionException, SQLException { List<String> searchQueryPreviousResults = SearchQueryPreviousResultUtil .getSearchQueryPreviousResults(searchQueryId); if (!searchQueryPreviousResults.isEmpty()) { Iterator iterator = newSearchResults.iterator(); while (iterator.hasNext()) { SearchResult searchResult = (SearchResult) iterator.next(); if (searchQueryPreviousResults.contains(searchResult.getItemId())) { iterator.remove(); }// ww w . j ava 2s.c o m } } }
From source file:com.meetme.plugins.jira.gerrit.webpanel.GerritReviewsIssueLeftPanel.java
private static int removeClosedReviews(List<GerritChange> changes) { Iterator<GerritChange> it = changes.iterator(); int c = 0;// w ww. j a v a2 s .co m while (it.hasNext()) { GerritChange change = it.next(); if (!change.isOpen()) { it.remove(); c += 1; } } return c; }
From source file:Main.java
private static ArrayList<ArrayList> sortObjectArrayListSimpleMaster(ArrayList listIn, String paramName) { ArrayList<ArrayList> answer = new ArrayList<ArrayList>(); ArrayList newList = new ArrayList(); ArrayList<Integer> indices = new ArrayList<Integer>(); try {/* w ww . j a va 2 s. co m*/ if (listIn.size() > 0) { Class<?> c = listIn.get(0).getClass(); Field f = c.getDeclaredField(paramName); f.setAccessible(true); Class<?> t = f.getType(); Double dd = new Double(14); Float ff = new Float(14); Integer ii = new Integer(14); Map sortedPos = new LinkedHashMap(); Map sortedNeg = new LinkedHashMap(); Map unsorted = new LinkedHashMap(); int indexCount = 0; long count = 0; if (t.isPrimitive()) { for (Object thisObj : listIn) { Object o = f.get(thisObj); double d = 0; if (t.getName().equals("char")) { d = (int) ((Character) o); } else if (t.isInstance(dd)) d = (Double) o; else if (t.isInstance(ff)) d = (Float) o; else if (t.isInstance(ii)) d = (Integer) o; else d = new Double(o.toString()); boolean isNegative = false; if (d < 0) { isNegative = true; d = Math.abs(d); } String format = "%1$30f"; String newKey = String.format(format, d); String format2 = "%1$20d"; String countString = String.format(format2, count); newKey += "-" + countString; if (isNegative) { sortedNeg.put(newKey, thisObj); } else { sortedPos.put(newKey, thisObj); } unsorted.put(thisObj, indexCount); count++; indexCount++; } TreeMap<String, Object> resultPos = new TreeMap(); resultPos.putAll(sortedPos); sortedPos = resultPos; TreeMap<String, Object> resultNeg = new TreeMap(); resultNeg.putAll(sortedNeg); sortedNeg = resultNeg; } else if (t.isInstance(paramName)) { // System.out.println("is a string with value " + o); for (Object thisObj : listIn) { String key = (String) (f.get(thisObj)); sortedPos.put(key + "-" + count, thisObj); unsorted.put(thisObj, indexCount); count++; indexCount++; } TreeMap<String, Object> result = new TreeMap(String.CASE_INSENSITIVE_ORDER); result.putAll(sortedPos); sortedPos = result; } Iterator itNeg = sortedNeg.entrySet().iterator(); while (itNeg.hasNext()) { Map.Entry pairs = (Map.Entry) itNeg.next(); newList.add(pairs.getValue()); itNeg.remove(); } Collections.reverse(newList); Iterator itPos = sortedPos.entrySet().iterator(); while (itPos.hasNext()) { Map.Entry pairs = (Map.Entry) itPos.next(); Object obj = pairs.getValue(); newList.add(obj); indices.add((Integer) unsorted.get(obj)); itPos.remove(); } } } catch (Exception e) { System.out .println("problem sorting list. listIn.size(): " + listIn.size() + " and param: " + paramName); answer.add(newList); answer.add(indices); return answer; } answer.add(newList); answer.add(indices); return answer; }
From source file:com.github.lynxdb.server.core.TimeSerie.java
public static TimeSerie merge(List<TimeSerie> _series) { Assert.notEmpty(_series);/* w w w. j a va2 s . c om*/ List<SuperIterator> sil = new ArrayList<>(); _series.forEach((TimeSerie t) -> { if (t.hasNext()) { SuperIterator<Entry> si = new SuperIterator<>(t); si.next(); sil.add(si); } }); Map<String, String> tags = new HashMap<>(); tags.putAll(_series.get(0).getTags()); _series.forEach((TimeSerie t) -> { Iterator<Map.Entry<String, String>> i = tags.entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, String> e = i.next(); if (!t.getTags().containsKey(e.getKey()) || !t.getTags().get(e.getKey()).equals(e.getValue())) { i.remove(); } } }); return new TimeSerie(_series.get(0).getName(), tags, new ChainableIterator<Entry>() { @Override public boolean hasNext() { return sil.stream() .anyMatch((superIterator) -> superIterator.hasNext() || superIterator.getCurrent() != null); } @Override public Entry next() { Iterator<SuperIterator> rr = sil.iterator(); while (rr.hasNext()) { if (rr.next().getCurrent() == null) { rr.remove(); } } long max = Long.MIN_VALUE; for (SuperIterator<Entry> r : sil) { max = Long.max(max, r.getCurrent().getTime()); } for (SuperIterator<Entry> r : sil) { if (r.getCurrent().getTime() == max) { r.next(); return r.getPrevious(); } } throw new IllegalStateException("something went wrong"); } }); }
From source file:com.xyz.util.WebDataUtil.java
/** * ?ID?,???./*from w w w . ja v a2s . c o m*/ * * ??????id,??????id?????. * ???id?ID?,?ID?id??. * * @param srcObjects ?? * @param checkedIds ID? * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //ID?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,ID???id,ID?id???ID. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertToUncheckedException(e); } }
From source file:com.thinkmore.framework.orm.hibernate.HibernateWebUtils.java
/** * ?ID?,???.//from w ww. j a v a 2 s . com * * ??????id,??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); 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(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertReflectionExceptionToUnchecked(e); } }