List of usage examples for java.util LinkedList listIterator
ListIterator<E> listIterator();
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareADMLuceneSearcherImpl.java
public List<Pair<String, Integer>> getTopTerms(String field, int count) { RepositoryAwareClosingIndexSearcher searcher = null; try {// w w w. j av a2 s. c o m LinkedList<Pair<String, Integer>> answer = new LinkedList<Pair<String, Integer>>(); searcher = getSearcher(indexer); IndexReader reader = searcher.getIndexReader(); TermEnum terms = reader.terms(new Term(field, "")); do { Term term = terms.term(); if (term != null) { if (!term.field().equals(field)) { break; } int freq = terms.docFreq(); Pair<String, Integer> pair = new Pair<String, Integer>(term.text(), Integer.valueOf(freq)); if (answer.size() < count) { if (answer.size() == 0) { answer.add(pair); } else if (answer.get(answer.size() - 1).getSecond().compareTo(pair.getSecond()) >= 0) { answer.add(pair); } else { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it .hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } } } else if (answer.get(count - 1).getSecond().compareTo(pair.getSecond()) < 0) { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it.hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } answer.removeLast(); } else { // off the end } } } while (terms.next()); terms.close(); return answer; } catch (IOException e) { throw new SearcherException(e); } finally { if (searcher != null) { try { searcher.close(); } catch (IOException e) { throw new SearcherException(e); } } } }
From source file:com.sun.portal.rssportlet.SettingsHandler.java
/** * Initialize the <code>RssPortletBean</code>. * * This is called after the bean has been set into this handler. */// w ww. j av a2 s. co m private void initSettingsBean() { PortletSession psession = getPortletRequest().getPortletSession(); //mandatory feeds mandate_feeds = (String[]) psession.getAttribute(MANDATE_FEEDS); //organizational feeds role_feeds = (String[]) psession.getAttribute(ROLE_FEEDS); if (role_feeds == null) { Map userInfo = (Map) portletRequest.getAttribute(PortletRequest.USER_INFO); String organizationalStatus = (String) userInfo.get("userRole"); String userRoleFeed = null; if ("Student".equalsIgnoreCase(organizationalStatus)) { userRoleFeed = STUDENT_FEEDS; } else if ("GradStudent".equalsIgnoreCase(organizationalStatus)) { userRoleFeed = GRAD_STUDENT_FEEDS; } else if ("Employee:Staff".equalsIgnoreCase(organizationalStatus)) { userRoleFeed = STAFF_FEEDS; } else if ("Employee:Faculty".equalsIgnoreCase(organizationalStatus)) { userRoleFeed = FACULTY_FEEDS; } else if ("Guest".equalsIgnoreCase(organizationalStatus)) { userRoleFeed = GUEST_FEEDS; } else { userRoleFeed = GUEST_FEEDS; } role_feeds = (String[]) psession.getAttribute(userRoleFeed); psession.setAttribute(ROLE_FEEDS, role_feeds); } //these are the feeds pushed at discrete time levels in the application //the level (horizon) of feeds that are pushed to the user and //seen by the user are tracked in user pref. attribute default_feeds_level default_feeds = (List) psession.getAttribute(DEFAULT_FEEDS); String[] sessionDefaultFeeds = null; if (null != default_feeds && default_feeds.size() != 0) { int default_feeds_level = 1; //every user gets some pushed feeds String feedLevel = (String) psession.getAttribute(SessionKeys.DEFAULT_FEEDS_LEVEL); if (null != feedLevel) { try { default_feeds_level = Integer.parseInt(feedLevel); } catch (NumberFormatException nfe) { default_feeds_level = 1; } } else { default_feeds_level = getIntPreference(PrefKeys.DEFAULT_FEEDS_LEVEL, 1); //stote in session and pref. psession.setAttribute(SessionKeys.DEFAULT_FEEDS_LEVEL, String.valueOf(default_feeds.size())); } sessionDefaultFeeds = (String[]) psession.getAttribute(SESSION_DEFAULT_FEEDS); if (null != sessionDefaultFeeds && sessionDefaultFeeds.length != 0) { sessionDefaultFeeds = new String[] {}; Iterator it = default_feeds.listIterator(); int counter = 1; int newDefaultFeeds = 0; while (it.hasNext()) { if (counter >= default_feeds_level) { String[] defaultFeeds = (String[]) it.next(); for (int i = 0; i < defaultFeeds.length; i++) { sessionDefaultFeeds[newDefaultFeeds] = defaultFeeds[i]; newDefaultFeeds++; } } counter++; } psession.setAttribute(SESSION_DEFAULT_FEEDS, sessionDefaultFeeds); } } //user selected feeds LinkedList feeds = new LinkedList( Arrays.asList(getPortletPreferences().getValues(PrefKeys.USER_FEEDS, new String[] {}))); feeds = stripDelimiter(feeds); //add mandatory+role feeds to feeds list if (null != role_feeds) { if (log.isDebugEnabled()) { log.debug("SetHandler feed role_feeds.length***********" + role_feeds.length); } for (int i = 0; i < role_feeds.length; i++) { feeds.add(i, role_feeds[i]); } } if (null != mandate_feeds) { if (log.isDebugEnabled()) { log.debug("SetHandler feed mandate_feeds.length***********" + mandate_feeds.length); } for (int i = 0; i < mandate_feeds.length; i++) { feeds.add(i, mandate_feeds[i]); } } if (null != sessionDefaultFeeds && sessionDefaultFeeds.length != 0) { if (log.isDebugEnabled()) { log.debug("SetHandler feed mandate_feeds.length***********" + sessionDefaultFeeds.length); } for (int i = 0; i < sessionDefaultFeeds.length; i++) { feeds.add(i, sessionDefaultFeeds[i]); } } if (log.isDebugEnabled()) { Iterator it = feeds.listIterator(); while (it.hasNext()) { log.debug("SettingsHandler feed LinkedList***********" + (String) it.next()); } } getSettingsBean().setFeeds(feeds); int maxAge = getIntPreference(PrefKeys.MAX_AGE, 72); getSettingsBean().setMaxAge(maxAge); int cacheTimeout = getIntPreference(PrefKeys.CACHE_TIMEOUT, 3600); getSettingsBean().setCacheTimeout(cacheTimeout); int maxDescriptionLength = getIntPreference(PrefKeys.MAX_DESCRIPTION_LENGTH, 512); getSettingsBean().setMaxDescriptionLength(maxDescriptionLength); boolean newWindow = getBooleanPreference(PrefKeys.NEWWIN, false); getSettingsBean().setNewWindow(newWindow); boolean disableMaxAge = getBooleanPreference(PrefKeys.DISABLE_MAX_AGE, false); getSettingsBean().setDisableMaxAge(disableMaxAge); int maxEntries = getIntPreference(PrefKeys.MAX_ENTRIES, 5); getSettingsBean().setMaxEntries(maxEntries); if (feeds != null && feeds.size() != 0) { String startFeed = getPortletPreferences().getValue(PrefKeys.START_FEED, (String) feeds.get(0)); System.out.println("SettingsHandler PrefKeys.START_FEED ***********" + startFeed); if (startFeed != null) { startFeed = stripDelimiter(startFeed); } getSettingsBean().setStartFeed(startFeed); } initSelectedFeed(); getSettingsBean().setLocale(getPortletRequest().getLocale()); //set feed titles if (feeds != null && feeds.size() != 0) { setFeedTitleList(feeds); } }
From source file:com.cablelabs.sim.PCSim2.java
/** * Sets the extensions and services that may have been overwritten within * a single test script for the test//from ww w . ja va 2 s. c o m * */ public void setExtensions(LinkedList<FSM> fsms) { ListIterator<FSM> iter = fsms.listIterator(); while (iter.hasNext()) { FSM fsm = iter.next(); NetworkElements nes = fsm.getNetworkElements(); ListIterator<String> extIter = nes.getDisableExtensions(); Extension e = Extension.DISABLED; while (extIter.hasNext()) { String ext = extIter.next(); if (ext != null) { if (ext.equals("gruu")) ss.setGRUUExtension(e); else if (ext.equals("precondition")) ss.setPreconditionExtension(e); else if (ext.equals("100rel")) ss.setReliabilityExtension(e); } } extIter = nes.getSupportedExtensions(); e = Extension.SUPPORTED; while (extIter.hasNext()) { String ext = extIter.next(); if (ext != null) { if (ext.equals("gruu")) ss.setGRUUExtension(e); else if (ext.equals("precondition")) ss.setPreconditionExtension(e); else if (ext.equals("100rel")) ss.setReliabilityExtension(e); } } extIter = nes.getRequireExtensions(); e = Extension.REQUIRED; while (extIter.hasNext()) { String ext = extIter.next(); if (ext != null) { if (ext.equals("gruu")) ss.setGRUUExtension(e); else if (ext.equals("precondition")) ss.setPreconditionExtension(e); else if (ext.equals("100rel")) ss.setReliabilityExtension(e); } } } }
From source file:com.cablelabs.sim.PCSim2.java
@Override public boolean startTests(LinkedList<File> dutFiles, LinkedList<File> testCaseFiles, boolean dutPrimary) { ListIterator<File> iter = dutFiles.listIterator(); while (iter.hasNext()) { dutConfigFiles.add(iter.next().getAbsolutePath()); }/*from w ww . j ava2 s . com*/ iter = testCaseFiles.listIterator(); while (iter.hasNext()) { testScriptFiles.add(iter.next().getAbsolutePath()); } this.dutPrimary = dutPrimary; return true; }
From source file:com.sun.portal.rssportlet.RssPortlet.java
private void processEditAction(ActionRequest request, ActionResponse response, AlertHandler alertHandler, Resources resources, SettingsBean readBean, SettingsBean writeBean) throws PortletModeException { String[] checkedFeeds = request.getParameterValues(INPUT_FEEDS); LinkedList feeds = null; if (checkedFeeds != null) { feeds = new LinkedList(Arrays.asList(checkedFeeds)); PortletSession psession = request.getPortletSession(); String[] mandate_feeds = (String[]) psession.getAttribute(MANDATE_FEEDS); String[] role_feeds = (String[]) psession.getAttribute(ROLE_FEEDS); //add role based feeds if (null != role_feeds) { for (int i = 0; i < role_feeds.length; i++) { feeds.add(i, role_feeds[i]); }//from w ww. ja v a 2s. co m } //add mandatory feeds if (null != mandate_feeds) { for (int i = 0; i < mandate_feeds.length; i++) { feeds.add(i, mandate_feeds[i]); } } String[] sessionDefaultFeeds = (String[]) psession.getAttribute(SettingsHandler.SESSION_DEFAULT_FEEDS); if (null != sessionDefaultFeeds && sessionDefaultFeeds.length != 0) { for (int i = 0; i < sessionDefaultFeeds.length; i++) { feeds.add(i, sessionDefaultFeeds[i]); } } } else if (request.getParameter(FormNames.WINDOW_CUSTOM) != null) { //mandataoy + role based feeds are already included feeds = readBean.getFeeds(); } else { //none of the feeds are checked PortletSession psession = request.getPortletSession(); String[] mandate_feeds = (String[]) psession.getAttribute(MANDATE_FEEDS); String[] role_feeds = (String[]) psession.getAttribute(ROLE_FEEDS); //add role based feeds feeds = new LinkedList(); if (null != role_feeds) { for (int i = 0; i < role_feeds.length; i++) { feeds.add(i, role_feeds[i]); } } //add mandatory feeds if (null != mandate_feeds) { for (int i = 0; i < mandate_feeds.length; i++) { feeds.add(i, mandate_feeds[i]); } } } if (log.isDebugEnabled()) { Iterator it = feeds.listIterator(); it = feeds.listIterator(); while (it.hasNext()) { log.debug("RssPortlet feeds ***********" + (String) it.next()); } } if (feeds == null) { // // no feeds // empty the feeds list // writeBean.setFeeds(new LinkedList()); } else { // // entries selected, reset feed list to // the selected entries. // writeBean.setFeeds(feeds); // // start feed // only set the start feed if the feeds list in non-null // (that's the only way we get here) // make sure the start feed is in the new feeds list // catch the case where the user deletes the start feed // String startFeed = request.getParameter(INPUT_START_FEED); if (log.isDebugEnabled()) { log.debug("RssPortlet INPUT_START_FEED***********" + startFeed); } if (startFeed != null && feeds.contains(startFeed)) { writeBean.setStartFeed(startFeed); } // // case where we delete the selected feed // set to the start feed // if (readBean.getSelectedFeed() != null && !feeds.contains(readBean.getSelectedFeed())) { String selectedFeed = writeBean.getStartFeed(); writeBean.setSelectedFeed(selectedFeed); } // // case where selected feed is null, because feed // list was previously null // set the selected feed to the start feed // if (readBean.getFeeds().size() == 0) { writeBean.setSelectedFeed(writeBean.getStartFeed()); } } //handle custom page- could be done in a separate method? if (request.getParameter(FormNames.WINDOW_CUSTOM) != null) { String s = request.getParameter(INPUT_MAX_AGE); if (s != null && s.length() > 0) { // // test to make sure it's an int // try { int n = Integer.parseInt(s); if (n < 1) { alertHandler.setError(resources.get("enter_a_whole_number_greater_than_zero")); } else { writeBean.setMaxAge(n); } } catch (NumberFormatException nfe) { alertHandler.setError(resources.get("enter_a_whole_number_greater_than_zero")); } } String maxEntries = request.getParameter(INPUT_MAX_ENTRIES); if (maxEntries != null && maxEntries.length() > 0) { // // test to make sure it's an int // try { int n = Integer.parseInt(maxEntries); if (n < 1) { alertHandler.setError(resources.get("enter_a_whole_number_greater_than_zero")); } else { writeBean.setMaxEntries(n); } } catch (NumberFormatException nfe) { alertHandler.setError(resources.get("enter_a_whole_number_greater_than_zero")); } } String[] disableMaxAge = request.getParameterValues(INPUT_DISABLE_MAX_AGE); if (disableMaxAge != null && disableMaxAge.length > 0) { writeBean.setDisableMaxAge(true); } else { writeBean.setDisableMaxAge(false); } String[] newWindow = request.getParameterValues(INPUT_NEWWIN); if (newWindow != null && newWindow.length > 0) { writeBean.setNewWindow(true); } else { writeBean.setNewWindow(false); } } if (!alertHandler.isErrorExists()) { // if there were no errors, then go back to // view mode response.setPortletMode(PortletMode.VIEW); } else { response.setRenderParameter(FormNames.SUBMIT_CUSTOM, FormNames.SUBMIT_CUSTOM); } }
From source file:nya.miku.wishmaster.cache.FileCache.java
private synchronized void trim() { for (int i = 0; i < 3; ++i) { if (maxSize == 0 || size <= maxSize) return; LinkedList<Pair<String, Long>> files = database.getFilesForTrim(size - maxSize); while (size > maxSize) { File oldest = null;/* ww w. j a v a 2s .c o m*/ for (ListIterator<Pair<String, Long>> it = files.listIterator(); it.hasNext();) { File file = pathToFile(it.next().getLeft()); if (isPageFile(file) && pagesSize < maxPagesSize) continue; it.remove(); oldest = file; break; } if (oldest == null) { Logger.e(TAG, "No files to trim"); break; } else { Logger.d(TAG, "Deleting " + oldest.getPath()); if (!delete(oldest)) { Logger.e(TAG, "Cannot delete cache file: " + oldest.getPath()); break; } } } } }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.java
public List<Pair<String, Integer>> getTopTerms(String field, int count) { ClosingIndexSearcher searcher = null; try {// w w w .jav a 2s . c o m LinkedList<Pair<String, Integer>> answer = new LinkedList<Pair<String, Integer>>(); searcher = getSearcher(indexer); IndexReader reader = searcher.getIndexReader(); TermEnum terms = reader.terms(new Term(field, "")); do { Term term = terms.term(); if (term != null) { if (!term.field().equals(field)) { break; } int freq = terms.docFreq(); Pair<String, Integer> pair = new Pair<String, Integer>(term.text(), Integer.valueOf(freq)); if (answer.size() < count) { if (answer.size() == 0) { answer.add(pair); } else if (answer.get(answer.size() - 1).getSecond().compareTo(pair.getSecond()) >= 0) { answer.add(pair); } else { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it .hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } } } else if (answer.get(count - 1).getSecond().compareTo(pair.getSecond()) < 0) { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it.hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } answer.removeLast(); } else { // off the end } } } while (terms.next()); terms.close(); return answer; } catch (IOException e) { throw new SearcherException(e); } finally { if (searcher != null) { try { searcher.close(); } catch (IOException e) { throw new SearcherException(e); } } } }
From source file:org.apache.fop.layoutmgr.AbstractBreaker.java
private int adjustBlockSpaces(LinkedList<KnuthGlue> spaceList, int difference, int total) { if (log.isDebugEnabled()) { log.debug("AdjustBlockSpaces: difference " + difference + " / " + total + " on " + spaceList.size() + " spaces in block"); }/* w w w . j av a2 s . c om*/ ListIterator<KnuthGlue> spaceListIterator = spaceList.listIterator(); int adjustedDiff = 0; int partial = 0; while (spaceListIterator.hasNext()) { KnuthGlue blockSpace = spaceListIterator.next(); partial += (difference > 0 ? blockSpace.getStretch() : blockSpace.getShrink()); if (log.isDebugEnabled()) { log.debug("available = " + partial + " / " + total); log.debug("competenza = " + (((int) ((float) partial * difference / total)) - adjustedDiff) + " / " + difference); } int newAdjust = ((BlockLevelLayoutManager) blockSpace.getLayoutManager()).negotiateBPDAdjustment( ((int) ((float) partial * difference / total)) - adjustedDiff, blockSpace); adjustedDiff += newAdjust; } return adjustedDiff; }
From source file:org.apache.fop.layoutmgr.AbstractBreaker.java
private int adjustLineNumbers(LinkedList<KnuthGlue> lineList, int difference, int total) { if (log.isDebugEnabled()) { log.debug("AdjustLineNumbers: difference " + difference + " / " + total + " on " + lineList.size() + " elements"); }//ww w. ja v a2 s.c om ListIterator<KnuthGlue> lineListIterator = lineList.listIterator(); int adjustedDiff = 0; int partial = 0; while (lineListIterator.hasNext()) { KnuthGlue line = lineListIterator.next(); partial += (difference > 0 ? line.getStretch() : line.getShrink()); int newAdjust = ((BlockLevelLayoutManager) line.getLayoutManager()) .negotiateBPDAdjustment(((int) ((float) partial * difference / total)) - adjustedDiff, line); adjustedDiff += newAdjust; } return adjustedDiff; }
From source file:org.apache.fop.layoutmgr.BlockLayoutManager.java
/** {@inheritDoc} */ @Override//from w ww . ja va 2 s .co m public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { getParentArea(null); // if this will create the first block area in a page // and display-align is after or center, add space before if (layoutContext.getSpaceBefore() > 0) { addBlockSpacing(0.0, MinOptMax.getInstance(layoutContext.getSpaceBefore())); } LayoutManager childLM; LayoutManager lastLM = null; LayoutContext lc = new LayoutContext(0); lc.setSpaceAdjust(layoutContext.getSpaceAdjust()); // set space after in the LayoutContext for children if (layoutContext.getSpaceAfter() > 0) { lc.setSpaceAfter(layoutContext.getSpaceAfter()); } PositionIterator childPosIter; // "unwrap" the NonLeafPositions stored in parentIter // and put them in a new list; LinkedList<Position> positionList = new LinkedList<Position>(); Position pos; Position firstPos = null; Position lastPos = null; while (parentIter.hasNext()) { pos = parentIter.next(); //log.trace("pos = " + pos.getClass().getName() + "; " + pos); if (pos.getIndex() >= 0) { if (firstPos == null) { firstPos = pos; } lastPos = pos; } Position innerPosition = pos; if (pos instanceof NonLeafPosition) { //Not all elements are wrapped innerPosition = pos.getPosition(); } if (innerPosition != null && (innerPosition.getLM() != this || innerPosition instanceof MappingPosition)) { // innerPosition was created by another LM positionList.add(innerPosition); lastLM = innerPosition.getLM(); } } addId(); addMarkersToPage(true, isFirst(firstPos), isLast(lastPos)); // the Positions in positionList were inside the elements // created by the LineLM childPosIter = new PositionIterator(positionList.listIterator()); while ((childLM = childPosIter.getNextChildLM()) != null) { // set last area flag lc.setFlags(LayoutContext.LAST_AREA, (layoutContext.isLastArea() && childLM == lastLM)); lc.setStackLimitBP(layoutContext.getStackLimitBP()); // Add the line areas to Area childLM.addAreas(childPosIter, lc); } addMarkersToPage(false, isFirst(firstPos), isLast(lastPos)); TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), effSpaceBefore, effSpaceAfter); flush(); curBlockArea = null; resetSpaces(); //Notify end of block layout manager to the PSLM checkEndOfLayout(lastPos); }