List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:org.stockwatcher.data.cassandra.StockDAOImpl.java
@Override public SortedSet<Exchange> getExchanges(StatementOptions options) { SortedSet<Exchange> exchanges = new TreeSet<Exchange>(); try {//from w ww .j ava2 s.c o m Statement statement = select().column("exchange_id").column("exchange_name").column("currency_code") .from("Exchange").where(eq("active", true)); for (Row row : execute(statement, options)) { exchanges.add(createExchange(row)); } } catch (DriverException e) { throw new DAOException(e); } if (exchanges.isEmpty()) { throw new DAOException("no active exchanges found"); } return exchanges; }
From source file:br.com.hslife.orcamento.controller.PanoramaParcelamentoController.java
private void gerarGraficoDespesa(List<LancamentoConta> pagamentos) { // Verifica se deve continuar com a gerao do grfico a partir da quantidade de lanamentos if (pagamentos == null || pagamentos.size() == 0) { exibirGraficoDespesa = false;/* w w w .jav a 2s . co m*/ return; } // Instancia o Map que ir gravar os dados para gerar o grfico // necessrio manter o LinkedHashMap para poder preservar a ordenao dos meses e anos // no grfico. Caso contrrio, ser necessrio implementar um Comparator para realizar // a ordenao das chaves (em formato String) de acordo com a sequncia de meses e anos Map<String, Double> dadosPagamento = new LinkedHashMap<String, Double>(); Map<String, Double> dadosAPagar = new LinkedHashMap<String, Double>(); String dataKey = ""; maxValueBarPagamentosDespesa = 1.0; saldoDevedor = 0.0; // Gera as chaves e popula os Maps SortedSet<Date> chaves = new TreeSet<>(); Calendar dataAtual = Calendar.getInstance(); for (Integer i = 1; i <= periodo; i++) { chaves.add(dataAtual.getTime()); if (periodoAConsiderar.equals("ANTERIOR")) dataAtual.add(Calendar.MONTH, -1); else dataAtual.add(Calendar.MONTH, 1); } // Popula os Maps com as chaves geradas for (Date data : chaves) { dataKey = new SimpleDateFormat("MM/yyyy").format(data); dadosPagamento.put(dataKey, 0.0); dadosAPagar.put(dataKey, 0.0); } // Itera a lista de pagamentos para somar no ms/ano correspondente for (LancamentoConta pagamento : pagamentos) { if (pagamento.getStatusLancamentoConta().equals(StatusLancamentoConta.QUITADO)) { if (pagamento.getFaturaCartao() != null && pagamento.getFaturaCartao().getDataFechamento() != null) dataKey = new SimpleDateFormat("MM/yyyy") .format(pagamento.getFaturaCartao().getDataFechamento()); else dataKey = new SimpleDateFormat("MM/yyyy").format(pagamento.getDataPagamento()); if (dadosPagamento.get(dataKey) != null) { if (!pagamento.getLancamentoPeriodico().getMoeda().equals(moedaPadrao)) { dadosPagamento.put(dataKey, dadosPagamento.get(dataKey) + (pagamento.getValorPago() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao())); } else { dadosPagamento.put(dataKey, dadosPagamento.get(dataKey) + pagamento.getValorPago()); } } } else { dataKey = new SimpleDateFormat("MM/yyyy").format(pagamento.getDataVencimento()); if (dadosAPagar.get(dataKey) != null) { if (!pagamento.getLancamentoPeriodico().getMoeda().equals(moedaPadrao)) { dadosAPagar.put(dataKey, dadosAPagar.get(dataKey) + (pagamento.getLancamentoPeriodico().getValorParcela() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao())); } else { dadosAPagar.put(dataKey, dadosAPagar.get(dataKey) + pagamento.getLancamentoPeriodico().getValorParcela()); } } else { if (periodoAConsiderar.equals("ANTERIOR") && pagamento.getDataVencimento().before(new Date())) { saldoDevedor += pagamento.getLancamentoPeriodico().getMoeda().isPadrao() ? pagamento.getLancamentoPeriodico().getValorParcela() : Util.arredondar(pagamento.getLancamentoPeriodico().getValorParcela() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao()); } } } } // Popula o grfico com os dados obtido e habilita a exibio ultimosPagamentosDespesaModel = new BarChartModel(); ultimosPagamentosDespesaModel.setLegendPosition("s"); ultimosPagamentosDespesaModel.setTitle("Panorama dos Parcelamentos - Despesa"); ultimosPagamentosDespesaModel.setStacked(true); ultimosPagamentosDespesaModel.setExtender("ext1"); ChartSeries pagamentosSerie = new ChartSeries(); ChartSeries aPagarSerie = new ChartSeries(); pagamentosSerie.setLabel("Parcelas Pagas"); aPagarSerie.setLabel("Parcelas Pagar"); for (String key : dadosPagamento.keySet()) { pagamentosSerie.set(key, dadosPagamento.get(key)); aPagarSerie.set(key, dadosAPagar.get(key)); if ((dadosPagamento.get(key) + dadosAPagar.get(key) + 100) > maxValueBarPagamentosDespesa) { maxValueBarPagamentosDespesa = dadosPagamento.get(key) + dadosAPagar.get(key) + 100; } } ultimosPagamentosDespesaModel.addSeries(pagamentosSerie); ultimosPagamentosDespesaModel.addSeries(aPagarSerie); exibirGraficoDespesa = true; }
From source file:br.com.hslife.orcamento.controller.PanoramaParcelamentoController.java
private void gerarGraficoReceita(List<LancamentoConta> pagamentos) { // Verifica se deve continuar com a gerao do grfico a partir da quantidade de lanamentos if (pagamentos == null || pagamentos.size() == 0) { exibirGraficoReceita = false;/*from w w w .ja v a 2 s.c o m*/ return; } // Instancia o Map que ir gravar os dados para gerar o grfico // necessrio manter o LinkedHashMap para poder preservar a ordenao dos meses e anos // no grfico. Caso contrrio, ser necessrio implementar um Comparator para realizar // a ordenao das chaves (em formato String) de acordo com a sequncia de meses e anos Map<String, Double> dadosPagamento = new LinkedHashMap<String, Double>(); Map<String, Double> dadosAPagar = new LinkedHashMap<String, Double>(); String dataKey = ""; maxValueBarPagamentosReceita = 1.0; saldoCredor = 0.0; // Gera as chaves e popula os Maps SortedSet<Date> chaves = new TreeSet<>(); Calendar dataAtual = Calendar.getInstance(); for (Integer i = 1; i <= periodo; i++) { chaves.add(dataAtual.getTime()); if (periodoAConsiderar.equals("ANTERIOR")) dataAtual.add(Calendar.MONTH, -1); else dataAtual.add(Calendar.MONTH, 1); } // Popula os Maps com as chaves geradas for (Date data : chaves) { dataKey = new SimpleDateFormat("MM/yyyy").format(data); dadosPagamento.put(dataKey, 0.0); dadosAPagar.put(dataKey, 0.0); } // Itera a lista de pagamentos para somar no ms/ano correspondente for (LancamentoConta pagamento : pagamentos) { if (pagamento.getStatusLancamentoConta().equals(StatusLancamentoConta.QUITADO)) { if (pagamento.getFaturaCartao() != null && pagamento.getFaturaCartao().getDataFechamento() != null) dataKey = new SimpleDateFormat("MM/yyyy") .format(pagamento.getFaturaCartao().getDataFechamento()); else dataKey = new SimpleDateFormat("MM/yyyy").format(pagamento.getDataPagamento()); if (dadosPagamento.get(dataKey) != null) { if (!pagamento.getLancamentoPeriodico().getMoeda().equals(moedaPadrao)) { dadosPagamento.put(dataKey, dadosPagamento.get(dataKey) + (pagamento.getValorPago() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao())); } else { dadosPagamento.put(dataKey, dadosPagamento.get(dataKey) + pagamento.getValorPago()); } } } else { dataKey = new SimpleDateFormat("MM/yyyy").format(pagamento.getDataVencimento()); if (dadosAPagar.get(dataKey) != null) { if (!pagamento.getLancamentoPeriodico().getMoeda().equals(moedaPadrao)) { dadosAPagar.put(dataKey, dadosAPagar.get(dataKey) + (pagamento.getLancamentoPeriodico().getValorParcela() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao())); } else { dadosAPagar.put(dataKey, dadosAPagar.get(dataKey) + pagamento.getLancamentoPeriodico().getValorParcela()); } } else { if (periodoAConsiderar.equals("ANTERIOR") && pagamento.getDataVencimento().before(new Date())) { saldoCredor += pagamento.getLancamentoPeriodico().getMoeda().isPadrao() ? pagamento.getLancamentoPeriodico().getValorParcela() : Util.arredondar(pagamento.getLancamentoPeriodico().getValorParcela() * pagamento.getLancamentoPeriodico().getMoeda().getValorConversao()); } } } } // Popula o grfico com os dados obtido e habilita a exibio ultimosPagamentosReceitaModel = new BarChartModel(); ultimosPagamentosReceitaModel.setLegendPosition("s"); ultimosPagamentosReceitaModel.setTitle("Panorama dos Parcelamentos - Receita"); ultimosPagamentosReceitaModel.setStacked(true); ultimosPagamentosReceitaModel.setExtender("ext1"); ChartSeries pagamentosSerie = new ChartSeries(); ChartSeries aPagarSerie = new ChartSeries(); pagamentosSerie.setLabel("Parcelas Pagas"); aPagarSerie.setLabel("Parcelas Pagar"); for (String key : dadosPagamento.keySet()) { pagamentosSerie.set(key, dadosPagamento.get(key)); aPagarSerie.set(key, dadosAPagar.get(key)); if ((dadosPagamento.get(key) + dadosAPagar.get(key) + 100) > maxValueBarPagamentosReceita) { maxValueBarPagamentosReceita = dadosPagamento.get(key) + dadosAPagar.get(key) + 100; } } ultimosPagamentosReceitaModel.addSeries(pagamentosSerie); ultimosPagamentosReceitaModel.addSeries(aPagarSerie); exibirGraficoReceita = true; }
From source file:de.faustedition.tei.TeiValidator.java
@Override public void run() { try {//from w w w .j a v a2 s. c om final SortedSet<FaustURI> xmlErrors = new TreeSet<FaustURI>(); final SortedMap<FaustURI, String> teiErrors = new TreeMap<FaustURI, String>(); for (FaustURI source : xml.iterate(new FaustURI(FaustAuthority.XML, "/transcript"))) { try { final List<String> errors = validate(source); if (!errors.isEmpty()) { teiErrors.put(source, Joiner.on("\n").join(errors)); } } catch (SAXException e) { logger.debug("XML error while validating transcript: " + source, e); xmlErrors.add(source); } catch (IOException e) { logger.warn("I/O error while validating transcript: " + source, e); } } if (xmlErrors.isEmpty() && teiErrors.isEmpty()) { return; } reporter.send("TEI validation report", new ReportCreator() { public void create(PrintWriter body) { if (!xmlErrors.isEmpty()) { body.println(Strings.padStart(" XML errors", 79, '=')); body.println(); body.println(Joiner.on("\n").join(xmlErrors)); body.println(); } if (!teiErrors.isEmpty()) { body.println(Strings.padStart(" TEI errors", 79, '=')); body.println(); for (Map.Entry<FaustURI, String> teiError : teiErrors.entrySet()) { body.println(Strings.padStart(" " + teiError.getKey(), 79, '-')); body.println(); body.println(teiError.getValue()); body.println(); body.println(); } } } }); } catch (EmailException e) { e.printStackTrace(); } }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftExporterBeanTest.java
Experiment makeGoodExperiment() throws Exception { final Project prj = new Project(); final Experiment experiment = new Experiment(); prj.setExperiment(experiment);/*from w ww .j av a 2 s. co m*/ final Method setter = Experiment.class.getDeclaredMethod("setProject", Project.class); setter.setAccessible(true); setter.invoke(experiment, prj); final TermSource src = this.vocab.getSource("MO", "1.3.1.1"); // to ensure consistent order experiment.setExperimentDesignTypes(new LinkedHashSet<Term>()); experiment.getExperimentDesignTypes().add(this.vocab.getTerm(src, "test-design-type1")); experiment.getExperimentDesignTypes().add(this.vocab.getTerm(src, "test-design-type2")); experiment.setPublicIdentifier("test-exp-id"); experiment.setTitle("test-title"); final Publication pub = new Publication(); pub.setPubMedId("test-pub"); experiment.getPublications().add(pub); final ExperimentContact ec = new ExperimentContact(); final Person per = new Person(); per.setFirstName("fff"); per.setMiddleInitials("mmm"); per.setLastName("lll"); ec.setPerson(per); experiment.getExperimentContacts().add(ec); final ArrayDesign ad = new ArrayDesign(); experiment.getArrayDesigns().add(ad); ad.setName("test-ad"); ad.setGeoAccession("test-ga"); final Organization o = new Organization(); ad.setProvider(o); o.setName("Affymetrix"); final Source source = new Source(); source.setId(1L); source.getProviders().add(o); source.setName("test-source"); experiment.getSources().add(source); Sample sample = new Sample(); sample.setId(2L); sample.setName("test-sample1"); Organism ozm = new Organism(); ozm.setId(1L); ozm.setScientificName("test Organizm 1"); sample.setOrganism(ozm); source.getSamples().add(sample); sample.getSources().add(source); final Extract extract = new Extract(); extract.setId(3L); extract.setName("test-extract"); sample.getExtracts().add(extract); extract.getSamples().add(sample); sample = new Sample(); sample.setId(4L); sample.setName("test-sample2"); ozm = new Organism(); ozm.setId(2L); ozm.setScientificName("test Organizm 2"); sample.setOrganism(ozm); source.getSamples().add(sample); sample.getSources().add(source); sample.getExtracts().add(extract); extract.getSamples().add(sample); final LabeledExtract lb = new LabeledExtract(); lb.setId(5L); lb.setLabel(this.vocab.getTerm(src, "label")); final Term mt = this.vocab.getTerm(src, "test-mat"); mt.setId(1L); mt.setValue("MT val"); lb.setMaterialType(mt); extract.getLabeledExtracts().add(lb); lb.getExtracts().add(extract); final Hybridization h = new Hybridization(); h.setId(6L); final Array a = new Array(); a.setDesign(ad); h.setArray(a); h.setName("test-hyb"); experiment.getHybridizations().add(h); ProtocolApplication pa = new ProtocolApplication(); pa.setId(7L); Protocol p = this.vocab.getProtocol("some extract", src); Term type = this.vocab.getTerm(src, "nucleic_acid_extraction"); p.setDescription("extract desc"); p.setType(type); pa.setProtocol(p); sample.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(8L); type = this.vocab.getTerm(src, "labeling"); p = this.vocab.getProtocol("some label", src); p.setDescription("labeling desc"); p.setType(type); pa.setProtocol(p); extract.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(9L); p = this.vocab.getProtocol("some hybridization", src); p.setDescription("hybridization desc"); type = this.vocab.getTerm(src, "hybridization"); p.setType(type); pa.setProtocol(p); lb.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(10L); p = this.vocab.getProtocol("some scan", src); p.setDescription("scan desc"); type = this.vocab.getTerm(src, "scan"); p.setType(type); pa.setProtocol(p); h.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(11L); p = this.vocab.getProtocol("some treatment", src); p.setDescription("treatment desc"); type = this.vocab.getTerm(src, "treatment"); p.setType(type); pa.setProtocol(p); h.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(12L); p = this.vocab.getProtocol("another treatment", src); p.setDescription("another treatment desc"); type = this.vocab.getTerm(src, "treatment"); p.setType(type); pa.setProtocol(p); h.getProtocolApplications().add(pa); pa = new ProtocolApplication(); pa.setId(13L); p = this.vocab.getProtocol("some growth", src); p.setDescription("growth desc"); type = this.vocab.getTerm(src, "growth"); p.setType(type); pa.setProtocol(p); h.getProtocolApplications().add(pa); final RawArrayData rawData = new RawArrayData(); pa = new ProtocolApplication(); pa.setId(14L); rawData.setName("raw-array-data"); rawData.getHybridizations().add(h); p = this.vocab.getProtocol("data processing", src); p.setDescription("data proc desc"); pa.setProtocol(p); rawData.getProtocolApplications().add(pa); final CaArrayFile rawCaArrayFile = this.fasStub.add(this.rawFile); rawCaArrayFile.setUncompressedSize(TEST_DATA.getBytes().length); rawCaArrayFile.setName("raw_file.data"); rawCaArrayFile.setFileStatus(FileStatus.IMPORTED); rawData.setDataFile(rawCaArrayFile); h.getRawDataCollection().add(rawData); final DerivedArrayData d = new DerivedArrayData(); final CaArrayFile derCaArrayFile = this.fasStub.add(this.derivedFile); derCaArrayFile.setFileType(AFFYMETRIX_CHP); derCaArrayFile.setName("derived_file.data"); derCaArrayFile.setCompressedSize(1024); derCaArrayFile.setUncompressedSize(TEST_DATA.getBytes().length); derCaArrayFile.setFileStatus(FileStatus.IMPORTED); d.setDataFile(derCaArrayFile); h.getDerivedDataCollection().add(d); final CaArrayFile suppCaArrayFile = this.fasStub.add(this.supplementalFile); suppCaArrayFile.setName("supplimental.data"); suppCaArrayFile.setCompressedSize(1024); suppCaArrayFile.setUncompressedSize(TEST_DATA.getBytes().length); suppCaArrayFile.setFileStatus(FileStatus.IMPORTED); final Field supplementalFilesField = Project.class.getDeclaredField("supplementalFiles"); supplementalFilesField.setAccessible(true); final SortedSet<CaArrayFile> supplementalFiles = (SortedSet<CaArrayFile>) supplementalFilesField.get(prj); supplementalFiles.add(suppCaArrayFile); final Category ca = this.vocab.getCategory(src, "test-cat"); final UserDefinedCharacteristic cha = new UserDefinedCharacteristic(ca, "test-val", type); source.getCharacteristics().add(cha); final UserDefinedFactorValue fv = new UserDefinedFactorValue("test-value", type); final Factor fact = new Factor(); fact.setName("test-factor"); fv.setFactor(fact); h.getFactorValues().add(fv); lb.setTissueSite(this.vocab.getTerm(src, "some tissue site")); extract.setDiseaseState(this.vocab.getTerm(src, "some disease state")); source.setCellType(this.vocab.getTerm(src, "some cell type")); sample.setExternalId("test external id"); lb.getHybridizations().add(h); h.getLabeledExtracts().add(lb); return experiment; }
From source file:net.sourceforge.fenixedu.domain.degreeStructure.DegreeModule.java
public ExecutionSemester getMinimumExecutionPeriod() { if (isRoot()) { return isBolonhaDegree() ? getBeginBolonhaExecutionPeriod() : getFirstExecutionPeriodOfFirstExecutionDegree(); }//from w w w .j a v a 2s. co m final SortedSet<ExecutionSemester> executionSemesters = new TreeSet<ExecutionSemester>(); for (final Context context : getParentContextsSet()) { executionSemesters.add(context.getBeginExecutionPeriod()); } return executionSemesters.first(); }
From source file:net.big_oh.algorithms.search.informed.astar.AStarSearch.java
public AStarSearchResult<SearchNodeType> doSearch(SearchNodeType startNode) { Duration searchDuration = new Duration(); // create priority queue SortedSet<SearchNodeType> prioritySet = new TreeSet<SearchNodeType>(new Comparator<SearchNodeType>() { public int compare(SearchNodeType o1, SearchNodeType o2) { switch (searchType) { case MIN: return Double.compare(getF(o1), getF(o2)); case MAX: return -1 * Double.compare(getF(o1), getF(o2)); default: throw new RuntimeException("Unexpected search type: " + searchType); }/*from w w w. ja v a 2 s. c om*/ } }); // enqueue the start node prioritySet.add(startNode); // declare tracking member variables int numSearchNodesGenerated = 0; int numSearchNodesConsidered = 0; int maxPossibleBranchingFactor = 1; // search for a goal state SearchNodeType goalNode = null; while (!prioritySet.isEmpty()) { // Remove the best candidate node from the queue SearchNodeType candidateSearchNode = prioritySet.first(); prioritySet.remove(candidateSearchNode); numSearchNodesConsidered++; // get the next search node candidates Collection<SearchNodeType> nextSearchNodes = nextNodesGenerator.getNextSearchNodes(candidateSearchNode); // do some record keeping numSearchNodesGenerated += nextSearchNodes.size(); maxPossibleBranchingFactor = Math.max(maxPossibleBranchingFactor, nextSearchNodes.size()); if (candidateSearchNode.isGoalState()) { // sanity check assert (nextSearchNodes.isEmpty()); // found an optimal solution goalNode = candidateSearchNode; break; } else { // enqueue all next search nodes Duration enqueueDuration = new Duration(); prioritySet.addAll(nextSearchNodes); if (logger.isDebugEnabled()) { logger.debug("Enqueued " + nextSearchNodes.size() + " A* search nodes in " + enqueueDuration.stop() + " milliseconds."); } } } // return the search results AStarSearchResult<SearchNodeType> results = new AStarSearchResult<SearchNodeType>(goalNode, numSearchNodesGenerated, calculateEffectiveBranchingFactor(goalNode.getNodeDepth(), numSearchNodesConsidered, maxPossibleBranchingFactor)); logger.debug("Completed an A* search in " + searchDuration.stop() + " milliseconds."); logger.debug("Number of nodes generated: " + results.getNumSearchNodesGenerated()); logger.debug("Depth of goal node: " + results.getGoalNode().getNodeDepth()); logger.debug("Effective branching factor: " + results.getEfectiveBranchingFactor()); return results; }
From source file:com.redhat.rhn.common.localization.LocalizationService.java
/** * Get a list of available prefixes and ensure that it is sorted by * returning a SortedSet object./*ww w .j a v a 2 s. c o m*/ * @return SortedSet sorted set of available prefixes. */ public SortedSet<String> availablePrefixes() { SelectMode prefixMode = ModeFactory.getMode("util_queries", "available_prefixes"); // no params for this query DataResult<Map<String, Object>> dr = prefixMode.execute(new HashMap()); SortedSet<String> ret = new TreeSet<String>(); Iterator<Map<String, Object>> i = dr.iterator(); while (i.hasNext()) { Map<String, Object> row = i.next(); ret.add((String) row.get("prefix")); } return ret; }
From source file:com.google.wave.splash.text.ContentRenderer.java
/** * Takes content and applies style and formatting to it based on its * annotations and elements./*w ww . j a v a 2s . c o m*/ * * @param content the content * @param annotations the annotations * @param elements the elements * @param contributors the contributors * @return the string */ public String renderHtml(final String content, final Annotations annotations, final SortedMap<Integer, Element> elements, final List<String> contributors) { final StringBuilder builder = new StringBuilder(); // NOTE(dhanji): This step is enormously important! final char[] raw = content.toCharArray(); final SortedSet<Marker> markers = new TreeSet<Marker>(); // First add annotations sorted by range. for (final Annotation annotation : annotations.asList()) { // Ignore anything but style or title annotations. final String annotationName = annotation.getName(); if (annotationName.startsWith("style")) { markers.add(Marker.fromAnnotation(annotation, annotation.getRange().getStart(), false)); markers.add(Marker.fromAnnotation(annotation, annotation.getRange().getEnd(), true)); } else if (annotationName.startsWith("link")) { markers.add(Marker.fromAnnotation(annotation, annotation.getRange().getStart(), false)); markers.add(Marker.fromAnnotation(annotation, annotation.getRange().getEnd(), true)); } else if ("conv/title".equals(annotationName)) { // Find the first newline and make sure the annotation only gets to that // point. final int start = annotation.getRange().getStart(); final int from = raw[0] == '\n' ? 1 : 0; final int end = content.indexOf('\n', from); if (end > start && start < end) { // Commented (vjrj) // final Annotation title = new Annotation(Annotation.FONT_WEIGHT, // "bold", start, end); // markers.add(Marker.fromAnnotation(title, start, false)); // markers.add(Marker.fromAnnotation(title, end, true)); } else { // LOG? } } } // Now add elements sorted by index. for (final Map.Entry<Integer, Element> entry : elements.entrySet()) { markers.add(Marker.fromElement(entry.getValue(), entry.getKey())); } builder.append("<p>"); int cursor = 0; for (final Marker marker : markers) { if (marker.index > cursor) { final int to = Math.min(raw.length, marker.index); builder.append(Markup.sanitize(new String(raw, cursor, to - cursor))); } cursor = marker.index; if (marker.isElement()) { renderElement(marker.element, marker.index, contributors, builder); } else { emitAnnotation(marker, builder); } } // add any tail bits if (cursor < raw.length - 1) { builder.append(Markup.sanitize(new String(raw, cursor, raw.length - cursor))); } // Replace empty paragraphs. (TODO expensive and silly) return builder.append("</ul>").toString().replaceAll("<p>\n</p>", "<p><br/></p>") .replaceAll("<p>\n<div style=\"font-size", "<p><br/><div style=\"font-size"); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewHomepageDA.java
public ActionForward listStudents(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final SortedMap<Degree, SortedSet<Homepage>> homepages = new TreeMap<Degree, SortedSet<Homepage>>( Degree.COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID); for (final Registration registration : rootDomainObject.getRegistrationsSet()) { final StudentCurricularPlan studentCurricularPlan = registration.getActiveStudentCurricularPlan(); if (studentCurricularPlan != null) { final DegreeCurricularPlan degreeCurricularPlan = studentCurricularPlan.getDegreeCurricularPlan(); final Degree degree = degreeCurricularPlan.getDegree(); final Person person = registration.getPerson(); final SortedSet<Homepage> degreeHomepages; if (homepages.containsKey(degree)) { degreeHomepages = homepages.get(degree); } else { degreeHomepages = new TreeSet<Homepage>(Homepage.HOMEPAGE_COMPARATOR_BY_NAME); homepages.put(degree, degreeHomepages); }/*from ww w . j av a 2 s. c o m*/ final Homepage homepage = person.getHomepage(); if (homepage != null && homepage.getActivated().booleanValue()) { degreeHomepages.add(homepage); } } } request.setAttribute("homepages", homepages); final String selectedPage = request.getParameter("selectedPage"); if (selectedPage != null) { request.setAttribute("selectedPage", selectedPage); } return mapping.findForward("list-homepages-students"); }