Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

In this page you can find the example usage for java.text NumberFormat format.

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.prowidesoftware.swift.model.field.Field32R.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  w  ww. j  a  v  a  2  s  . c  om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 32R");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:edu.isistan.carcha.lsa.LSARunnerTest.java

/**
 * Test calculate metrics.// w ww .  java 2  s .co m
 * 
 * @param result
 *            the result
 * @param golden
 *            the golden
 */
public void calculateMetrics(TraceabilityDocument result, TraceabilityDocument golden) {

    double fn = ListUtils.removeAll(golden.getLinks(), result.getLinks()).size();
    double fp = ListUtils.removeAll(result.getLinks(), golden.getLinks()).size();
    double tn = Utils.calculateTrueNegatives(golden, result);
    double tp = ListUtils.intersection(result.getLinks(), golden.getLinks()).size();

    double presicion = tp / (tp + fp + 0.0000000001);
    double recall = tp / (tp + fn);
    double fMeasure = 5 * ((presicion * recall) / ((4 * presicion) + recall + 0.0000000001));
    double accuracy = (tp + tn) / (fn + fp + tp + tn);

    NumberFormat df = new DecimalFormat("#0.00");

    logger.info("Golden TRAs:" + golden.getLinks().size());
    logger.info("Discovered TRAs:" + result.getLinks().size());
    logger.info("------------------");
    logger.info("False Negative:\t" + fn);
    logger.info("False Positive:\t" + fp);
    logger.info("True  Negative:\t" + tn);
    logger.info("True Positive:\t" + tp);
    logger.info("------------------");
    logger.info("Presition:\t" + df.format(presicion * 100) + "%");
    logger.info("Recall:\t" + df.format(recall * 100) + "%");
    logger.info("Acurracy:\t" + df.format(accuracy * 100) + "%");
    logger.info("F-Measure:\t" + df.format(fMeasure * 100) + "%");
    logger.info("");
    logger.info("");
}

From source file:com.prowidesoftware.swift.model.field.Field336.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*ww w  . ja va2s.  com*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 336");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent2AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    if (component == 3) {
        //default format (as is)
        return getComponent(3);
    }
    return null;
}

From source file:com.hm.his.module.user.controller.UserController.java

/**
 * <p>Description:<p>//from  w  w  w . java2 s .co  m
 * @author ZhouPengyu
 * @date 2016-3-2 ?11:39:16
 */
