List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:de.innovationgate.utils.WGUtils.java
/** * Converts any number to a BigDecimal, suited for comparison and (monetary) arithmetic. * This class uses conversions that avoid rounding errors by forced conversion for the * Number types from JRE. Fallback for other types is to convert them to Double. * @param n The number/*w w w .ja va 2s.co m*/ */ public static BigDecimal toBigDecimal(Number n) { if (n instanceof BigDecimal) { return (BigDecimal) n; } if (n instanceof Long) { return new BigDecimal((Long) n); } else if (n instanceof Integer) { return new BigDecimal((Integer) n); } else if (n instanceof Float) { return new BigDecimal((Float) n); } else if (n instanceof Double) { return new BigDecimal((Double) n); } else if (n instanceof Short) { return new BigDecimal((Short) n); } else if (n instanceof Byte) { return new BigDecimal((Byte) n); } else if (n instanceof BigInteger) { return new BigDecimal((BigInteger) n); } else if (n instanceof AtomicInteger) { return new BigDecimal(n.intValue()); } else if (n instanceof AtomicLong) { return new BigDecimal(n.longValue()); } else { return new BigDecimal(n.doubleValue()); } }
From source file:net.pms.util.Rational.java
/** * Compares this {@link Rational} by value with any class implementing * {@link Number}./*from www . ja v a2s . c o m*/ * <p> * This method is provided in preference to individual methods for each of * the six boolean comparison operators ({@literal <}, ==, {@literal >}, * {@literal >=}, !=, {@literal <=}). The suggested idiom for performing * these comparisons is: {@code (x.compareTo(y)} <<i>op</i>> * {@code 0)}, where <<i>op</i>> is one of the six comparison * operators. * <p> * <b>Note:</b> {@code NaN} can't be compared by value and is considered * greater than anything but itself as defined for {@link Double}. * * @param number the {@link Number} to which this {@link Rational}'s value * is to be compared. * @return A negative integer, zero, or a positive integer as this * {@link Rational} is numerically less than, equal to, or greater * than {@code number}. */ public int compareTo(@Nonnull Number number) { // Establish special cases boolean numberIsNaN; boolean numberIsInfinite; int numberSignum; if (number instanceof Rational) { numberIsNaN = Rational.isNaN((Rational) number); numberIsInfinite = Rational.isInfinite((Rational) number); numberSignum = ((Rational) number).numerator.signum(); } else if (number instanceof Float) { numberIsNaN = Float.isNaN(number.floatValue()); numberIsInfinite = Float.isInfinite(number.floatValue()); numberSignum = (int) Math.signum(number.floatValue()); } else if (number instanceof Double) { numberIsNaN = Double.isNaN(number.doubleValue()); numberIsInfinite = Double.isInfinite(number.doubleValue()); numberSignum = (int) Math.signum(number.doubleValue()); } else { numberIsNaN = false; numberIsInfinite = false; long l = number.longValue(); numberSignum = l == 0 ? 0 : l > 0 ? 1 : -1; } // NaN comparison is done according to the rules for Double. if (isNaN()) { return numberIsNaN ? 0 : 1; } if (numberIsNaN) { return -1; } if (isInfinite()) { if (numberIsInfinite) { return signum() - numberSignum; } return this.signum(); } if (numberIsInfinite) { return -numberSignum; } // List known integer types for faster and more accurate comparison if (number instanceof BigInteger) { if (isInteger()) { return bigIntegerValue().compareTo((BigInteger) number); } return bigDecimalValue(2, RoundingMode.HALF_EVEN).compareTo(new BigDecimal((BigInteger) number)); } if (number instanceof AtomicInteger || number instanceof AtomicLong || number instanceof Byte || number instanceof Integer || number instanceof Long || number instanceof Short) { if (isInteger()) { return bigIntegerValue().compareTo(BigInteger.valueOf(number.longValue())); } return bigDecimalValue(2, RoundingMode.HALF_EVEN).compareTo(new BigDecimal(number.longValue())); } if (number instanceof BigDecimal) { Rational other = valueOf((BigDecimal) number); return compareTo(other); } return bigDecimalValue().compareTo(new BigDecimal(number.doubleValue())); }
From source file:org.opencastproject.serviceregistry.impl.ServiceRegistryJpaImpl.java
/** * {@inheritDoc}//from w ww .j ava2 s . c o m * * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getServiceStatistics() */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<ServiceStatistics> getServiceStatistics() throws ServiceRegistryException { EntityManager em = null; try { em = emf.createEntityManager(); Query query = em.createNamedQuery("ServiceRegistration.statistics"); Map<ServiceRegistration, JaxbServiceStatistics> statsMap = new HashMap<ServiceRegistration, JaxbServiceStatistics>(); List queryResults = query.getResultList(); for (Object result : queryResults) { Object[] oa = (Object[]) result; ServiceRegistrationJpaImpl serviceRegistration = ((ServiceRegistrationJpaImpl) oa[0]); Status status = ((Status) oa[1]); Number count = (Number) oa[2]; Number meanQueueTime = (Number) oa[3]; Number meanRunTime = (Number) oa[4]; // The statistics query returns a cartesian product, so we need to iterate over them to build up the objects JaxbServiceStatistics stats = statsMap.get(serviceRegistration); if (stats == null) { stats = new JaxbServiceStatistics(serviceRegistration); statsMap.put(serviceRegistration, stats); } // the status will be null if there are no jobs at all associated with this service registration if (status != null) { switch (status) { case RUNNING: stats.setRunningJobs(count.intValue()); break; case QUEUED: case DISPATCHING: stats.setQueuedJobs(count.intValue()); break; case FINISHED: stats.setMeanRunTime(meanRunTime.longValue()); stats.setMeanQueueTime(meanQueueTime.longValue()); stats.setFinishedJobs(count.intValue()); break; default: break; } } } // Make sure we also include the services that have no processing history so far List<ServiceRegistration> services = em.createNamedQuery("ServiceRegistration.getAll").getResultList(); for (ServiceRegistration s : services) { if (!statsMap.containsKey(s)) statsMap.put(s, new JaxbServiceStatistics((ServiceRegistrationJpaImpl) s)); } List<ServiceStatistics> stats = new ArrayList<ServiceStatistics>(statsMap.values()); Collections.sort(stats, new Comparator<ServiceStatistics>() { @Override public int compare(ServiceStatistics o1, ServiceStatistics o2) { ServiceRegistration reg1 = o1.getServiceRegistration(); ServiceRegistration reg2 = o2.getServiceRegistration(); int typeComparison = reg1.getServiceType().compareTo(reg2.getServiceType()); return typeComparison == 0 ? reg1.getHost().compareTo(reg2.getHost()) : typeComparison; } }); return stats; } catch (Exception e) { throw new ServiceRegistryException(e); } finally { if (em != null) em.close(); } }
From source file:uk.ac.diamond.scisoft.analysis.dataset.AbstractDataset.java
/** * Sets the error for the dataset to a single value for all points in the dataset * @param errorValue The error value for all elements of the dataset *//* w w w . ja v a 2 s . c o m*/ public void setError(Number errorValue) { this.errorData = null; if (errorValue instanceof Integer) { this.errorValue = errorValue.intValue() * errorValue.intValue(); return; } if (errorValue instanceof Float) { this.errorValue = errorValue.floatValue() * errorValue.floatValue(); return; } if (errorValue instanceof Long) { this.errorValue = errorValue.longValue() * errorValue.longValue(); return; } if (errorValue instanceof Short) { this.errorValue = errorValue.intValue() * errorValue.intValue(); return; } if (errorValue instanceof Byte) { this.errorValue = errorValue.intValue() * errorValue.intValue(); return; } // If all else fails this.errorValue = errorValue.doubleValue() * errorValue.doubleValue(); return; }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * /*from w w w . j ava 2 s . c om*/ * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }
From source file:org.patientview.radar.dao.impl.PatientDaoImpl.java
public void save(final Patient patient) { // Sex fix//from w w w. j a va2 s .c om if (patient.getSexModel() != null) { if (patient.getSexModel().getType().equalsIgnoreCase("male")) { patient.setSex("M"); } else if (patient.getSexModel().getType().equalsIgnoreCase("female")) { patient.setSex("F"); } } // If we have an ID then update, otherwise insert new and set the ID if (patient.hasValidId()) { jdbcTemplate.update( "UPDATE patient SET " + "rrNo = ?, " + "dateReg = ?, " + "nhsno = ?, " + "nhsNoType = ?, " + "hospitalnumber = ?, " + "uktNo = ?, " + "surname = ?, " + "surnameAlias = ?, " + "forename = ?, " + "dateofbirth = ?, " + "AGE = ?, " + "SEX = ?, " + "ethnicGp = ?, " + "address1 = ?, " + "address2 = ?, " + "address3 = ?, " + "address4 = ?, " + "POSTCODE = ?, " + "postcodeOld = ?," + "CONSENT = ?, " + "dateBapnReg = ?, " + "consNeph = ?, " + "STATUS = ?, " + "emailAddress = ?, " + "telephone1 = ?, " + "telephone2 = ?, " + "mobile = ?, " + "rrtModality = ?, " + "genericDiagnosis = ?, " + "dateOfGenericDiagnosis = ?, " + "otherClinicianAndContactInfo = ?, " + "comments = ?, " + "republicOfIrelandId = ?, " + "isleOfManId = ?, " + "channelIslandsId = ?, " + "indiaId = ?, " + "radarConsentConfirmedByUserId = ?, " + "generic = ?, " + "patientLinkId = ? " + " WHERE id = ?", patient.getRrNo(), patient.getDateReg(), patient.getNhsno(), patient.getNhsNumberType() != null ? patient.getNhsNumberType().getId() : 1, patient.getHospitalnumber(), patient.getUktNo(), patient.getSurname(), patient.getSurnameAlias(), patient.getForename(), patient.getDob() != null ? new SimpleDateFormat(DATE_FORMAT).format(patient.getDob()) : null, patient.getAge(), patient.getSex(), patient.getEthnicity() != null ? patient.getEthnicity().getCode() : null, patient.getAddress1(), patient.getAddress2(), patient.getAddress3(), patient.getAddress4(), patient.getPostcode(), patient.getPostcodeOld(), patient.isConsent(), patient.getDateReg(), patient.getClinician() != null ? patient.getClinician().getId() : null, patient.getStatusModel() != null ? patient.getStatusModel().getId() : null, patient.getEmailAddress(), patient.getTelephone1(), patient.getTelephone2(), patient.getMobile(), patient.getRrtModalityEunm() != null ? patient.getRrtModalityEunm().getId() : null, patient.getGenericDiagnosisModel() != null ? patient.getGenericDiagnosisModel().getId() : null, patient.getDateOfGenericDiagnosis(), patient.getOtherClinicianAndContactInfo(), patient.getComments(), patient.getRepublicOfIrelandId(), patient.getIsleOfManId(), patient.getChannelIslandsId(), patient.getIndiaId(), patient.getRadarConsentConfirmedByUserId(), patient.isGeneric(), patient.getPatientLinkId() == null ? null : patient.getPatientLinkId(), patient.getId()); } else { Number id = patientInsert.executeAndReturnKey(new HashMap<String, Object>() { { put("rrNo", patient.getRrNo()); put("dateReg", patient.getDateReg()); put("nhsno", patient.getNhsno()); put("nhsNoType", patient.getNhsNumberType() != null ? patient.getNhsNumberType().getId() : null); put("hospitalnumber", patient.getHospitalnumber()); put("uktNo", patient.getUktNo()); put("surname", patient.getSurname()); put("surnameAlias", patient.getSurnameAlias()); put("forename", patient.getForename()); put("dateofbirth", patient.getDob() != null ? new SimpleDateFormat(DATE_FORMAT).format(patient.getDob()) : null); put("AGE", patient.getAge()); put("SEX", patient.getSex()); put("ethnicGp", patient.getEthnicity() != null ? patient.getEthnicity().getCode() : null); put("address1", patient.getAddress1()); put("address2", patient.getAddress2()); put("address3", patient.getAddress3()); put("address4", patient.getAddress4()); put("POSTCODE", patient.getPostcode()); put("postcodeOld", patient.getPostcodeOld()); put("CONSENT", patient.isConsent()); put("dateBapnReg", null); put("consNeph", patient.getClinician() != null ? patient.getClinician().getId() : null); put("unitcode", patient.getUnitcode() != null ? patient.getUnitcode() : patient.getRenalUnit().getUnitCode()); put("STATUS", patient.getStatusModel() != null ? patient.getStatusModel().getId() : null); put("emailAddress", patient.getEmailAddress()); put("telephone1", patient.getTelephone1()); put("telephone2", patient.getTelephone2()); put("mobile", patient.getMobile()); put("rrtModality", patient.getRrtModalityEunm() != null ? patient.getRrtModalityEunm().getId() : null); put("genericDiagnosis", patient.getGenericDiagnosisModel() != null ? patient.getGenericDiagnosisModel().getId() : null); put("dateOfGenericDiagnosis", patient.getDateOfGenericDiagnosis()); put("otherClinicianAndContactInfo", patient.getOtherClinicianAndContactInfo()); put("comments", patient.getComments()); put("republicOfIrelandId", patient.getRepublicOfIrelandId()); put("isleOfManId", patient.getIsleOfManId()); put("channelIslandsId", patient.getChannelIslandsId()); put("indiaId", patient.getIndiaId()); put("generic", patient.isGeneric()); put("radarConsentConfirmedByUserId", patient.getRadarConsentConfirmedByUserId()); put("sourceType", SourceType.RADAR.getName()); put("patientLinkId", patient.getPatientLinkId() == null ? null : patient.getPatientLinkId()); } }); patient.setId(id.longValue()); //The id of the patient record is now the new radar number Long radarNumber = getNextRadarNumber(); jdbcTemplate.update("UPDATE patient set radarNo = ? WHERE id = ? ", radarNumber, id.longValue()); patient.setRadarNo(radarNumber); // Sex fix if (patient.getSexModel() != null) { if (patient.getSexModel().getType().equalsIgnoreCase("m")) { patient.setSex("Male"); } else if (patient.getSexModel().getType().equalsIgnoreCase("f")) { patient.setSex("Female"); } } } }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private AbstractDataset getTimeSeriesCollectionDataset(Report report) { List<Stat> reportData = report.getReportData(); // fill dataset TimeSeriesCollection dataSet = new TimeSeriesCollection(); String dataSource = report.getReportDefinition().getReportParams().getHowChartSource(); String seriesFrom = report.getReportDefinition().getReportParams().getHowChartSeriesSource(); if (StatsManager.T_TOTAL.equals(seriesFrom) || StatsManager.T_NONE.equals(seriesFrom)) { seriesFrom = null;/*from w ww .j a va2 s . c o m*/ } Class periodGrouping = null; if (StatsManager.CHARTTIMESERIES_DAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod()) || StatsManager.CHARTTIMESERIES_WEEKDAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Day.class; } else if (StatsManager.CHARTTIMESERIES_MONTH .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Month.class; } else if (StatsManager.CHARTTIMESERIES_YEAR .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Year.class; } boolean visitsTotalsChart = ReportManager.WHAT_VISITS_TOTALS .equals(report.getReportDefinition().getReportParams().getWhat()) || report.getReportDefinition().getReportParams().getHowTotalsBy().contains(StatsManager.T_VISITS) || report.getReportDefinition().getReportParams().getHowTotalsBy() .contains(StatsManager.T_UNIQUEVISITS); Set<RegularTimePeriod> keys = new HashSet<RegularTimePeriod>(); if (!visitsTotalsChart && seriesFrom == null) { // without additional series String name = msgs.getString("th_total"); TimeSeries ts = new TimeSeries(name, periodGrouping); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } dataSet.addSeries(ts); } else if (!visitsTotalsChart && seriesFrom != null) { // with additional series Map<Comparable, TimeSeries> series = new HashMap<Comparable, TimeSeries>(); //TimeSeries ts = new TimeSeries(dataSource, org.jfree.data.time.Day.class); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); Comparable serie = (Comparable) getStatValue(s, seriesFrom); if (key != null && serie != null) { // determine appropriate serie TimeSeries ts = null; if (!series.containsKey(serie)) { ts = new TimeSeries(serie.toString(), periodGrouping); series.put(serie, ts); } else { ts = series.get(serie); } Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } // add series for (TimeSeries ts : series.values()) { dataSet.addSeries(ts); } } else if (visitsTotalsChart) { // 2 series: visits & unique visitors TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"), periodGrouping); TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"), periodGrouping); for (Stat _s : reportData) { SiteVisits s = (SiteVisits) _s; RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = tsV.getValue(key)) == null) { tsV.add(key, s.getTotalVisits()); tsUV.add(key, s.getTotalUnique()); } else { tsV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); tsUV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); } keys.add(key); } } dataSet.addSeries(tsV); dataSet.addSeries(tsUV); } // fill missing values with zeros /*for(TimeSeries ts : (List<TimeSeries>) dataSet.getSeries()) { for(RegularTimePeriod tp : keys) { if(ts.getValue(tp) == null) { ts.add(tp, 0.0); } } }*/ dataSet.setXPosition(TimePeriodAnchor.MIDDLE); return dataSet; }
From source file:com.parse.ParseObject.java
/** * Access a {@code long} value.// w w w.j a v a 2s . c o m * * @param key * The key to access the value for. * @return {@code 0} if there is no such key or if it is not a {@code long}. */ public long getLong(String key) { Number number = getNumber(key); if (number == null) { return 0; } return number.longValue(); }
From source file:org.patientview.radar.dao.impl.DemographicsDaoImpl.java
public void saveDemographics(final Patient patient) { // If we have an ID then update, otherwise insert new and set the ID if (patient.hasValidId()) { jdbcTemplate.update("UPDATE patient SET " + "rrNo = ?, " + "dateReg = ?, " + "nhsno = ?, " + "nhsNoType = ?, " + "hospitalnumber = ?, " + "uktNo = ?, " + "surname = ?, " + "surnameAlias = ?, " + "forename = ?, " + "dateofbirth = ?, " + "AGE = ?, " + "SEX = ?, " + "ethnicGp = ?, " + "address1 = ?, " + "address2 = ?, " + "address3 = ?, " + "address4 = ?, " + "POSTCODE = ?, " + "postcodeOld = ?," + "CONSENT = ?, " + "dateBapnReg = ?, " + "consNeph = ?, " + // "unitcode = ?, " + // "RENAL_UNIT_2 = ?, " + "STATUS = ?, " + // "RDG = ?, " + "emailAddress = ?, " + "telephone1 = ?, " + "telephone2 = ?, " + "mobile = ?, " + "rrtModality = ?, " + "genericDiagnosis = ?, " + "dateOfGenericDiagnosis = ?, " + "otherClinicianAndContactInfo = ?, " + "comments = ?, " + "republicOfIrelandId = ?, " + "isleOfManId = ?, " + "channelIslandsId = ?, " + "indiaId = ?, " + "radarConsentConfirmedByUserId = ?, " + "generic = ? " + "patientLinkId = ? " + " WHERE radarNo = ?", patient.getRrNo(), patient.getDateReg(), patient.getNhsno(), patient.getNhsNumberType() != null ? patient.getNhsNumberType().getId() : 1, patient.getHospitalnumber(), patient.getUktNo(), patient.getSurname(), patient.getSurnameAlias(), patient.getForename(), patient.getDob() != null ? new SimpleDateFormat(DATE_FORMAT).format(patient.getDob()) : null, patient.getDateofbirth(), patient.getAge(), patient.getSexModel() != null ? patient.getSexModel().getType() : null, patient.getEthnicity() != null ? patient.getEthnicity().getCode() : null, patient.getAddress1(), patient.getAddress2(), patient.getAddress3(), patient.getAddress4(), patient.getPostcode(), patient.getPostcodeOld(), patient.isConsent(), patient.getDateReg(), patient.getClinician() != null ? patient.getClinician().getId() : null, // patient.getDiseaseGroup() != null ? patient.getDiseaseGroup().getId() : null, // patient.getRenalUnitAuthorised() != null ? // patient.getRenalUnitAuthorised().getId() : null, patient.getStatusModel() != null ? patient.getStatusModel().getId() : null, // patient.getDiseaseGroup() != null ? patient.getDiseaseGroup().getId() : null, patient.getEmailAddress(), patient.getTelephone1(), patient.getTelephone2(), patient.getMobile(),// www . ja v a2 s. c o m patient.getRrtModalityEunm() != null ? patient.getRrtModalityEunm().getId() : null, patient.getGenericDiagnosisModel() != null ? patient.getGenericDiagnosisModel().getId() : null, patient.getDateOfGenericDiagnosis(), patient.getOtherClinicianAndContactInfo(), patient.getComments(), patient.getRepublicOfIrelandId(), patient.getIsleOfManId(), patient.getChannelIslandsId(), patient.getIndiaId(), patient.getRadarConsentConfirmedByUserId(), patient.isGeneric(), patient.getPatientLinkId(), patient.getId()); } else { Number id = demographicsInsert.executeAndReturnKey(new HashMap<String, Object>() { { put("rrNo", patient.getRrNo()); put("dateReg", patient.getDateReg()); put("nhsno", patient.getNhsno()); put("nhsNoType", patient.getNhsNumberType() != null ? patient.getNhsNumberType().getId() : null); put("hospitalnumber", patient.getHospitalnumber()); put("uktNo", patient.getUktNo()); put("surname", patient.getSurname()); put("surnameAlias", patient.getSurnameAlias()); put("forename", patient.getForename()); put("dateofbirth", patient.getDateofbirth()); put("AGE", patient.getAge()); put("SEX", patient.getSexModel() != null ? patient.getSexModel().getType() : null); put("ethnicGp", patient.getEthnicity() != null ? patient.getEthnicity().getCode() : null); put("address1", patient.getAddress1()); put("address2", patient.getAddress2()); put("address3", patient.getAddress3()); put("address4", patient.getAddress4()); put("POSTCODE", patient.getPostcode()); put("postcodeOld", patient.getPostcodeOld()); put("CONSENT", patient.isConsent()); put("dateBapnReg", null); // Todo: Fix put("consNeph", patient.getClinician() != null ? patient.getClinician().getId() : null); put("unitcode", patient.getUnitcode() != null ? patient.getUnitcode() : patient.getRenalUnit().getUnitCode()); // put("RENAL_UNIT_2", patient.getRenalUnitAuthorised() != null ? // patient.getRenalUnitAuthorised().getId() : null); put("STATUS", patient.getStatusModel() != null ? patient.getStatusModel().getId() : null); // put("RDG", patient.getDiseaseGroup() != null ? patient.getDiseaseGroup().getId() : null); put("emailAddress", patient.getEmailAddress()); put("telephone1", patient.getTelephone1()); put("telephone2", patient.getTelephone2()); put("mobile", patient.getMobile()); put("rrtModality", patient.getRrtModalityEunm() != null ? patient.getRrtModalityEunm().getId() : null); put("genericDiagnosis", patient.getGenericDiagnosisModel() != null ? patient.getGenericDiagnosisModel().getId() : null); put("dateOfGenericDiagnosis", patient.getDateOfGenericDiagnosis()); put("otherClinicianAndContactInfo", patient.getOtherClinicianAndContactInfo()); put("comments", patient.getComments()); put("republicOfIrelandId", patient.getRepublicOfIrelandId()); put("isleOfManId", patient.getIsleOfManId()); put("channelIslandsId", patient.getChannelIslandsId()); put("indiaId", patient.getIndiaId()); put("generic", patient.isGeneric()); put("radarConsentConfirmedByUserId", patient.getRadarConsentConfirmedByUserId()); put("sourceType", SourceType.RADAR.getName()); put("patientLinkId", patient.getPatientLinkId()); } }); patient.setId(id.longValue()); //The id of the patient record is now the new radar number jdbcTemplate.update("UPDATE patient set radarNo = ? WHERE id = ? ", id.longValue(), id.longValue()); patient.setRadarNo(patient.getId()); } }
From source file:com.tesora.dve.sql.parser.TranslatorUtils.java
public TableModifier buildMaxRowsModifier(ExpressionNode en) { LiteralExpression litex = asLiteral(en); Object v = litex.getValue(pc.getValues()); if (v instanceof Number) { Number n = (Number) v; return new MaxRowsModifier(n.longValue()); }/*from w w w .ja va 2 s .c om*/ throw new SchemaException(Pass.FIRST, "Invalid max rows value - not a number"); }