List of usage examples for java.util ListIterator remove
void remove();
From source file:org.easyrec.service.web.nodomain.impl.ShopRecommenderServiceImpl.java
@SuppressWarnings({ "unchecked" }) @IOLog// w ww . j a va 2 s . c o m @Profiled @Override public List<Item> mostRatedItems(Integer tenantId, String itemType, Integer cluster, Integer numberOfResults, Integer offset, String timeRange, TimeConstraintVO constraint, Session session) { List<Item> items; offset = CollectionUtils.getSafeOffset(offset); RemoteTenant remoteTenant = remoteTenantDAO.get(tenantId); if (logger.isDebugEnabled()) { logger.debug("<MOST_RATED@" + remoteTenant.getStringId() + "> " + " requesting most rated Items"); } if (timeRange == null) { timeRange = "ALL"; } // default timeRange String cacheKey = tenantId + WS.ACTION_MOST_RATED + itemType + cluster + timeRange; Element e = cache.get(cacheKey); if ((e != null) && (!e.isExpired())) { items = itemService.filterDeactivatedItems((List<Item>) e.getValue()); return CollectionUtils.getSafeSubList(items, offset, numberOfResults); } if (constraint == null) constraint = new TimeConstraintVO(); adjustConstraint(constraint, TimeRange.getEnumFromString(timeRange)); Monitor monCore = MonitorFactory.start(JAMON_REST_MOST_RATED_CORE); List<RankedItemVO<Integer, String>> rankedItems = domainActionService.mostRatedItems(tenantId, itemType, cluster, WS.MAX_NUMBER_OF_RANKING_RESULTS, constraint, Boolean.TRUE); // filter invisible items Set<String> invisibleItemTypes = typeMappingService.getItemTypes(tenantId, false); if (invisibleItemTypes.size() > 0) { ListIterator<RankedItemVO<Integer, String>> iterator = rankedItems.listIterator(); while (iterator.hasNext()) { RankedItemVO<Integer, String> rankedItemVO = iterator.next(); if (invisibleItemTypes.contains(rankedItemVO.getItem().getType())) iterator.remove(); } } monCore.stop(); items = idMappingService.mapRankedItems(rankedItems, remoteTenant, session, WS.MAX_NUMBER_OF_RANKING_RESULTS, 0); cache.put(new Element(cacheKey, items)); return CollectionUtils.getSafeSubList(items, offset, numberOfResults); }
From source file:org.easyrec.service.web.nodomain.impl.ShopRecommenderServiceImpl.java
@SuppressWarnings({ "unchecked" }) @IOLog//from w w w . java 2 s.co m @Profiled @Override public List<Item> mostViewedItems(Integer tenantId, String itemType, Integer cluster, Integer numberOfResults, Integer offset, String timeRange, TimeConstraintVO constraint, Session session) { List<Item> items; offset = CollectionUtils.getSafeOffset(offset); RemoteTenant remoteTenant = remoteTenantDAO.get(tenantId); if (logger.isDebugEnabled()) { logger.debug("<MOST_VIEWED@" + remoteTenant.getStringId() + "> " + " requesting most viewed Items"); } if (timeRange == null) { timeRange = "ALL"; } // default timeRange String cacheKey = tenantId + WS.ACTION_MOST_VIEWED + itemType + cluster + timeRange; Element e = cache.get(cacheKey); if ((e != null) && (!e.isExpired())) { logger.debug("most viewed - cache hit"); items = itemService.filterDeactivatedItems((List<Item>) e.getValue()); return CollectionUtils.getSafeSubList(items, offset, numberOfResults); } if (constraint == null) constraint = new TimeConstraintVO(); adjustConstraint(constraint, TimeRange.getEnumFromString(timeRange)); logger.debug("most viewed - cache miss - fetching new data from db"); Monitor monCore = MonitorFactory.start(JAMON_REST_MOST_VIEWED_CORE); List<RankedItemVO<Integer, String>> rankedItems = domainActionService.mostViewedItems(tenantId, itemType, cluster, WS.MAX_NUMBER_OF_RANKING_RESULTS, constraint, Boolean.TRUE); // filter invisible items Set<String> invisibleItemTypes = typeMappingService.getItemTypes(tenantId, false); if (invisibleItemTypes.size() > 0) { ListIterator<RankedItemVO<Integer, String>> iterator = rankedItems.listIterator(); while (iterator.hasNext()) { RankedItemVO<Integer, String> rankedItemVO = iterator.next(); if (invisibleItemTypes.contains(rankedItemVO.getItem().getType())) iterator.remove(); } } monCore.stop(); items = idMappingService.mapRankedItems(rankedItems, remoteTenant, session, WS.MAX_NUMBER_OF_RANKING_RESULTS, 0); cache.put(new Element(cacheKey, items)); return CollectionUtils.getSafeSubList(items, offset, numberOfResults); }
From source file:org.commonjava.maven.ext.core.impl.RESTCollector.java
/** * Prescans the Project to build up a list of Project GAs and also the various Dependencies. *///from w w w. ja v a 2 s .c om private void collect(final List<Project> projects) throws ManipulationException { final RESTState state = session.getState(RESTState.class); final VersioningState vs = session.getState(VersioningState.class); final DependencyState ds = session.getState(DependencyState.class); final PluginState ps = session.getState(PluginState.class); if (!session.isEnabled() || !state.isEnabled()) { logger.debug(getClass().getSimpleName() + ": Nothing to do!"); return; } final ArrayList<ProjectVersionRef> restParam = new ArrayList<>(); final ArrayList<ProjectVersionRef> newProjectKeys = new ArrayList<>(); final String override = vs.getOverride(); for (final Project project : projects) { if (isEmpty(override)) { // TODO: Check this : For the rest API I think we need to check every project GA not just inheritance root. // Strip SNAPSHOT from the version for matching. DA will handle OSGi conversion. ProjectVersionRef newKey = new SimpleProjectVersionRef(project.getKey()); if (project.getVersion().endsWith("-SNAPSHOT")) { if (!vs.preserveSnapshot()) { newKey = new SimpleProjectVersionRef(project.getKey().asProjectRef(), project.getVersion().substring(0, project.getVersion().indexOf("-SNAPSHOT"))); } else { logger.warn("SNAPSHOT detected for REST call but preserve-snapshots is enabled."); } } newProjectKeys.add(newKey); } else if (project.isExecutionRoot()) { // We want to manually override the version ; therefore ignore what is in the project and calculate potential // matches for that instead. Project p = projects.get(0); newProjectKeys.add(new SimpleProjectVersionRef(p.getGroupId(), p.getArtifactId(), override)); } } restParam.addAll(newProjectKeys); // If the dependencyState getRemoteBOMDepMgmt contains suffix then send that to process as well. // We only recognise dependencyManagement of the form g:a:version-rebuild not g:a:version-rebuild-<numeric>. for (ProjectVersionRef bom : (ds.getRemoteBOMDepMgmt() == null ? Collections.<ProjectVersionRef>emptyList() : ds.getRemoteBOMDepMgmt())) { if (!Version.hasBuildNumber(bom.getVersionString()) && bom.getVersionString().contains(PropertiesUtils.getSuffix(session))) { // Create the dummy PVR to send to DA (which requires a numeric suffix). ProjectVersionRef newBom = new SimpleProjectVersionRef(bom.asProjectRef(), bom.getVersionString() + "-0"); logger.debug("Adding dependencyManagement BOM {} into REST call.", newBom); restParam.add(newBom); } } Set<ArtifactRef> localDeps = establishAllDependencies(session, projects, null); // Ok we now have a defined list of top level project plus a unique list of all possible dependencies. // Need to send that to the rest interface to get a translation. for (ArtifactRef p : localDeps) { restParam.add(p.asProjectVersionRef()); } // Call the REST to populate the result. logger.debug("Passing {} GAVs following into the REST client api {} ", restParam.size(), restParam); logger.info("Calling REST client..."); long start = System.nanoTime(); Map<ProjectVersionRef, String> restResult = null; try { restResult = state.getVersionTranslator().translateVersions(restParam); } finally { printFinishTime(start, (restResult != null)); } logger.debug("REST Client returned {} ", restResult); // Process rest result for boms ListIterator<ProjectVersionRef> iterator = (ds.getRemoteBOMDepMgmt() == null ? Collections.<ProjectVersionRef>emptyList().listIterator() : ds.getRemoteBOMDepMgmt().listIterator()); while (iterator.hasNext()) { ProjectVersionRef pvr = iterator.next(); // As before, only process the BOMs if they are of the format <rebuild suffix> without a numeric portion. if (!Version.hasBuildNumber(pvr.getVersionString()) && pvr.getVersionString().contains(PropertiesUtils.getSuffix(session))) { // Create the dummy PVR to compare with results to... ProjectVersionRef newBom = new SimpleProjectVersionRef(pvr.asProjectRef(), pvr.getVersionString() + "-0"); if (restResult.keySet().contains(newBom)) { ProjectVersionRef replacementBOM = new SimpleProjectVersionRef(pvr.asProjectRef(), restResult.get(newBom)); logger.debug("Replacing BOM value of {} with {}.", pvr, replacementBOM); iterator.remove(); iterator.add(replacementBOM); } } } vs.setRESTMetadata(parseVersions(session, projects, state, newProjectKeys, restResult)); final Map<ArtifactRef, String> overrides = new HashMap<>(); // Convert the loaded remote ProjectVersionRefs to the original ArtifactRefs for (ArtifactRef a : localDeps) { if (restResult.containsKey(a.asProjectVersionRef())) { overrides.put(a, restResult.get(a.asProjectVersionRef())); } } logger.debug("Setting REST Overrides {} ", overrides); ds.setRemoteRESTOverrides(overrides); // Unfortunately as everything is just GAVs we have to send everything to the PluginManipulator as well. ps.setRemoteRESTOverrides(overrides); }
From source file:com.android.talkback.SpeechController.java
private void speak(FeedbackItem item, int queueMode, UtteranceCompleteRunnable completedAction) { // If this FeedbackItem is flagged as NO_SPEECH, ignore speech and // immediately process earcons and haptics without disrupting the speech // queue./*www .ja va2 s . c o m*/ // TODO: Consider refactoring non-speech feedback out of // this class entirely. if (item.hasFlag(FeedbackItem.FLAG_NO_SPEECH)) { for (FeedbackFragment fragment : item.getFragments()) { playEarconsFromFragment(fragment); playHapticsFromFragment(fragment); } return; } if (item.hasFlag(FeedbackItem.FLAG_SKIP_DUPLICATE) && hasItemOnQueueOrSpeaking(item)) { return; } item.setUninterruptible(queueMode == QUEUE_MODE_UNINTERRUPTIBLE); item.setCompletedAction(completedAction); boolean currentFeedbackInterrupted = false; if (shouldClearQueue(item, queueMode)) { FeedbackItemFilter filter = getFeedbackItemFilter(item, queueMode); // Call onUtteranceComplete on each queue item to be cleared. ListIterator<FeedbackItem> iterator = mFeedbackQueue.listIterator(0); while (iterator.hasNext()) { FeedbackItem currentItem = iterator.next(); if (filter.accept(currentItem)) { iterator.remove(); notifyItemInterrupted(currentItem); } } if (mCurrentFeedbackItem != null && filter.accept(mCurrentFeedbackItem)) { notifyItemInterrupted(mCurrentFeedbackItem); currentFeedbackInterrupted = true; } } mFeedbackQueue.add(item); if (mSpeechListener != null) { mSpeechListener.onUtteranceQueued(item); } // If TTS isn't ready, this should be the only item in the queue. if (!mFailoverTts.isReady()) { LogUtils.log(this, Log.ERROR, "Attempted to speak before TTS was initialized."); return; } if ((mCurrentFeedbackItem == null) || currentFeedbackInterrupted) { mCurrentFragmentIterator = null; speakNextItem(); } else { LogUtils.log(this, Log.VERBOSE, "Queued speech item, waiting for \"%s\"", mCurrentFeedbackItem.getUtteranceId()); } }
From source file:org.apache.usergrid.mq.Query.java
public void removeFiltersForProperty(String name) { if (name == null) { return;/*from ww w . ja v a 2s . c o m*/ } ListIterator<FilterPredicate> iterator = filterPredicates.listIterator(); while (iterator.hasNext()) { FilterPredicate f = iterator.next(); if (f.propertyName.equalsIgnoreCase(name)) { iterator.remove(); } } }
From source file:org.etudes.component.app.melete.MeleteCHServiceImpl.java
public List getListFromCollection(String collId, String mimeType) { try {/* ww w .j a v a 2 s . c o m*/ if (!isUserAuthor()) { logger.info("User is not authorized to access meleteDocs collection"); } // setup a security advisor meleteSecurityService.pushAdvisor(); ContentCollection c = getContentservice().getCollection(collId); List mem = c.getMemberResources(); if (mem == null) return null; ListIterator memIt = mem.listIterator(); while (memIt != null && memIt.hasNext()) { ContentEntity ce = (ContentEntity) memIt.next(); if (ce.isResource()) { String contentextension = ((ContentResource) ce).getContentType(); if (!contentextension.equals(mimeType)) memIt.remove(); } else { memIt.remove(); } } return mem; } catch (Exception e) { logger.error(e.toString()); } finally { // clear the security advisor meleteSecurityService.popAdvisor(); } return null; }
From source file:org.etudes.component.app.melete.MeleteCHServiceImpl.java
public List getListofLinksFromCollection(String collId) { try {//ww w. ja v a 2s. c o m if (!isUserAuthor()) { logger.info("User is not authorized to access meleteDocs collection"); return null; } // setup a security advisor meleteSecurityService.pushAdvisor(); ContentCollection c = getContentservice().getCollection(collId); List mem = c.getMemberResources(); if (mem == null) return null; ListIterator memIt = mem.listIterator(); while (memIt != null && memIt.hasNext()) { ContentEntity ce = (ContentEntity) memIt.next(); if (ce.isResource()) { String contentextension = ((ContentResource) ce).getContentType(); if (!contentextension.equals(MIME_TYPE_LINK)) memIt.remove(); } else memIt.remove(); } return mem; } catch (Exception e) { logger.error(e.toString()); } finally { // clear the security advisor meleteSecurityService.popAdvisor(); } return null; }
From source file:org.kuali.kfs.module.bc.document.service.impl.BudgetDocumentServiceImpl.java
/** * Reloads benefits target accounting lines. Usually called right after an annual benefits calculation and the display needs * updated with a fresh copy from the database. All old row versions are removed and database row versions are inserted in the * list in the correct order.// w ww . ja v a 2 s. com * * @param bcDoc */ @Transactional protected void reloadBenefitsLines(BudgetConstructionDocument bcDoc) { // get list of potential fringe objects to use as an in query param Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, bcDoc.getUniversityFiscalYear()); fieldValues.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, bcDoc.getChartOfAccountsCode()); List<LaborLedgerBenefitsCalculation> benefitsCalculation = kualiModuleService .getResponsibleModuleService(LaborLedgerBenefitsCalculation.class) .getExternalizableBusinessObjectsList(LaborLedgerBenefitsCalculation.class, fieldValues); List<String> fringeObjects = new ArrayList<String>(); for (LaborLedgerBenefitsCalculation element : benefitsCalculation) { fringeObjects.add(element.getPositionFringeBenefitObjectCode()); } List<PendingBudgetConstructionGeneralLedger> dbPBGLFringeLines = budgetConstructionDao .getDocumentPBGLFringeLines(bcDoc.getDocumentNumber(), fringeObjects); List<PendingBudgetConstructionGeneralLedger> docPBGLExpLines = bcDoc .getPendingBudgetConstructionGeneralLedgerExpenditureLines(); // holds the request sums of removed, added records and used to adjust the document expenditure request total KualiInteger docRequestTotals = KualiInteger.ZERO; KualiInteger dbRequestTotals = KualiInteger.ZERO; // remove the current set of fringe lines ListIterator docLines = docPBGLExpLines.listIterator(); while (docLines.hasNext()) { PendingBudgetConstructionGeneralLedger docLine = (PendingBudgetConstructionGeneralLedger) docLines .next(); if (fringeObjects.contains(docLine.getFinancialObjectCode())) { docRequestTotals = docRequestTotals.add(docLine.getAccountLineAnnualBalanceAmount()); docLines.remove(); } } // add the dbset of fringe lines, if any if (dbPBGLFringeLines != null && !dbPBGLFringeLines.isEmpty()) { if (docPBGLExpLines == null || docPBGLExpLines.isEmpty()) { docPBGLExpLines.addAll(dbPBGLFringeLines); } else { ListIterator dbLines = dbPBGLFringeLines.listIterator(); docLines = docPBGLExpLines.listIterator(); PendingBudgetConstructionGeneralLedger dbLine = (PendingBudgetConstructionGeneralLedger) dbLines .next(); PendingBudgetConstructionGeneralLedger docLine = (PendingBudgetConstructionGeneralLedger) docLines .next(); boolean dbDone = false; boolean docDone = false; while (!dbDone) { if (docDone || docLine.getFinancialObjectCode() .compareToIgnoreCase(dbLine.getFinancialObjectCode()) > 0) { if (!docDone) { docLine = (PendingBudgetConstructionGeneralLedger) docLines.previous(); } dbRequestTotals = dbRequestTotals.add(dbLine.getAccountLineAnnualBalanceAmount()); dbLine.setPersistedAccountLineAnnualBalanceAmount( dbLine.getAccountLineAnnualBalanceAmount()); this.populatePBGLLine(dbLine); docLines.add(dbLine); if (!docDone) { docLine = (PendingBudgetConstructionGeneralLedger) docLines.next(); } if (dbLines.hasNext()) { dbLine = (PendingBudgetConstructionGeneralLedger) dbLines.next(); } else { dbDone = true; } } else { if (docLines.hasNext()) { docLine = (PendingBudgetConstructionGeneralLedger) docLines.next(); } else { docDone = true; } } } } } // adjust the request total for the removed and added recs bcDoc.setExpenditureAccountLineAnnualBalanceAmountTotal( bcDoc.getExpenditureAccountLineAnnualBalanceAmountTotal() .add(dbRequestTotals.subtract(docRequestTotals))); }
From source file:org.etudes.component.app.melete.MeleteCHServiceImpl.java
public List getListofFilesFromCollection(String collId) { try {/*from w w w . j ava 2s .c o m*/ // setup a security advisor meleteSecurityService.pushAdvisor(); long starttime = System.currentTimeMillis(); logger.debug("time to get all collectionMap" + starttime); ContentCollection c = getContentservice().getCollection(collId); List mem = c.getMemberResources(); if (mem == null) return null; ListIterator memIt = mem.listIterator(); while (memIt != null && memIt.hasNext()) { ContentEntity ce = (ContentEntity) memIt.next(); if (ce.isResource()) { String contentextension = ((ContentResource) ce).getContentType(); if (contentextension.equals(MIME_TYPE_LINK) || contentextension.equals(MIME_TYPE_LTI)) { memIt.remove(); } } else memIt.remove(); } long endtime = System.currentTimeMillis(); logger.debug("end time to get all collectionMap" + (endtime - starttime)); return mem; } catch (Exception e) { logger.error(e.toString()); } finally { // clear the security advisor meleteSecurityService.popAdvisor(); } return null; }
From source file:org.apache.fop.layoutmgr.table.TableContentLayoutManager.java
/** * Creates Knuth elements by iterating over a TableRowIterator. * @param iter TableRowIterator instance to fetch rows from * @param context Active LayoutContext/*from w w w. j a va 2 s . co m*/ * @param alignment alignment indicator * @param bodyType Indicates what kind of body is being processed * (BODY, HEADER or FOOTER) * @return An element list */ private LinkedList getKnuthElementsForRowIterator(TableRowIterator iter, LayoutContext context, int alignment, int bodyType) { LinkedList returnList = new LinkedList(); EffRow[] rowGroup = iter.getNextRowGroup(); // TODO homogenize the handling of keeps and breaks context.clearKeepsPending(); context.setBreakBefore(Constants.EN_AUTO); context.setBreakAfter(Constants.EN_AUTO); Keep keepWithPrevious = Keep.KEEP_AUTO; int breakBefore = Constants.EN_AUTO; if (rowGroup != null) { RowGroupLayoutManager rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup, stepper); List nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType); keepWithPrevious = keepWithPrevious.compare(context.getKeepWithPreviousPending()); breakBefore = context.getBreakBefore(); int breakBetween = context.getBreakAfter(); returnList.addAll(nextRowGroupElems); while ((rowGroup = iter.getNextRowGroup()) != null) { rowGroupLM = new RowGroupLayoutManager(getTableLM(), rowGroup, stepper); //Note previous pending keep-with-next and clear the strength //(as the layout context is reused) Keep keepWithNextPending = context.getKeepWithNextPending(); context.clearKeepWithNextPending(); //Get elements for next row group nextRowGroupElems = rowGroupLM.getNextKnuthElements(context, alignment, bodyType); /* * The last break element produced by TableStepper (for the previous row * group) may be used to represent the break between the two row groups. * Its penalty value and break class must just be overridden by the * characteristics of the keep or break between the two. * * However, we mustn't forget that if the after border of the last row of * the row group is thicker in the normal case than in the trailing case, * an additional glue will be appended to the element list. So we may have * to go two steps backwards in the list. */ //Determine keep constraints Keep keep = keepWithNextPending.compare(context.getKeepWithPreviousPending()); context.clearKeepWithPreviousPending(); keep = keep.compare(getTableLM().getKeepTogether()); int penaltyValue = keep.getPenalty(); int breakClass = keep.getContext(); breakBetween = BreakUtil.compareBreakClasses(breakBetween, context.getBreakBefore()); if (breakBetween != Constants.EN_AUTO) { penaltyValue = -KnuthElement.INFINITE; breakClass = breakBetween; } BreakElement breakElement; ListIterator elemIter = returnList.listIterator(returnList.size()); ListElement elem = (ListElement) elemIter.previous(); if (elem instanceof KnuthGlue) { breakElement = (BreakElement) elemIter.previous(); } else { breakElement = (BreakElement) elem; } breakElement.setPenaltyValue(penaltyValue); breakElement.setBreakClass(breakClass); returnList.addAll(nextRowGroupElems); breakBetween = context.getBreakAfter(); } } /* * The last break produced for the last row-group of this table part must be * removed, because the breaking after the table will be handled by TableLM. * Unless the element list ends with a glue, which must be kept to accurately * represent the content. In such a case the break is simply disabled by setting * its penalty to infinite. */ ListIterator elemIter = returnList.listIterator(returnList.size()); ListElement elem = (ListElement) elemIter.previous(); if (elem instanceof KnuthGlue) { BreakElement breakElement = (BreakElement) elemIter.previous(); breakElement.setPenaltyValue(KnuthElement.INFINITE); } else { elemIter.remove(); } context.updateKeepWithPreviousPending(keepWithPrevious); context.setBreakBefore(breakBefore); //fox:widow-content-limit int widowContentLimit = getTableLM().getTable().getWidowContentLimit().getValue(); if (widowContentLimit != 0 && bodyType == TableRowIterator.BODY) { ElementListUtils.removeLegalBreaks(returnList, widowContentLimit); } //fox:orphan-content-limit int orphanContentLimit = getTableLM().getTable().getOrphanContentLimit().getValue(); if (orphanContentLimit != 0 && bodyType == TableRowIterator.BODY) { ElementListUtils.removeLegalBreaksFromEnd(returnList, orphanContentLimit); } return returnList; }