List of usage examples for java.util LinkedList getFirst
public E getFirst()
From source file:net.sf.markov4jmeter.testplangenerator.transformation.filters.AbstractFilter.java
/** * Searches for a (unique) occurrence of an element of certain type in a * given Test Plan. If no matching element is available, an error message * will be given; in case more than one element is available, the first * match will be used, and a warning message will be given. * * @param testPlan Test Plan to be explored. * @param type type of element to be searched for. * * @return/*from w w w. j a v a 2 s .co m*/ * a valid element, or <code>null</code> if no element is available. */ protected <T extends AbstractTestElement> T findUniqueTestPlanElement(final ListedHashTree testPlan, final Class<T> type) { final LinkedList<T> elements = this.testPlanModifier.collectElementsByType(testPlan, type); final int n = elements.size(); T element = null; if (n == 0) { final String message = String.format(AbstractFilter.ERROR_ELEMENT_NOT_FOUND, type); AbstractFilter.LOG.error(message); } else { if (n > 1) { final String message = String.format(AbstractFilter.WARNING_ELEMENT_NOT_UNIQUE, type); AbstractFilter.LOG.warn(message); } element = elements.getFirst(); } return element; }
From source file:net.relet.freimap.LinkInfo.java
public void setLinkProfile(LinkedList<LinkData> lp) { XYSeries data = new XYSeries("etx"); XYSeries avail = new XYSeries("avail"); XYSeriesCollection datac = new XYSeriesCollection(data); datac.addSeries(avail);// w w w .j a v a 2 s .c om linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx", datac, PlotOrientation.VERTICAL, false, false, false); sexupLayout(linkChart); long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan maxCount = 0; //max idem long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks double sum = 0; /* ok, this ain't effective, we do it just to pre-calculate maxCount */ ListIterator<LinkData> li = lp.listIterator(); while (li.hasNext()) { LinkData ld = li.next(); count++; if (ld.time - lastClock > aggregate) { if (maxCount < count) maxCount = count; lastClock = ld.time; count = 0; } } //reset for second iteration count = 0; lastClock = first; //iterate again li = lp.listIterator(); while (li.hasNext()) { LinkData ld = li.next(); sum += ld.quality; count++; if (aggregate == 0) aggregate = 1000;//dirty hack if (ld.time - lastClock > aggregate) { for (long i = lastClock; i < ld.time - aggregate; i += aggregate) { data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN); avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0); } count = 0; sum = 0; lastClock = ld.time; } } status = STATUS_AVAILABLE; }
From source file:org.artifactory.storage.db.binstore.service.BinaryStoreImpl.java
private void setBinaryProvidersContext(LinkedList<BinaryProviderBase> binaryProviders) { if (!(binaryProviders.getFirst() instanceof UsageTrackingBinaryProvider)) { throw new IllegalStateException("The first binary provider should be read tracking!"); }/*from w w w . jav a 2 s .c o m*/ // Make sure the last one is the empty binary provider if (!(binaryProviders.getLast() instanceof EmptyBinaryProvider)) { binaryProviders.add(new EmptyBinaryProvider()); } FileBinaryProvider foundFileBinaryProvider = null; BinaryProviderBase previous = null; for (BinaryProviderBase binaryProvider : binaryProviders) { if (previous != null) { // Set next to previous previous.setContext(new BinaryProviderContextImpl(this, binaryProvider)); } if (foundFileBinaryProvider == null && previous instanceof FileBinaryProvider) { foundFileBinaryProvider = (FileBinaryProvider) previous; } previous = binaryProvider; } fileBinaryProvider = foundFileBinaryProvider; firstBinaryProvider = (UsageTrackingBinaryProvider) binaryProviders.getFirst(); }
From source file:net.relet.freimap.NodeInfo.java
public void setLinkCountProfile(LinkedList<LinkCount> lcp) { if (lcp.size() == 0) { minLinks = 0;/*w w w .java2 s .c om*/ maxLinks = 0; return; } XYSeries data = new XYSeries("links"); XYSeries avail = new XYSeries("avail"); XYSeriesCollection datac = new XYSeriesCollection(data); datac.addSeries(avail); linkCountChart = ChartFactory.createXYLineChart("average incoming link count\r\nincoming link availability", "time", "count", datac, PlotOrientation.VERTICAL, false, false, false); sexupLayout(linkCountChart); long first = lcp.getFirst().time, last = lcp.getLast().time, lastClock = first, count = 0, maxCount = 0; long aggregate = (last - first) / CHART_WIDTH; double sum = 0; /* ok, this ain't effective, we do it just to pre-calculate maxCount */ ListIterator<LinkCount> li = lcp.listIterator(); while (li.hasNext()) { LinkCount lc = li.next(); count++; if (lc.time - lastClock > aggregate) { if (maxCount < count) maxCount = count; lastClock = lc.time; count = 0; } } //reset for second iteration count = 0; lastClock = first; //iterate again li = lcp.listIterator(); while (li.hasNext()) { LinkCount lc = li.next(); if (minLinks > lc.count) minLinks = lc.count; if (maxLinks < lc.count) maxLinks = lc.count; sum += lc.count; count++; if (aggregate == 0) aggregate = 1000;//dirty hack if (lc.time - lastClock > aggregate) { for (long i = lastClock; i < lc.time - aggregate; i += aggregate) { data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN); avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0); } count = 0; sum = 0; lastClock = lc.time; } } status = STATUS_AVAILABLE; }
From source file:org.apache.fop.layoutmgr.table.TableContentLayoutManager.java
/** * Get a sequence of KnuthElements representing the content * of the node assigned to the LM./*from w w w . java 2 s . c o m*/ * * @param context the LayoutContext used to store layout information * @param alignment the desired text alignment * @return the list of KnuthElements * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(LayoutContext, int) */ public List getNextKnuthElements(LayoutContext context, int alignment) { if (LOG.isDebugEnabled()) { LOG.debug("==> Columns: " + getTableLM().getColumns()); } KnuthBox headerAsFirst = null; KnuthBox headerAsSecondToLast = null; KnuthBox footerAsLast = null; if (headerIter != null && headerList == null) { this.headerList = getKnuthElementsForRowIterator(headerIter, context, alignment, TableRowIterator.HEADER); this.headerNetHeight = ElementListUtils.calcContentLength(this.headerList); if (LOG.isDebugEnabled()) { LOG.debug("==> Header: " + headerNetHeight + " - " + this.headerList); } TableHeaderFooterPosition pos = new TableHeaderFooterPosition(getTableLM(), true, this.headerList); KnuthBox box = new KnuthBox(headerNetHeight, pos, false); if (getTableLM().getTable().omitHeaderAtBreak()) { //We can simply add the table header at the start //of the whole list headerAsFirst = box; } else { headerAsSecondToLast = box; } } if (footerIter != null && footerList == null) { this.footerList = getKnuthElementsForRowIterator(footerIter, context, alignment, TableRowIterator.FOOTER); this.footerNetHeight = ElementListUtils.calcContentLength(this.footerList); if (LOG.isDebugEnabled()) { LOG.debug("==> Footer: " + footerNetHeight + " - " + this.footerList); } //We can simply add the table footer at the end of the whole list TableHeaderFooterPosition pos = new TableHeaderFooterPosition(getTableLM(), false, this.footerList); KnuthBox box = new KnuthBox(footerNetHeight, pos, false); footerAsLast = box; } LinkedList returnList = getKnuthElementsForRowIterator(bodyIter, context, alignment, TableRowIterator.BODY); if (headerAsFirst != null) { int insertionPoint = 0; if (returnList.size() > 0 && ((ListElement) returnList.getFirst()).isForcedBreak()) { insertionPoint++; } returnList.add(insertionPoint, headerAsFirst); } else if (headerAsSecondToLast != null) { int insertionPoint = returnList.size(); if (returnList.size() > 0 && ((ListElement) returnList.getLast()).isForcedBreak()) { insertionPoint--; } returnList.add(insertionPoint, headerAsSecondToLast); } if (footerAsLast != null) { int insertionPoint = returnList.size(); if (returnList.size() > 0 && ((ListElement) returnList.getLast()).isForcedBreak()) { insertionPoint--; } returnList.add(insertionPoint, footerAsLast); } return returnList; }
From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java
/** * Adds filter Queries to the query for selected categories returned from the UI * //from ww w .j ava 2 s. c o m * @param query * @param selectedCats */ public void addSelectedFilterQueriesToQuery(SolrQuery query, List<String> selectedCats) { String filterQuery = ""; LinkedList<String> selectedCategories = new LinkedList<String>(); selectedCategories.addAll(selectedCats); if (selectedCategories == null || selectedCategories.isEmpty()) { } else { LinkedList<CategoryFilter> existingCategories = new LinkedList<CategoryFilter>(); existingCategories.addAll(getChartSearchService().getAllCategoryFilters()); int indexOfFirstSelected = selectedCategories.indexOf(selectedCategories.getFirst()); int indexOfLastSelected = selectedCategories.indexOf(selectedCategories.getLast()); int indexOfFirstExisting = existingCategories.indexOf(existingCategories.getFirst()); int indexOfLastExisting = existingCategories.indexOf(existingCategories.getLast()); for (int i = indexOfFirstSelected; i <= indexOfLastSelected; i++) { String currentSelected = selectedCategories.get(i); for (int j = indexOfFirstExisting; j <= indexOfLastExisting; j++) { CategoryFilter currentExisting = existingCategories.get(j); String currentExistingName = currentExisting.getCategoryName(); if (currentSelected.equals(currentExistingName.toLowerCase())) { if (i != indexOfLastSelected) { filterQuery += currentExisting.getFilterQuery() + " OR "; } else filterQuery += currentExisting.getFilterQuery(); } } } query.addFilterQuery(filterQuery); } }
From source file:org.epics.archiverappliance.retrieval.DataRetrievalServlet.java
/** * Determine the thread pool to be used for post processing based on some characteristics of the request * The plugins will yield a list of callables that could potentially be evaluated in parallel * Whether we evaluate in parallel is made here. * @param pvName/*from w ww. j av a 2s . c o m*/ * @param postProcessor * @return */ private static RetrievalExecutorResult determineExecutorForPostProcessing(String pvName, PVTypeInfo typeInfo, LinkedList<TimeSpan> requestTimes, HttpServletRequest req, PostProcessor postProcessor) { long memoryConsumption = postProcessor.estimateMemoryConsumption(pvName, typeInfo, requestTimes.getFirst().getStartTime(), requestTimes.getLast().getEndTime(), req); double memoryConsumptionInMB = (double) memoryConsumption / (1024 * 1024); DecimalFormat twoSignificantDigits = new DecimalFormat("###,###,###,###,###,###.##"); logger.debug("Memory consumption estimate from postprocessor for pv " + pvName + " is " + memoryConsumption + "(bytes) ~= " + twoSignificantDigits.format(memoryConsumptionInMB) + "(MB)"); // For now, we only use the current thread to execute in serial. // Once we get the unit tests for the post processors in a more rigorous shape, we can start using the ForkJoinPool. // There are some complexities in using the ForkJoinPool - in this case, we need to convert to using synchronized versions of the SummaryStatistics and DescriptiveStatistics // We also still have the issue where we can add a sample twice because of the non-transactional nature of ETL. // However, there is a lot of work done by the PostProcessors in estimateMemoryConsumption so leave this call in place. return new RetrievalExecutorResult(new CurrentThreadExecutorService(), requestTimes); }
From source file:org.alfresco.repo.rendition.StandardRenditionLocationResolverImpl.java
private RenditionLocationImpl findOrCreateTemplatedPath(NodeRef sourceNode, String path, NodeRef companyHome) { if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("FindOrCreateTemplatedPath for ").append(sourceNode).append(", ").append(path); log.debug(msg.toString());/*from w w w. jav a2 s. c o m*/ } NodeService nodeService = serviceRegistry.getNodeService(); List<String> pathElements = Arrays.asList(path.split("/")); LinkedList<String> folderElements = new LinkedList<String>(pathElements); // We need to strip out any empty strings within the path elements. // prior to passing this path to the fileFolderService for creation. // e.g. "//foo//bar///item.txt" would cause an exception. folderElements.removeAll(Arrays.asList(new String[] { "" })); // Remove 'Company Home' if it is at the start of the path. Serializable companyHomeName = nodeService.getProperty(companyHome, ContentModel.PROP_NAME); if (folderElements.getFirst().equals(companyHomeName)) { folderElements.removeFirst(); } String fileName = folderElements.removeLast(); if (fileName == null || fileName.length() == 0) { StringBuilder msg = new StringBuilder(); msg.append("The path must include a valid filename! Path: ").append(path); if (log.isDebugEnabled()) { log.debug(msg.toString()); } throw new RenditionServiceException(msg.toString()); } FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); NodeRef parent = companyHome; if (!folderElements.isEmpty()) { FileInfo parentInfo = FileFolderUtil.makeFolders(fileFolderService, companyHome, folderElements, ContentModel.TYPE_FOLDER); parent = parentInfo.getNodeRef(); } if (log.isDebugEnabled()) { log.debug("folderElements: " + folderElements); log.debug("parent: " + parent); log.debug(" " + nodeService.getType(parent) + " " + nodeService.getPath(parent)); log.debug("fileName: " + fileName); } NodeRef child = fileFolderService.searchSimple(parent, fileName); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("RenditionLocation parent=").append(parent).append(", child=").append(child) .append(", fileName=").append(fileName); log.debug(msg.toString()); if (child != null) { log.debug("child path = " + nodeService.getPath(child)); } } return new RenditionLocationImpl(parent, child, fileName); }
From source file:net.gaast.giggity.ScheduleViewActivity.java
public void finishNavDrawer() { if (sched == null) { Log.e("finishNavDrawer", "Called before critical was loaded?"); return;/*from ww w. j ava 2 s .com*/ } LinkedList<Date> days = sched.getDays(); TextView dr = (TextView) drawerLayout.findViewById(R.id.date_range); dr.setText(Giggity.dateRange(days.getFirst(), days.getLast())); if (sched.getLinks() != null) { ViewGroup menu = (LinearLayout) drawerLayout.findViewById(R.id.menu); View sep = menu.findViewById(R.id.custom_sep); sep.setVisibility(View.VISIBLE); for (final Schedule.Link link : sched.getLinks()) { TextView item = (TextView) getLayoutInflater().inflate(R.layout.burger_menu_item, null); item.setText(link.getTitle()); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openLink(link, true); drawerLayout.closeDrawers(); } }); menu.addView(item, menu.indexOfChild(sep)); } } }
From source file:edu.cmu.tetrad.search.SearchGraphUtils.java
public static Graph bestGuessCycleOrientation(Graph graph, IndependenceTest test) { while (true) { List<Node> cycle = GraphUtils.directedCycle(graph); if (cycle == null) { break; }/*from ww w . j ava 2 s .co m*/ LinkedList<Node> _cycle = new LinkedList<Node>(cycle); Node first = _cycle.getFirst(); Node last = _cycle.getLast(); _cycle.addFirst(last); _cycle.addLast(first); int _j = -1; double minP = Double.POSITIVE_INFINITY; for (int j = 1; j < _cycle.size() - 1; j++) { int i = j - 1; int k = j + 1; Node x = test.getVariable(_cycle.get(i).getName()); Node y = test.getVariable(_cycle.get(j).getName()); Node z = test.getVariable(_cycle.get(k).getName()); test.isIndependent(x, z, Collections.singletonList(y)); double p = test.getPValue(); if (p < minP) { _j = j; minP = p; } } Node x = _cycle.get(_j - 1); Node y = _cycle.get(_j); Node z = _cycle.get(_j + 1); graph.removeEdge(x, y); graph.removeEdge(z, y); graph.addDirectedEdge(x, y); graph.addDirectedEdge(z, y); } return graph; }