List of usage examples for java.util ListIterator previous
E previous();
From source file:org.saiku.reporting.core.builder.SimpleCrosstabBuilder.java
public void build() throws ReportProcessingException { /*/*from ww w. j a v a 2s.c om*/ * Generate the Details-Row */ final CrosstabCellBody cellBody = new CrosstabCellBody(); //--------------------------------- DetailsHeader detailsHeader = new DetailsHeader(); detailsHeader.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); detailsHeader.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_ROW); ArrayList<FieldDefinition> detailFieldDefinitions = this.reportSpecification.getFieldDefinitions(); final float[] computedWidth = ReportBuilderUtil.correctFieldWidths(detailFieldDefinitions, definition); DetailsHeaderBuilder detailsHeaderBuilder = new DetailsHeaderBuilder(attributeContext, definition, flowController, reportSpecification); int j = 0; for (FieldDefinition field : detailFieldDefinitions) { detailsHeaderBuilder.build(detailsHeader, field, computedWidth[j], j); j++; } cellBody.setHeader(detailsHeader); //--------------------------------- cellBody.addElement(createCell(null, INNERMOST, INNERMOST)); GroupBody body = cellBody; /* * Generate the Column-Groups */ ArrayList<GroupDefinition> groupDefinitions = this.reportSpecification.getGroupDefinitions(); ListIterator<GroupDefinition> colGrpItr = groupDefinitions.listIterator(groupDefinitions.size()); while (colGrpItr.hasPrevious()) { final GroupDefinition colGrp = colGrpItr.previous(); if (colGrp.getType().equals(GroupType.CT_COLUMN)) { final CrosstabColumnGroup columnGroup = new CrosstabColumnGroup(body); columnGroup.setName("Group " + colGrp.getGroupName()); columnGroup.setField(colGrp.getFieldId()); /* 1) Chrosstab Header 2) Title Header 3) Summary Header */ final List<RootBandFormat> headerFormats = colGrp.getHeaderFormats(); int index = groupDefinitions.indexOf(colGrp); String uid = RPT_GROUP_HEADER + index; String htmlClass = "saiku " + uid; RootBandFormat headerFormat = null; if (headerFormats.size() < 1 || headerFormats.get(0) == null) { headerFormat = new RootBandFormat(); headerFormats.add(0, headerFormat); } else { headerFormat = headerFormats.get(0); } Element headerItem = createFieldItem(colGrp.getFieldId()); //MergeFormatUtil.mergeElementFormats(headerItem, headerFormat); MergeFormatUtil.mergeElementFormats(columnGroup.getHeader(), headerFormat); headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-0"); headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-0"); //Is this used for style definitions? headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Xml.ID, uid + "-0"); columnGroup.getHeader().addElement(headerItem); columnGroup.getHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); columnGroup.getHeader().getStyle().setStyleProperty(TextStyleKeys.BOLD, Boolean.TRUE); RootBandFormat titleFormat = null; if (headerFormats.size() < 2 || headerFormats.get(1) == null) { titleFormat = new RootBandFormat(); headerFormats.add(1, titleFormat); } else { titleFormat = headerFormats.get(1); } String titleLabel = titleFormat.getLabel() != null ? titleFormat.getLabel() : colGrp.getDisplayName(); Element titleItem = createLabel(titleLabel); MergeFormatUtil.mergeElementFormats(titleItem, titleFormat); titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-1"); titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-1"); columnGroup.getTitleHeader().addElement(titleItem); columnGroup.getTitleHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); RootBandFormat summaryFormat = null; if (headerFormats.size() < 3 || headerFormats.get(2) == null) { summaryFormat = new RootBandFormat(); headerFormats.add(1, summaryFormat); } else { summaryFormat = headerFormats.get(2); } String summaryLabel = summaryFormat.getLabel() != null ? summaryFormat.getLabel() : "Total"; Element summaryItem = createLabel(summaryLabel); MergeFormatUtil.mergeElementFormats(summaryItem, summaryFormat); summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-2"); summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-2"); columnGroup.getSummaryHeader().addElement(summaryItem); columnGroup.getSummaryHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); columnGroup.setPrintSummary(colGrp.isPrintSummary()); if (colGrp.isPrintSummary()) { //create cell needs to be enhanced later to always pick the correct group combination for the //element formats final CrosstabCell cell = createCell("Group " + colGrp.getFieldId(), colGrp.getFieldId(), INNERMOST); cell.setColumnField(colGrp.getFieldId()); cell.setName(colGrp.getFieldId()); cellBody.addElement(cell); } body = new CrosstabColumnGroupBody(columnGroup); } } /* * Generate the Row-Groups */ ListIterator<GroupDefinition> rowGrpItr = groupDefinitions.listIterator(groupDefinitions.size()); while (rowGrpItr.hasPrevious()) { final GroupDefinition rowGrp = rowGrpItr.previous(); if (rowGrp.getType().equals(GroupType.CT_ROW)) { final CrosstabRowGroup rowGroup = new CrosstabRowGroup(body); int index = groupDefinitions.indexOf(rowGrp); String uid = RPT_GROUP_HEADER + index; String htmlClass = "saiku " + uid; rowGroup.setName("Group " + rowGrp.getGroupName()); rowGroup.setField(rowGrp.getFieldId()); final List<RootBandFormat> headerFormats = rowGrp.getHeaderFormats(); RootBandFormat headerFormat = null; if (headerFormats.size() < 1 || headerFormats.get(0) == null) { headerFormat = new RootBandFormat(); headerFormats.add(0, headerFormat); } else { headerFormat = headerFormats.get(0); } Element headerItem = createFieldItem(rowGrp.getFieldId()); //MergeFormatUtil.mergeElementFormats(headerItem, headerFormat); MergeFormatUtil.mergeElementFormats(rowGroup.getHeader(), headerFormat); headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-0"); headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-0"); rowGroup.getHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); rowGroup.getHeader().getStyle().setStyleProperty(TextStyleKeys.BOLD, Boolean.TRUE); rowGroup.getHeader().addElement(headerItem); RootBandFormat titleFormat = null; if (headerFormats.size() < 2 || headerFormats.get(1) == null) { titleFormat = new RootBandFormat(); headerFormats.add(1, titleFormat); } else { titleFormat = headerFormats.get(1); } String titleLabel = titleFormat.getLabel() != null ? titleFormat.getLabel() : rowGrp.getDisplayName(); Element titleItem = createLabel(titleLabel); MergeFormatUtil.mergeElementFormats(titleItem, titleFormat); titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-1"); titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-1"); rowGroup.getTitleHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); rowGroup.getTitleHeader().addElement(titleItem); RootBandFormat summaryFormat = null; if (headerFormats.size() < 3 || headerFormats.get(2) == null) { summaryFormat = new RootBandFormat(); headerFormats.add(1, summaryFormat); } else { summaryFormat = headerFormats.get(2); } String summaryLabel = summaryFormat.getLabel() != null ? summaryFormat.getLabel() : "Total"; Element summaryItem = createLabel(summaryLabel); MergeFormatUtil.mergeElementFormats(summaryItem, summaryFormat); summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS, htmlClass + "-2"); summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-2"); rowGroup.getSummaryHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f); rowGroup.getSummaryHeader().addElement(summaryItem); rowGroup.setPrintSummary(rowGrp.isPrintSummary()); if (rowGrp.isPrintSummary()) { final CrosstabCell cell = createCell("Group " + rowGroup.getField(), INNERMOST, rowGrp.getFieldId()); cell.setRowField(rowGrp.getFieldId()); cell.setName(rowGrp.getFieldId()); cellBody.addElement(cell); ListIterator<GroupDefinition> colGrpItrInner = groupDefinitions .listIterator(groupDefinitions.size()); while (colGrpItrInner.hasPrevious()) { final GroupDefinition colGrp = colGrpItrInner.previous(); if (colGrp.getType().equals(GroupType.CT_COLUMN)) { if (colGrp.isPrintSummary()) { final CrosstabCell crosstabCell = createCell("Group " + rowGroup.getField(), colGrp.getFieldId(), rowGrp.getFieldId()); crosstabCell.setColumnField(colGrp.getFieldId()); crosstabCell.setRowField(rowGrp.getFieldId()); crosstabCell.setName(colGrp.getFieldId() + "," + rowGroup.getField()); cellBody.addElement(crosstabCell); } } } } body = new CrosstabRowGroupBody(rowGroup); } } /* * Let's ommit Other-Groups for now */ // At The end we need to wrap the generated stuff in a crosstabgroup and put it in the // report CrosstabGroup crosstabRootGroup = new CrosstabGroup(body); crosstabRootGroup.setPrintColumnTitleHeader(true); crosstabRootGroup.setPrintDetailsHeader(true); insertCrosstab(crosstabRootGroup); //remove all relational groups GroupUtils.removedUnusedTemplateGroups(0, definition); }
From source file:net.sourceforge.fenixedu.domain.degreeStructure.DegreeModule.java
public ICurricularRule getMostRecentActiveCurricularRule(final CurricularRuleType ruleType, final CourseGroup parentCourseGroup, final ExecutionYear executionYear) { final List<ICurricularRule> curricularRules = new ArrayList<ICurricularRule>( getCurricularRules(ruleType, parentCourseGroup, (ExecutionYear) null)); Collections.sort(curricularRules, ICurricularRule.COMPARATOR_BY_BEGIN); if (curricularRules.isEmpty()) { return null; }// ww w . ja v a 2s . c o m if (executionYear == null) { final ListIterator<ICurricularRule> iter = curricularRules.listIterator(curricularRules.size()); while (iter.hasPrevious()) { final ICurricularRule curricularRule = iter.previous(); if (curricularRule.isActive()) { return curricularRule; } } return null; } ICurricularRule result = null; for (final ICurricularRule curricularRule : curricularRules) { if (curricularRule.isValid(executionYear)) { if (result != null) { // TODO: remove this throw when curricular rule ensures // that it can be only one active for execution period // and replace by: return curricularRule throw new DomainException( "error.degree.module.has.more.than.one.credits.limit.for.executionYear", getName()); } result = curricularRule; } } return result; }
From source file:hydrograph.ui.propertywindow.widgets.dialog.hiveInput.HiveFieldDialogHelper.java
/** * //w w w . j a va 2s.c om * Compares available fields and selected partition key fields for * hive input and output components. * */ public boolean compare_fields(TableItem[] items, List<String> sourceFieldsList) { ListIterator<String> t_itr, s_itr; boolean is_equal = true; List<String> target_fields = new ArrayList<String>(); if (items.length > 0) { for (TableItem tableItem : items) { target_fields.add((String) tableItem.getText()); } List<String> source_field = new ArrayList<String>(sourceFieldsList); t_itr = target_fields.listIterator(target_fields.size()); s_itr = source_field.listIterator(source_field.size()); while (t_itr.hasPrevious() & s_itr.hasPrevious()) { if (StringUtils.equals(s_itr.previous(), t_itr.previous())) { is_equal = true; } else { is_equal = false; break; } } } return is_equal; }
From source file:gr.iit.demokritos.cru.cps.ai.ComputationalCreativityMetrics.java
public double MinClosure(String phrase, String story) { double closure = 0.0; //in case minclosue is not called by ComputeRar_Eff if (story.equalsIgnoreCase("")) { story = phrase;//from w w w. j a v a2 s. c o m } //hashmap of the terms and their index HashMap<String, Double> termIndex = new HashMap<String, Double>(); //take the top terms of the phrase by their stems tf // HashMap<ArrayList<String>, Double> termsTf = inf.TopTerms(story.toLowerCase(), true); for (String s : phrase.split(" ")) { termIndex.put(s, 1.0 * story.indexOf(s)); } //sort the hashamp (descending) and traverse it reversely, to start from the first word in the phrase LinkedHashMap<String, Double> sorted = inf.sortHashMapByValues(termIndex); ListIterator iter = new ArrayList(sorted.keySet()).listIterator(sorted.size()); HashMap<String, Double> graph = new HashMap<String, Double>(); //store the first word in the phrase, in order to be found in the first iteration graph.put(sorted.keySet().toArray()[sorted.keySet().size() - 1].toString(), 0.0); //for each word that comes next in the phrase while (iter.hasPrevious()) { String s = iter.previous().toString(); //find the shortest distance from it to the root (first word) double min = 1.0; //looking through every word that has already defined its min distance to the root for (String k : graph.keySet()) { double dist = getDistance(s, k); //+ graph.get(k); if (dist < min) { min = dist; } } graph.put(s, min); //keep the overal sum of weights of the edges closure += min; } return closure; }
From source file:org.springframework.ldap.core.DistinguishedName.java
/** * Add an LDAP path first in this DistinguishedName. E.g.: * /*from www.j ava 2 s.co m*/ * <pre> * DistinguishedName name1 = new DistinguishedName("ou=people"); * DistinguishedName name2 = new DistinguishedName("c=SE, dc=jayway, dc=se"); * name1.prepend(name2); * </pre> * * will result in <code>ou=people, c=SE, dc=jayway, dc=se</code> * * @param path the path to prepend. */ public void prepend(DistinguishedName path) { ListIterator i = path.getNames().listIterator(path.getNames().size()); while (i.hasPrevious()) { names.add(0, i.previous()); } }
From source file:org.openiot.ui.request.definition.web.sparql.SparqlGenerator.java
@SuppressWarnings("unchecked") public void visit(org.openiot.ui.request.definition.web.model.nodes.impl.filters.Group node) { // Unwind the stack till we find the sink GraphNodeEndpoint ourEndpoint = null; ListIterator<GraphNodeConnection> connectionIt = visitedConnectionGraphStack .listIterator(visitedConnectionGraphStack.size()); ourEndpoint = connectionIt.previous().getSourceEndpoint(); // Get attributes endpoint GraphNodeEndpoint attributesEndpoint = node.getEndpointByLabel("ATTRIBUTES"); this.targetDataSource = (GenericSource) model.findGraphEndpointConnections(attributesEndpoint).get(0) .getSourceNode();/*ww w . j a va 2s . c o m*/ // Generate groups List<String> groupList = (List<String>) node.getPropertyValueMap().get("GROUPS"); for (String group : groupList) { String timeComponent = group.replace("recordTime_", ""); subGroupNode.appendToScope(new Expression( "( fn:" + timeComponent + "-from-dateTime(?" + targetDataSource.getUID() + "_recordTime) )")); subOrderNode.appendToScope(new Expression( "( fn:" + timeComponent + "-from-dateTime(?" + targetDataSource.getUID() + "_recordTime) )")); } // Follow the connection that matches our endpoint label (ie the // currently grouped property) List<GraphNodeConnection> incomingConnections = model.findGraphEndpointConnections(attributesEndpoint); String attrName = ourEndpoint.getLabel().replace("grp_", ""); for (GraphNodeConnection connection : incomingConnections) { if (!attrName.equals(connection.getSourceEndpoint().getLabel())) { continue; } this.visitedConnectionGraphStack.push(connection); this.visitViaReflection(connection.getSourceNode()); this.visitedConnectionGraphStack.pop(); } }
From source file:org.apache.hadoop.hbase.regionserver.RegionMergeTransactionImpl.java
@Override public boolean rollback(final Server server, final RegionServerServices services) throws IOException { assert this.mergedRegionInfo != null; this.server = server; this.rsServices = services; // Coprocessor callback if (rsCoprocessorHost != null) { rsCoprocessorHost.preRollBackMerge(this.region_a, this.region_b); }//from ww w .j av a 2s. co m boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); // Iterate in reverse. while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); transition(je.getPhase(), true); switch (je.getPhase()) { case SET_MERGING: if (services != null && !services.reportRegionStateTransition(TransitionCode.MERGE_REVERTED, mergedRegionInfo, region_a.getRegionInfo(), region_b.getRegionInfo())) { return false; } break; case CREATED_MERGE_DIR: this.region_a.writestate.writesEnabled = true; this.region_b.writestate.writesEnabled = true; this.region_a.getRegionFileSystem().cleanupMergesDir(); break; case CLOSED_REGION_A: try { // So, this returns a seqid but if we just closed and then reopened, // we should be ok. On close, we flushed using sequenceid obtained // from hosting regionserver so no need to propagate the sequenceid // returned out of initialize below up into regionserver as we // normally do. this.region_a.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_REGION_A of region " + region_a.getRegionInfo().getRegionNameAsString(), e); throw new RuntimeException(e); } break; case OFFLINED_REGION_A: if (services != null) services.addToOnlineRegions(this.region_a); break; case CLOSED_REGION_B: try { this.region_b.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_REGION_A of region " + region_b.getRegionInfo().getRegionNameAsString(), e); throw new RuntimeException(e); } break; case OFFLINED_REGION_B: if (services != null) services.addToOnlineRegions(this.region_b); break; case STARTED_MERGED_REGION_CREATION: this.region_a.getRegionFileSystem().cleanupMergedRegion(this.mergedRegionInfo); break; case PONR: // We got to the point-of-no-return so we need to just abort. Return // immediately. Do not clean up created merged regions. return false; // Informational states only case STARTED: case PREPARED: case COMPLETED: break; default: throw new RuntimeException("Unhandled journal entry: " + je); } } // Coprocessor callback if (rsCoprocessorHost != null) { rsCoprocessorHost.postRollBackMerge(this.region_a, this.region_b); } return result; }
From source file:chat.viska.commons.pipelines.Pipeline.java
private void processObject(final Object obj, final boolean isReading) { final ListIterator<Map.Entry<String, Pipe>> iterator = isReading ? pipes.listIterator() : pipes.listIterator(pipes.size()); final List<Object> cache = new ArrayList<>(); cache.add(obj);//from ww w .j a v a2s.c o m while (isReading ? iterator.hasNext() : iterator.hasPrevious()) { final Pipe pipe = isReading ? iterator.next().getValue() : iterator.previous().getValue(); final List<Object> toForward = new ArrayList<>(); for (Object it : cache) { final List<Object> out = new ArrayList<>(); try { if (isReading) { pipe.onReading(this, it, out); } else { pipe.onWriting(this, it, out); } } catch (Exception cause) { processException(iterator, cause, isReading); return; } toForward.addAll(out); } if (toForward.size() == 0) { return; } else { cache.clear(); cache.addAll(toForward); } } for (Object it : cache) { try { if (isReading) { inboundStream.onNext((I) it); } else { outboundStream.onNext((O) it); } } catch (ClassCastException ex) { continue; } } }
From source file:org.springframework.ldap.core.DistinguishedName.java
private String format(boolean compact) { // empty path if (names.size() == 0) return ""; StringBuffer buffer = new StringBuffer(256); ListIterator i = names.listIterator(names.size()); while (i.hasPrevious()) { LdapRdn rdn = (LdapRdn) i.previous(); buffer.append(rdn.getLdapEncoded()); // add comma, except in last iteration if (i.hasPrevious()) { if (compact) { buffer.append(","); } else { buffer.append(", "); }//from www .jav a2 s . c o m } } return buffer.toString(); }
From source file:com.alibaba.wasp.fserver.SplitTransaction.java
/** * @param server/*from ww w. j av a 2s .c om*/ * Hosting server instance (May be null when testing). * @param services * @throws java.io.IOException * If thrown, rollback failed. Take drastic action. * @return True if we successfully rolled back, false if we got to the point * of no return and so now need to abort the server to minimize * damage. */ public boolean rollback(final Server server, final FServerServices services) throws IOException { boolean result = true; ListIterator<JournalEntry> iterator = this.journal.listIterator(this.journal.size()); // Iterate in reverse. while (iterator.hasPrevious()) { JournalEntry je = iterator.previous(); switch (je) { case STARTED_SPLITTING: if (server != null && server.getZooKeeper() != null) { cleanZK(server, this.parent.getEntityGroupInfo(), false); } break; case SET_SPLITTING_IN_ZK: if (server != null && server.getZooKeeper() != null) { cleanZK(server, this.parent.getEntityGroupInfo(), true); } break; case CREATE_SPLIT_STOREAGE: this.parent.writestate.writesEnabled = true; break; case CLOSED_PARENT_ENTITYGROUP: try { this.parent.initialize(); } catch (IOException e) { LOG.error("Failed rollbacking CLOSED_PARENT_ENTITYGROUP of entityGroup " + this.parent.getEntityGroupNameAsString(), e); throw new RuntimeException(e); } break; case STARTED_ENTITYGROUP_A_CREATION: break; case STARTED_ENTITYGROUP_B_CREATION: break; case OFFLINED_PARENT: if (services != null) services.addToOnlineEntityGroups(this.parent); break; case PONR: // We got to the point-of-no-return so we need to just abort. Return // immediately. Do not clean up created daughter entityGroups. They need // to be in place so we don't delete the parent entityGroup mistakenly. // See HBASE-3872. return false; default: throw new RuntimeException("Unhandled journal entry: " + je); } } return result; }