@RequestMapping(value = {
        "/hospitalRegister" }, produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
@ResponseBody
public String register(@RequestBody Map<String, String> requestParams, HttpServletRequest request,
        HttpServletResponse response) {
    String userName = requestParams.get("userName");
    String password = requestParams.get("password");
    String realName = requestParams.get("realName");
    String phone = requestParams.get("phone");
    String mail = requestParams.get("mail");

    String registerInvitation = requestParams.get("registerInvitation");
    String hospitalName = requestParams.get("hospitalName");
    String address = requestParams.get("address");
    String hospitalLicense = requestParams.get("hospitalLicense");
    String invitationCode = requestParams.get("invitationCode");

    String smsCaptcha = requestParams.get("smsCaptcha");

    HisResponse hisResponse = new HisResponse();
    try {
        String sessionId = SessionUtils.getSession().getId();
        String smsCaptchaCache = JedisHelper.get(String.class, sessionId).split("-")[0];
        String cachePhoneNo = JedisHelper.get(String.class, sessionId).split("-")[1];
        log.error(sessionId + "----??" + smsCaptcha + "--??"
                + smsCaptchaCache);
        Map<String, Object> map = new HashMap<String, Object>();
        if ((smsCaptchaCache == null || !smsCaptchaCache.equals(smsCaptcha) || !cachePhoneNo.equals(phone))
                && !"hmluckycharm!".equals(smsCaptcha)) {
            map.put("status", 5);
            hisResponse.setBody(map);
            return hisResponse.toString();
        }

        Doctor doctor = new Doctor();
        if (StringUtils.isNotEmpty(registerInvitation)) {
            if (registerInvitation.equals("huimeitimes")) {
                doctor.setStatus(1l);
            } else {
                hisResponse.setErrorCode(401);
                return hisResponse.toString();
            }
        } else
            doctor.setStatus(1l);

        Hospital hospital = new Hospital();
        hospital.setHospitalName(hospitalName);
        hospital.setAddress(address);
        hospital.setOrganizationLicense(hospitalLicense);
        hospital.setInvitationCode(invitationCode);
        hospitalService.saveHospital(hospital);

        Long number = hospital.getHospitalId();
        NumberFormat formatter = NumberFormat.getNumberInstance();
        formatter.setMinimumIntegerDigits(8);
        formatter.setGroupingUsed(false);
        String s = formatter.format(number);
        hospital.setHospitalNumber(
                "HM" + RC4Utils.encry_RC4_string(s, UUID.randomUUID().toString()).toUpperCase());
        hospitalService.saveHospital(hospital);

        doctor.setDoctorName(userName);
        //?  ---?
        doctor.setPassword(MD5Utils.encrypt(password));
        //??
        doctor.setHighPasswd(MD5Utils.passwordSaltHash(doctor.getDoctorName(), doctor.getPassword()));
        doctor.setRealName(realName);
        doctor.setMail(mail);
        doctor.setPhone(phone);
        doctor.setFlag(1L);
        doctor.setIsAdmin(1l);

        doctor.setHospitalId(hospital.getHospitalId());
        doctorService.saveDoctor(doctor);

        if (doctor.getDoctorId() != null && doctor.getDoctorId() != 0l) {
            //              hospitalExamService.insertDefaultExam(hospital.getHospitalId(), doctor.getDoctorId());
            //              drugService.addDefaultDrugForNewHospital(hospital.getHospitalId(), doctor.getDoctorId());
            map.put("status", doctor.getStatus());
            map.put("doctorId", doctor.getDoctorId());
            if (hospital.getInvitationCode() != null && hospital.getInvitationCode().equals("18684989279"))
                map.put("changeImg", 1);
            else
                map.put("changeImg", 0);
            if (doctor.getStatus() != 1l) {
                smsService.getHospitalSmsConfig(hospital.getHospitalId());
                HmMailUtil.sendMail(doctor, hospital); //??
            }
            hisResponse.setBody(map);
        } else {
            hisResponse.setErrorCode(401);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hisResponse.toString();
}

From source file:clus.statistic.RegressionStat.java

public String getString(StatisticPrintInfo info) {
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    StringBuffer buf = new StringBuffer();

    buf.append("[");
    for (int i = 0; i < m_NbAttrs; i++) {
        if (i != 0)
            buf.append(",");
        double tot = getSumWeights(i);
        if (tot == 0)
            buf.append("?");
        else//  w  w  w  . j  ava  2s.com
            buf.append(fr.format(getSumValues(i) / tot));
    }
    buf.append("]");
    if (info.SHOW_EXAMPLE_COUNT_BYTARGET) {
        buf.append(": [");
        for (int i = 0; i < m_NbAttrs; i++) {
            if (i != 0)
                buf.append(",");
            buf.append(fr.format(m_SumWeights[i]));
        }
        buf.append("]");
    } else if (info.SHOW_EXAMPLE_COUNT) {
        buf.append(": ");
        buf.append(fr.format(m_SumWeight));
    }
    return buf.toString();
}

From source file:com.googlecode.fightinglayoutbugs.FightingLayoutBugs.java

private void registerDebugListener() {
    final AtomicInteger i = new AtomicInteger(0);
    final NumberFormat nf = new DecimalFormat("00");
    final File screenshotDir = this.screenshotDir;
    final Visualization.Listener debugListener = new Visualization.Listener() {
        @Override/*from   ww  w .j  a va  2  s  . c o  m*/
        public void algorithmStepFinished(String algorithm, String stepDescription, int[][] tempResult) {
            File pngFile = new File(screenshotDir, nf.format(i.incrementAndGet()) + "_" + algorithm + ".png");
            ImageHelper.pixelsToPngFile(tempResult, pngFile);
            LOG.debug(pngFile.getName() + " -- " + stepDescription);
        }

        @Override
        public void algorithmFinished(String algorithm, String stepDescription, int[][] result) {
            File pngFile = new File(screenshotDir, nf.format(i.incrementAndGet()) + "_" + algorithm + ".png");
            ImageHelper.pixelsToPngFile(result, pngFile);
            LOG.debug(pngFile.getName() + " -- " + stepDescription);
        }
    };
    Visualization.registerListener(debugListener);
    _runAfterAnalysis.add(new Runnable() {
        @Override
        public void run() {
            Visualization.unregisterListener(debugListener);
        }
    });
}

From source file:com.liusoft.dlog4j.velocity.VelocityTool.java

/**
 * (??)//from w  w w.ja v  a  2s. c o m
 * ?,?
 * @return
 */
public String festival() {
    long[] ds = LunarCalendar.today();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);
    String nongli = nf.format(ds[1]) + nf.format(ds[2]);
    Calendar cal = Calendar.getInstance();
    String yangli = nf.format(cal.get(Calendar.MONTH) + 1) + nf.format(cal.get(Calendar.DATE));
    //System.out.printf("nongli=%s,yangli=%s\r\n",nongli,yangli);
    String f_nl = getMessage(request, "festival", 'Y' + nongli);
    String f_yl = getMessage(request, "festival", yangli);
    if (f_nl != null && f_yl != null)
        return f_yl + "," + f_nl;
    if (f_nl != null)
        return f_nl;
    if (f_yl != null)
        return f_yl;
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field34J.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  ww  w . j ava 2 s  .  c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 34J");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field35H.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from   ww w.  ja  v a 2 s . c  o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 35H");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field37H.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*  w ww  . j  a v a  2  s .c o  m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 3) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 37H");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //default format (as is)
        return getComponent(1);
    }
    if (component == 2) {
        //default format (as is)
        return getComponent(2);
    }
    if (component == 3) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent3AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}