List of usage examples for java.util Calendar before
public boolean before(Object when)
Calendar
represents a time before the time represented by the specified Object
. From source file:com.ecofactor.qa.automation.newapp.service.DataServiceImpl.java
/** * Verify temperature changes in range data. * /* ww w . j av a 2s. c o m*/ * @param thermostatId * the thermostat id * @param algoId * the algo id * @param temperature * the temperature * @see com.ecofactor.qa.automation.algorithm.service.DataService#verifyTemperatureChangesInRangeData(int, * java.lang.String, double) */ @Override public void verifyTemperatureChangesInRangeData(int thermostatId, int algoId, double temperature) { DriverConfig.setLogString("Verify temperature changes in range data table for thermostat : " + thermostatId + ", Temperature : " + temperature, true); PartitionedThermostatRangeData rangeData = null; boolean eventProcessed = false; Calendar currentTime = DateUtil.getUTCCalendar(); Calendar endTime = DateUtil.getUTCCalendar(); endTime.add(Calendar.MINUTE, 15); Algorithm algorithm = algorithmDao.findById(algoId); DriverConfig.setLogString("Wait for Thermostat set point change in range data : " + thermostatId + ", Action : " + algorithm.getAction() + ". (Current Time : " + DateUtil.format(currentTime, DateUtil.DATE_FMT) + " Wait for maximum until : " + DateUtil.format(endTime, DateUtil.DATE_FMT) + ")", true); do { mediumWait(); rangeData = thermostatRangeDataDao.findLatestByThermostat(thermostatId); if (rangeData != null) { if (algorithm.getAction().equalsIgnoreCase("cool_setting")) { if (rangeData.getCoolSetting() != null && temperature == rangeData.getCoolSetting()) { eventProcessed = true; } } else { if (rangeData.getHeatSetting() != null && temperature == rangeData.getHeatSetting()) { eventProcessed = true; } } } if (eventProcessed) { break; } currentTime = DateUtil.getUTCCalendar(); } while (currentTime.before(endTime)); Assert.assertTrue(eventProcessed, "Temperature change issue in range data for thermostat : " + thermostatId); }
From source file:org.kuali.kfs.coa.businessobject.Account.java
/** * This method determines whether the account is expired or not. Note that if Expiration Date is the same date as testDate, then * this will return false. It will only return true if the account expiration date is one day earlier than testDate or earlier. * Note that this logic ignores all time components when doing the comparison. It only does the before/after comparison based on * date values, not time-values./*from ww w .j a v a2 s.c om*/ * * @param testDate - Calendar instance with the date to test the Account's Expiration Date against. This is most commonly set to * today's date. * @return true or false based on the logic outlined above */ @Override public boolean isExpired(Calendar testDate) { if (LOG.isDebugEnabled()) { LOG.debug("entering isExpired(" + testDate + ")"); } // dont even bother trying to test if the accountExpirationDate is null if (accountExpirationDate == null) { return false; } // remove any time-components from the testDate testDate = DateUtils.truncate(testDate, Calendar.DAY_OF_MONTH); // get a calendar reference to the Account Expiration // date, and remove any time components Calendar acctDate = Calendar.getInstance(); acctDate.setTime(this.accountExpirationDate); acctDate = DateUtils.truncate(acctDate, Calendar.DAY_OF_MONTH); // if the Account Expiration Date is before the testDate return acctDate.before(testDate); }
From source file:com.square.tarificateur.noyau.service.implementations.TarificateurEditiqueServiceImpl.java
/** * Dtermine le dlai de stage.//w ww . ja v a 2 s .com * @param personne la personne concerne par le dlai de stage * @return true si le dlai de stage est appliqu, false sinon */ private boolean calculerDelaiDeStage(Personne personne) { final Calendar dateNaissance = (Calendar) personne.getDateNaissance().clone(); final boolean personneCouverteActuellement = personne.getActuellementCouvert(); final boolean personneCouverteSixDerniersMois = personne.getCouvertSixDerniersMois(); // CALCULE DE L'AGE CALENDAIRE DE L'ASSURE final Calendar toDay = Calendar.getInstance(); int age = toDay.get(Calendar.YEAR) - dateNaissance.get(Calendar.YEAR); dateNaissance.add(Calendar.YEAR, age); if (toDay.before(dateNaissance)) { age--; } boolean delaiDeStage; if (age >= tarificateurSquareMappingService.getConstanteAdhesionAgeMiniDelaiStage().intValue()) { // Si la personne a 65 ans ou plus, le dlais de stage ne s'applique pas que si couvertActuellement et pas couvert 6 derniers mois delaiDeStage = !(personneCouverteActuellement && !personneCouverteSixDerniersMois); } else { // Si la personne a moins de 65 ans, le dlais de stage ne s'applique que si couvertActuellement et couvert 6 derniers mois, // ou si pas couvertActuellement et couvert 6 derniers mois delaiDeStage = (personneCouverteActuellement && personneCouverteSixDerniersMois) || (!personneCouverteActuellement && personneCouverteSixDerniersMois); } logger.debug(messageSourceUtil.get(MessageKeyUtil.LOGGER_DEBUG_DELAIS_STAGE, new String[] { String.valueOf(age), personneCouverteActuellement ? messageSourceUtil.get(MessageKeyUtil.MESSAGE_OUI) : messageSourceUtil.get(MessageKeyUtil.MESSAGE_NON), personneCouverteSixDerniersMois ? messageSourceUtil.get(MessageKeyUtil.MESSAGE_OUI) : messageSourceUtil.get(MessageKeyUtil.MESSAGE_NON), delaiDeStage ? messageSourceUtil.get(MessageKeyUtil.MESSAGE_OUI) : messageSourceUtil.get(MessageKeyUtil.MESSAGE_NON) })); return delaiDeStage; }
From source file:grupob.TipoProceso.java
private void cargarDatosLocal() { tableModel = new LocalTableModel(); tblLocal.setModel(tableModel);/*w w w.j a v a 2 s . com*/ /* DefaultTableModel modelo = (DefaultTableModel)jTable8.getModel(); listaLocales = Manager.queryAllLocales(); modelo.setRowCount(0); String datos[] = new String[4]; for (int i = 0; i < listaLocales.size(); i++) { datos[0] = listaLocales.get(i).getNombre(); if(listaLocales.get(i).getCantidadVotantesRegistrados() == 0){ datos[1] =""; }else{ datos[1] = Long.toString(listaLocales.get(i).getCantidadVotantesRegistrados()); } datos[2] = Integer.toString(listaLocales.get(i).getIdDistrito()); // datos[3] = Integer.toString(listaLocales.get(i).getIdTipo()); modelo.addRow(datos); } TableColumn colum1 = null; colum1 = jTable8.getColumnModel().getColumn(0); colum1.setPreferredWidth(40); TableColumn colum2 = null; colum2 = jTable8.getColumnModel().getColumn(1); colum2.setPreferredWidth(5); TableColumn colum3 = null; colum3 = jTable8.getColumnModel().getColumn(2); colum3.setPreferredWidth(40); TableColumn colum4 = null; colum4 = jTable8.getColumnModel().getColumn(3); colum4.setPreferredWidth(40); colum3.setPreferredWidth(10); */ // jTable8.getColumn("Region").setCellEditor(new ComboBoxEditor()); TipoProcesoVotacion tipoLocal = Manager.queryProcesoById(4); Calendar cal = Calendar.getInstance(); Date dateActual = cal.getTime(); if (tipoLocal != null && tipoLocal.getId() != 0) { if (!tipoLocal.getFechaInicio2().after(dateActual)) { dpFechaInicio1Local.setDate(tipoLocal.getFechaInicio1().getTime()); dpFechaInicio2Local.setDate(tipoLocal.getFechaInicio2().getTime()); dpFechaFin1Local.setDate(tipoLocal.getFechaFin1().getTime()); dpFechaFin2Local.setDate(tipoLocal.getFechaFin2().getTime()); txtPorcentajeLocal.setText("" + tipoLocal.getPorcentajeMinimo() * 100); } if ((tipoLocal.getFechaInicio1().before(dateActual)) && (cal.before(tipoLocal.getFechaFin2()))) { btnGuardarProcLocal.setEnabled(false); } if (tipoLocal.getFechaFin2().before(dateActual)) { btnGuardarProcLocal.setEnabled(false); } } TableColumn column = tblLocal.getColumnModel().getColumn(2); DistritoComboBox dist = new DistritoComboBox(); column.setCellEditor(dist); tblLocal.getColumnModel().getColumn(3).setCellRenderer(new ButtonEliminarLocales()); tblLocal.getColumnModel().getColumn(3).setCellEditor(new ButtonEliminarLocales()); if (listaLocales != null) { // TableColumn column = jTable8.getColumnModel().getColumn(2); // column.setCellEditor(new DistritoComboBox()); /* jTable8.getColumn("Eliminar").setCellRenderer(new ButtonRenderer()); jTable8.getColumn("Eliminar").setCellEditor(new ButtonEliminarLocales(new JCheckBox()));*/ } }
From source file:grupob.TipoProceso.java
void initInstitucional() { TipoProcesoVotacion tipoInstitucional = Manager.queryProcesoById(5); Calendar cal = Calendar.getInstance(); Date dateActual = cal.getTime(); if (tipoInstitucional != null && tipoInstitucional.getId() != 0) { if (!tipoInstitucional.getFechaInicio2().after(dateActual)) { btn1FIInstitucional.setDate(tipoInstitucional.getFechaInicio1().getTime()); btn2FIInstitucional.setDate(tipoInstitucional.getFechaInicio2().getTime()); btn1FFInstitucional.setDate(tipoInstitucional.getFechaFin1().getTime()); btn2FFInstitucional.setDate(tipoInstitucional.getFechaFin2().getTime()); txtPorInstitucional.setText("" + tipoInstitucional.getPorcentajeMinimo() * 100); }/* w w w.j a v a 2s . com*/ if ((tipoInstitucional.getFechaInicio1().before(dateActual)) && (cal.before(tipoInstitucional.getFechaFin2()))) { btnGuardarInstitucionalTP.setEnabled(false); } if (tipoInstitucional.getFechaFin2().before(dateActual)) { btnGuardarInstitucionalTP.setEnabled(true); } } }
From source file:oscar.form.study.hsfo2.pageUtil.XMLTransferUtil.java
/** * this method in fact generate all xml for one patient. it all patient data and all visit datas to xml * /*from w w w . j a v a 2 s . com*/ * @param site * @param pd * @param baseLineVd * : the baseLine visit data, namely the initial patient data * @throws Exception */ public void addPatientToSite(Site site, Hsfo2Patient pd, Hsfo2Visit baseLineVd, Calendar startDate, Calendar endDate) { if (baseLineVd == null) baseLineVd = (new HSFODAO()).getPatientBaseLineVisitData(pd); //If the baseline form not completed if (baseLineVd == null) return; String startDateStr = String.valueOf(startDate.get(Calendar.YEAR)) + "-" + String.valueOf(startDate.get(Calendar.MONTH) + 1) + "-" + String.valueOf(startDate.get(Calendar.DATE)); String endDateStr = String.valueOf(endDate.get(Calendar.YEAR)) + "-" + String.valueOf(endDate.get(Calendar.MONTH) + 1) + "-" + String.valueOf(endDate.get(Calendar.DATE)); String dateString2 = dformat2.format(pd.getConsentDate()); //e.g. "2012-03-13" Date signedDate = getSignedDate(pd.getPatient_Id(), startDateStr, endDateStr); if (signedDate == null) return; String dateString1 = dformat1.format(signedDate); //e.g. "2012-03-13T08:48:50" final XmlCalendar when = new XmlCalendar(dateString1); final String who = getSignedProvider(pd.getPatient_Id(), startDateStr, endDateStr); XmlCalendar dob = new XmlCalendar(dformat2.format(pd.getBirthDate())); //final Calendar visitDate = ConvertUtil.dateToCalendar( baseLineVd.getVisitDate_Id() ); final XmlCalendar visitDate = new XmlCalendar(dformat2.format(baseLineVd.getVisitDate_Id())); // add patient SitePatient patient = site.addNewSitePatient(); patient.setEmrPatientKey(pd.getPatient_Id()); // DatConsentDate dcd = patient.addNewDatConsentDate(); // dcd.setValue(new XmlCalendar(dateString2)); // // dcd.setSignedWhen(when); // // dcd.setSignedWho(who); // // DatDropDate ddd = patient.addNewDatDropDate(); // ddd.setSignedWhen(when); // ddd.setSignedWho(who); // // TxtEmrHcpID tehid = patient.addNewTxtEmrHcpID(); // DemographicData demoData = new DemographicData(); // String providerId=demoData.getDemographic(patient.getEmrPatientKey()).getProviderNo(); // if (pd.getEmrHCPId() == null) // tehid.setValue(""); // else // tehid.setValue(pd.getEmrHCPId()); /* get EmrHcpId from demographic table, not hsfo_patient table */ // if (providerId == null) // tehid.setValue(""); // else // tehid.setValue(providerId); // tehid.setSignedWhen(when); // tehid.setSignedWho(who); // ---- Initial section (unnamed): 8 fields are obtained independently of HSF HMP forms. //8 fields for patient demographics and EmrHcpID (each minOccurs=?1? and maxOccurs=?1?): //These data are obtained independently of HFS HMP forms // Surname TxtSurname tsn = patient.addNewTxtSurname(); tsn.setValue(pd.getLName()); tsn.setSignedWhen(when); tsn.setSignedWho(who); // GivenNames TxtGivenNames tgn = patient.addNewTxtGivenNames(); tgn.setValue(pd.getFName()); tgn.setSignedWhen(when); tgn.setSignedWho(who); DatBirthDate dbd = patient.addNewDatBirthDate(); dbd.setValue(dob); dbd.setSignedWhen(when); dbd.setSignedWho(who); SelSex ss = patient.addNewSelSex(); String sex = pd.getSex(); if ("m".equalsIgnoreCase(sex)) ss.setValue(StringSex.MALE); else ss.setValue(StringSex.FEMALE); ss.setSignedWhen(when); ss.setSignedWho(who); // Txt_EmrHcpID { TxtEmrHcpID hcpID = patient.addNewTxtEmrHcpID(); if (pd.getEmrHCPId() == null) hcpID.setValue(""); else hcpID.setValue(pd.getEmrHCPId()); hcpID.setSignedWhen(when); hcpID.setSignedWho(who); } //Txt_PostalCode { TxtPostalCode tpcfsa = patient.addNewTxtPostalCode(); tpcfsa.setValue(ConvertUtil.toUpperCase(pd.getPostalCode())); tpcfsa.setSignedWhen(when); tpcfsa.setSignedWho(who); } // sel_HsfHmpStatus { SelHsfHmpStatus hsfHmpStatus = patient.addNewSelHsfHmpStatus(); String status = pd.getStatusInHmp(); if ("Enrolled".equalsIgnoreCase(status)) status = "Enrolled"; else if ("NotEnrolled".equalsIgnoreCase(status)) status = "NotEnrolled"; hsfHmpStatus.setValue(org.hsfo.v2.StringHsfHmpStatus.Enum.forString(status)); hsfHmpStatus.setSignedWhen(when); hsfHmpStatus.setSignedWho(who); } // dat_HsfHmpStatusDate { DatHsfHmpStatusDate hsfHmpStatusDate = patient.addNewDatHsfHmpStatusDate(); //hsfHmpStatusDate.setValue( ConvertUtil.dateToCalendar( pd.getDateOfHmpStatus() ) ); hsfHmpStatusDate.setValue(new XmlCalendar(dformat2.format(pd.getDateOfHmpStatus()))); hsfHmpStatusDate.setSignedWhen(when); hsfHmpStatusDate.setSignedWho(who); } // ----- form_HsfHmpFlowsheet_Baseline section ------ //The fields are from HSF HMP Baseline only: //These data are obtained only once, on HSF HMPs baseline form Calendar visitDateValue = Calendar.getInstance(); visitDateValue.setTime(baseLineVd.getVisitDate_Id()); if (visitDateValue.after(startDate) && visitDateValue.before(endDate)) { addBaseLineData(patient, pd, baseLineVd, when, who); } // ------form_HsfHmpFlowsheet section ------ // Fields from both HSF HMP Baseline and Follow-up: //These data are obtained repeatedly on HSF HMP forms, always on the baseline form //first and then again serially on any number of successive follow-up forms. //The effective date of these data is captured in the sections VisitDate_key? attribute. addAllPatientVisit(patient, pd.getPatient_Id(), startDateStr, endDateStr); // ----- Final section: Fields for patient medical diagnoses, family history, physical exam results and lab test ----- //These data are obtained either directly on HSF HMPs Baseline and Follow-up forms or //independently of HSF HMP forms at any number of other times during patient care. //Each of these data have a valueDate? attribute that captures the effective date of the //value? attribute, for example, the date when the lab test result was measured or the //the patient provided the answer, or the measurement on physical exam was taken. addAllPatientVisitFinalSection(patient, pd.getPatient_Id(), startDateStr, endDateStr, startDate, endDate, visitDateValue, visitDate, when, who); }
From source file:com.FFLive.MySQLConnection.java
public void addStatus(List<String> leagueIDs) { Main.log.log(4, "Adding/Updating leagues... "); try {/*from w w w . ja va 2 s . c o m*/ Fixtures fixture = new Fixtures(); fixture.loadFixtures(); int gw = Integer.parseInt(fixture.gameweek); //Set the correct gameweek on the front of the webpage Calendar now = Calendar.getInstance(); if (now.before(new DateParser(fixture.kickOff).convertDate())) { setWebFrontGW("index", gw - 1); } else { setWebFrontGW("index", gw); } //CREATE all the required Gameweek Leagues... createGWTables(gw); for (String leagueID : leagueIDs) { PreparedStatement preparedStmt = conn.prepareStatement( "INSERT INTO status (LeagueID, Gameweek, starts, kickOff, ends) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE starts = ?, kickOff = ?, ends = ?"); preparedStmt.setInt(1, Integer.parseInt(leagueID)); preparedStmt.setInt(2, gw); preparedStmt.setString(3, fixture.startTime); preparedStmt.setString(4, fixture.kickOff); preparedStmt.setString(5, fixture.endTime); preparedStmt.setString(6, fixture.startTime); preparedStmt.setString(7, fixture.kickOff); preparedStmt.setString(8, fixture.endTime); preparedStmt.executeUpdate(); preparedStmt.close(); } //Make previous week tables if (gw != 1) { int prevGW = gw - 1; Fixtures prevFixture = new Fixtures(prevGW); prevFixture.loadFixtures(); createGWTables(prevGW); for (String leagueID : leagueIDs) { PreparedStatement preparedStmt = conn.prepareStatement( "INSERT INTO status (LeagueID, Gameweek, starts, kickOff, ends) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE starts = ?, kickOff = ?, ends = ?"); preparedStmt.setInt(1, Integer.parseInt(leagueID)); preparedStmt.setInt(2, prevGW); preparedStmt.setString(3, prevFixture.startTime); preparedStmt.setString(4, prevFixture.kickOff); preparedStmt.setString(5, prevFixture.endTime); preparedStmt.setString(6, prevFixture.startTime); preparedStmt.setString(7, prevFixture.kickOff); preparedStmt.setString(8, prevFixture.endTime); preparedStmt.executeUpdate(); preparedStmt.close(); } } Main.log.log(4, "Ready!\n", 0); } catch (SQLException e) { Main.log.ln(1); Main.log.log(1, "Critical Error Updating Leagues and Making Tables.. " + e + "\n"); Main.log.log(9, e); System.exit(1006); } }
From source file:com.square.core.service.implementations.PersonnePhysiqueServiceImplementation.java
/** * Calcule l'ge d'une personne partir de sa date de naissance. * @param datedeNaissance la date de naissance de la personne. * @return l'age de la personne//w w w.j a v a 2s . c o m */ private int calculerAge(Calendar datedeNaissance) { final Calendar dateNaissanceClonee = (Calendar) datedeNaissance.clone(); final Calendar dateActuelle = Calendar.getInstance(); int age = dateActuelle.get(Calendar.YEAR) - dateNaissanceClonee.get(Calendar.YEAR); dateNaissanceClonee.add(Calendar.YEAR, age); if (dateActuelle.before(dateNaissanceClonee)) { age--; } return age; }
From source file:org.yccheok.jstock.analysis.StockHistoryOperator.java
public void calculate(StockHistoryServer stockHistoryServer) { boolean valid = true; if (startDate != null && this.endDate != null) { if (startDate.after(endDate)) { valid = false;/*from w w w . java 2 s. c o m*/ log.error("startDate " + startDate + " should not after endDate " + endDate); } } else { log.error("startDate or endDate cannot be null"); valid = false; } if (valid == false) { Object oldValue = this.value; this.value = null; if (Utils.equals(oldValue, value) == false) { this.firePropertyChange("value", oldValue, this.value); } return; } java.util.List<Stock> stocks = new java.util.ArrayList<Stock>(); // To be added to end of "stocks" later. java.util.List<Stock> tmpStocks = new java.util.ArrayList<Stock>(); java.util.List<Double> values = new java.util.ArrayList<Double>(); // For MFI usage. java.util.List<Double> highs = new java.util.ArrayList<Double>(); java.util.List<Double> lows = new java.util.ArrayList<Double>(); java.util.List<Double> closes = new java.util.ArrayList<Double>(); // TODO: CRITICAL LONG BUG REVISED NEEDED. java.util.List<Long> volumes = new java.util.ArrayList<Long>(); final Calendar startCalendar = Calendar.getInstance(); final Calendar endCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); endCalendar.setTime(endDate); // Not sure why there is time information in startDate. Reset it. org.yccheok.jstock.engine.Utils.resetCalendarTime(startCalendar); org.yccheok.jstock.engine.Utils.resetCalendarTime(endCalendar); int day = 0; /* Fill up stocks. */ while (true) { final long startTimestamp = startCalendar.getTimeInMillis(); Stock stock = stockHistoryServer.getStock(startTimestamp); if (stock != null) { tmpStocks.add(stock); day++; } if (startCalendar.get(Calendar.YEAR) == endCalendar.get(Calendar.YEAR) && startCalendar.get(Calendar.MONTH) == endCalendar.get(Calendar.MONTH) && startCalendar.get(Calendar.DATE) == endCalendar.get(Calendar.DATE)) { break; } startCalendar.add(Calendar.DAY_OF_MONTH, 1); } if (day == 0) { Object oldValue = this.value; this.value = null; if (Utils.equals(oldValue, value) == false) { this.firePropertyChange("value", oldValue, this.value); } return; } // We have correct "day" right now. // Reset. startCalendar.setTime(startDate); org.yccheok.jstock.engine.Utils.resetCalendarTime(startCalendar); int remainingHistorySize = Math.max(0, getRequiredHistorySize(day) - day); long oldestHistoryTimestamp = stockHistoryServer.getTimestamp(0); Calendar oldestHistoryCalendar = Calendar.getInstance(); oldestHistoryCalendar.setTimeInMillis(oldestHistoryTimestamp); while (remainingHistorySize > 0) { startCalendar.add(Calendar.DAY_OF_MONTH, -1); if (startCalendar.before(oldestHistoryCalendar)) { break; } final long startTimestamp = startCalendar.getTimeInMillis(); Stock stock = stockHistoryServer.getStock(startTimestamp); if (stock != null) { stocks.add(stock); remainingHistorySize--; } } // Oldest comes first. java.util.Collections.reverse(stocks); // Stocks fill up completely! stocks.addAll(tmpStocks); if (this.function == Function.MFI) { for (Stock stock : stocks) { values.add(TechnicalAnalysis.getTypicalPrice(stock)); highs.add(stock.getHighPrice()); lows.add(stock.getLowPrice()); closes.add(stock.getLastPrice()); volumes.add(stock.getVolume()); } } else { switch (this.type) { case PrevPrice: for (Stock stock : stocks) { values.add(stock.getPrevPrice()); } break; case OpenPrice: for (Stock stock : stocks) { values.add(stock.getOpenPrice()); } break; case HighPrice: for (Stock stock : stocks) { values.add(stock.getHighPrice()); } break; case LowPrice: for (Stock stock : stocks) { values.add(stock.getLowPrice()); } break; case LastPrice: for (Stock stock : stocks) { values.add(stock.getLastPrice()); } break; case TypicalPrice: for (Stock stock : stocks) { values.add(TechnicalAnalysis.getTypicalPrice(stock)); } break; case Volume: // ??? for (Stock stock : stocks) { values.add(new Double(stock.getVolume())); } break; case MarketCapital: values.add(new Double(stockHistoryServer.getMarketCapital())); break; case SharesIssued: values.add(new Double(stockHistoryServer.getSharesIssued())); break; default: assert (false); } } // if (this.function == Function.MFI) final int dataSize = values.size(); if (dataSize == 0) { Object oldValue = this.value; this.value = null; if (Utils.equals(oldValue, value) == false) { this.firePropertyChange("value", oldValue, this.value); } return; } // Do not use primitive. As we do not want to perform auto unboxing // on TechnicalAnalysis's returned value. It might be null. Double v = function == Function.Min ? Double.MAX_VALUE : 0.0; // Use tmp_v to prevent frequent boxing/unboxing operation. double tmp_v = v; switch (function) { case Max: for (Double _value : values) { tmp_v = Math.max(tmp_v, _value); } v = tmp_v; break; case Min: for (Double _value : values) { tmp_v = Math.min(tmp_v, _value); } v = tmp_v; break; case Average: v = average(values); break; case MeanDeviation: double average = 0; for (Double _value : values) { average = average + _value; } average = average / (double) dataSize; for (Double _value : values) { tmp_v = tmp_v + Math.abs(_value - average); } tmp_v = tmp_v / (double) dataSize; v = tmp_v; break; case RSI: v = TechnicalAnalysis.createRSI(values, day); break; case EMA: v = TechnicalAnalysis.createEMA(values, day); break; case MFI: v = TechnicalAnalysis.createMFI(highs, lows, closes, volumes, day); break; case MACD: v = TechnicalAnalysis.createMACDFix(values, day).outMACD; break; case MACDSignal: v = TechnicalAnalysis.createMACDFix(values, day).outMACDSignal; break; case MACDHist: v = TechnicalAnalysis.createMACDFix(values, day).outMACDHist; break; default: assert (false); } Object oldValue = this.value; this.value = v; if (Utils.equals(oldValue, value) == false) { this.firePropertyChange("value", oldValue, this.value); } }
From source file:oscar.form.study.hsfo2.pageUtil.XMLTransferUtil.java
public void addFinalSection(Hsfo2Visit baseLineVd, SitePatient patient, String patientId, Calendar startDate, Calendar endDate, Calendar visitDateValue, XmlCalendar visitDate, XmlCalendar when, String who) { if (visitDateValue.after(startDate) && visitDateValue.before(endDate)) { {//from ww w . j av a2 s . co m // sel_HtnDx_type String hdt = baseLineVd.getHtnDxType(); StringHtnDxType.Enum dxType = StringHtnDxType.X; if ("PrimaryHtn".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.PRIMARY_HTN; if ("ElevatedBpReadings".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.ELEVATED_BP_READINGS; else // if ("null".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.X; SelHtnDxType element = patient.addNewSelHtnDxType(); element.setValue(dxType); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Dyslipidemia BHxDyslipidemia element = patient.addNewBHxDyslipidemia(); element.setValue(baseLineVd.isDyslipid()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_DM BHxDM element = patient.addNewBHxDM(); element.setValue(baseLineVd.isDiabetes()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Kidney BHxKidney element = patient.addNewBHxKidney(); element.setValue(baseLineVd.isKidneyDis()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Obesity BHxObesity element = patient.addNewBHxObesity(); element.setValue(baseLineVd.isObesity()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_CHD BHxCHD element = patient.addNewBHxCHD(); element.setValue(baseLineVd.isCHD()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_StrokeTIA BHxStrokeTIA element = patient.addNewBHxStrokeTIA(); element.setValue(baseLineVd.isStroke_TIA()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Depression BHxDepression element = patient.addNewBHxDepression(); element.setValue(baseLineVd.isDepression()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Htn BFamHxHtn element = patient.addNewBFamHxHtn(); element.setValue(baseLineVd.isFamHx_Htn()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Dyslipidemia BFamHxDyslipidemia element = patient.addNewBFamHxDyslipidemia(); element.setValue(baseLineVd.isFamHx_Dyslipid()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_DM BFamHxDM element = patient.addNewBFamHxDM(); element.setValue(baseLineVd.isFamHx_Diabetes()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Kidney BFamHxKidney element = patient.addNewBFamHxKidney(); element.setValue(baseLineVd.isFamHx_KidneyDis()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Obesity BFamHxObesity element = patient.addNewBFamHxObesity(); element.setValue(baseLineVd.isFamHx_Obesity()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_CHD BFamHxCHD element = patient.addNewBFamHxCHD(); element.setValue(baseLineVd.isFamHx_CHD()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_StrokeTIA BFamHxStrokeTIA element = patient.addNewBFamHxStrokeTIA(); element.setValue(baseLineVd.isFamHx_Stroke_TIA()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Depression BFamHxDepression element = patient.addNewBFamHxDepression(); element.setValue(baseLineVd.isFamHx_Depression()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getSBP() > 0) { // cmp_BP CmpBP element = patient.addNewCmpBP(); element.setSystolic(Integer.valueOf(baseLineVd.getSBP())); element.setDiastolic(Integer.valueOf(baseLineVd.getDBP())); element.setAutoOfficeMonitor(toYesNo(baseLineVd.isMonitor())); element.setValueDate(visitDate); // FIXME:???? which value date to set?? element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getHeight() > 0) { // dbl_Height_cm double height = baseLineVd.getHeight(); String heightUnit = baseLineVd.getHeight_unit(); if ("inch".equalsIgnoreCase(heightUnit)) { // convert inch to cm height *= 2.54; } DblHeightCm element = patient.addNewDblHeightCm(); element.setValue(height); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getWeight() > 0) { // dbl_Weight_kg double weight = baseLineVd.getWeight(); String weightUnit = baseLineVd.getWeight_unit(); if ("lb".equalsIgnoreCase(weightUnit)) { // convert lb to kg weight *= 0.45359237; } DblWeightKg element = patient.addNewDblWeightKg(); element.setValue(weight); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getWaist() > 0) { // dbl_WaistCircumf_cm double waist = baseLineVd.getWaist(); String waistUnit = baseLineVd.getWaist_unit(); if ("inch".equalsIgnoreCase(waistUnit)) { // convert inch to cm waist *= 2.54; } DblWaistCircumfCm element = patient.addNewDblWaistCircumfCm(); element.setValue(waist); element.setSignedWhen(when); element.setSignedWho(who); element.setValueDate(visitDate); } } if (baseLineVd.getTC_HDL_LabresultsDate() != null) { final XmlCalendar labWorkSection1Date = new XmlCalendar( dformat2.format(baseLineVd.getTC_HDL_LabresultsDate())); Calendar labDate1 = Calendar.getInstance(); labDate1.setTime(baseLineVd.getTC_HDL_LabresultsDate()); if (labDate1.after(startDate) && labDate1.before(endDate)) { if (baseLineVd.getLDL() > 0) { // dbl_LDL_mM DblLDLMM element = patient.addNewDblLDLMM(); element.setValue(baseLineVd.getLDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getTC_HDL() > 0) { // dbl_TCtoHDL DblTCtoHDL element = patient.addNewDblTCtoHDL(); element.setValue(baseLineVd.getTC_HDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getHDL() > 0) { // dbl_HDL_mM DblHDLMM element = patient.addNewDblHDLMM(); element.setValue(baseLineVd.getHDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getTriglycerides() > 0) { // dbl_Triglycerides_mM DblTriglyceridesMM element = patient.addNewDblTriglyceridesMM(); element.setValue(baseLineVd.getTriglycerides()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } } } if (baseLineVd.getA1C_LabresultsDate() != null) { final XmlCalendar labWorkSection2Date = new XmlCalendar( dformat2.format(baseLineVd.getA1C_LabresultsDate())); Calendar labDate2 = Calendar.getInstance(); labDate2.setTime(baseLineVd.getA1C_LabresultsDate()); if (labDate2.after(startDate) && labDate2.before(endDate)) { if (baseLineVd.getA1C() > 0) { // dbl_A1C_fraction DblA1CFraction element = patient.addNewDblA1CFraction(); element.setValue(baseLineVd.getA1C() / 100); element.setValueDate(labWorkSection2Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getFBS() > 0) { // dbl_FBS_mM DblFBSMM element = patient.addNewDblFBSMM(); element.setValue(baseLineVd.getFBS()); element.setValueDate(labWorkSection2Date); element.setSignedWhen(when); element.setSignedWho(who); } } } if (baseLineVd.getEgfrDate() != null) { final XmlCalendar labWorkSection3Date = new XmlCalendar(dformat2.format(baseLineVd.getEgfrDate())); //final Calendar labWorkSection3Date = ConvertUtil.dateToCalendar( baseLineVd.getEgfrDate() ); //the UI use EGFR date Calendar labDate3 = Calendar.getInstance(); labDate3.setTime(baseLineVd.getEgfrDate()); if (labDate3.after(startDate) && labDate3.before(endDate)) { if (baseLineVd.getEgfr() > 0) { // int_eGFR_mLPerMin IntEGFRMLPerMin element = patient.addNewIntEGFRMLPerMin(); element.setValue(baseLineVd.getEgfr()); element.setValueDate(labWorkSection3Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getAcr() > 0) { // dbl_ACR_mgPermmol DblACRMgPermmol element = patient.addNewDblACRMgPermmol(); element.setValue(baseLineVd.getAcr()); element.setValueDate(labWorkSection3Date); element.setSignedWhen(when); element.setSignedWho(who); } // HsfSiteCode_key } } }