Example usage for java.text NumberFormat setMaximumIntegerDigits

List of usage examples for java.text NumberFormat setMaximumIntegerDigits

Introduction

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

Prototype

public void setMaximumIntegerDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the integer portion of a number.

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFNumberFormat.java

public String evaluate(DoubleWritable d) {
    if (d == null) {
        return null;
    }/*from   ww  w .ja va  2s  . co m*/
    double ori = d.get();
    try {
        NumberFormat nFormat = NumberFormat.getNumberInstance();
        nFormat.setMaximumFractionDigits(maxdefault);
        nFormat.setMaximumIntegerDigits(maxdefault);
        nFormat.setGroupingUsed(false);
        return nFormat.format(ori);
    } catch (Exception e) {
        LOG.error("can not format value:  " + ori);
        return null;
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFNumberFormat.java

public String evaluate(DoubleWritable d, IntWritable fracMax, IntWritable intMax) {
    if (d == null || fracMax == null || intMax == null) {
        return null;
    }//  w w  w  .j  a  va  2  s  .  com
    double ori = d.get();
    try {
        NumberFormat nFormat = NumberFormat.getNumberInstance();
        nFormat.setMaximumFractionDigits(fracMax.get());
        nFormat.setMaximumIntegerDigits(intMax.get());
        nFormat.setGroupingUsed(false);
        return nFormat.format(ori);
    } catch (Exception e) {
        LOG.error("can not format value:  " + ori);
        return null;
    }
}

From source file:org.apache.nifi.schemaregistry.processors.CSVUtils.java

/**
 * According to the 1.7.7 spec If a logical type is invalid, for example a
 * decimal with scale greater than its precision,then implementations should
 * ignore the logical type and use the underlying Avro type.
 *///ww w  .  j  ava 2  s .com
private static void normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision) {
    if (scale < precision) {
        // write out with the specified precision and scale.
        numberFormat.setMaximumIntegerDigits(precision);
        numberFormat.setMaximumFractionDigits(scale);
        numberFormat.setMinimumFractionDigits(scale);
    }
}

From source file:org.asqatasun.webapp.command.factory.ChangeTestWeightCommandFactory.java

/**
 * //w w  w  .ja v  a 2s .co m
 * @param user
 * @param locale
 * @param testList
 * @param referentialKey
 * @return 
 *      an initialised instance of ChangeTestWeightCommand
 */
public ChangeTestWeightCommand getChangeTestWeightCommand(User user, Locale locale, Collection<Test> testList,
        String referentialKey) {
    Map<String, String> userTestWeight = new HashMap<String, String>();
    NumberFormat nf = NumberFormat.getNumberInstance(locale);
    nf.setMinimumFractionDigits(1);
    nf.setMaximumFractionDigits(1);
    nf.setMaximumIntegerDigits(1);
    nf.setMinimumIntegerDigits(1);
    for (OptionElement oe : optionElementDataService.getOptionElementFromUserAndFamilyCode(user,
            referentialKey + "_" + optionFamilyCodeStr)) {
        userTestWeight.put(oe.getOption().getCode(), nf.format(Double.valueOf(oe.getValue())));
    }
    for (Test test : testList) {
        if (!userTestWeight.containsKey(test.getCode())) {
            userTestWeight.put(test.getCode(), "");
        }
    }

    ChangeTestWeightCommand changeTestWeightCommand = new ChangeTestWeightCommand();
    changeTestWeightCommand.setTestWeightMap(userTestWeight);
    return changeTestWeightCommand;
}

From source file:org.codelibs.fess.web.IndexAction.java

protected String doSearchInternal() {
    final StringBuilder queryBuf = new StringBuilder(255);
    if (StringUtil.isNotBlank(indexForm.query)) {
        queryBuf.append(indexForm.query);
    }//w  ww  .j a v a 2  s  . co m
    if (StringUtil.isNotBlank(indexForm.op)) {
        request.setAttribute(Constants.DEFAULT_OPERATOR, indexForm.op);
    }
    if (queryBuf.indexOf(" OR ") >= 0) {
        queryBuf.insert(0, '(').append(')');
    }
    if (indexForm.additional != null) {
        final Set<String> fieldSet = new HashSet<String>();
        for (final String additional : indexForm.additional) {
            if (StringUtil.isNotBlank(additional) && additional.length() < 1000
                    && !hasFieldInQuery(fieldSet, additional)) {
                queryBuf.append(' ').append(additional);
            }
        }
    }
    if (!indexForm.fields.isEmpty()) {
        for (final Map.Entry<String, String[]> entry : indexForm.fields.entrySet()) {
            final List<String> valueList = new ArrayList<String>();
            final String[] values = entry.getValue();
            if (values != null) {
                for (final String v : values) {
                    valueList.add(v);
                }
            }
            if (valueList.size() == 1) {
                queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(0)).append('\"');
            } else if (valueList.size() > 1) {
                queryBuf.append(" (");
                for (int i = 0; i < valueList.size(); i++) {
                    if (i != 0) {
                        queryBuf.append(" OR");
                    }
                    queryBuf.append(' ').append(entry.getKey()).append(":\"").append(valueList.get(i))
                            .append('\"');
                }
                queryBuf.append(')');
            }

        }
    }
    if (StringUtil.isNotBlank(indexForm.sort)) {
        queryBuf.append(" sort:").append(indexForm.sort);
    }
    if (indexForm.lang != null) {
        final Set<String> langSet = new HashSet<>();
        for (final String lang : indexForm.lang) {
            if (StringUtil.isNotBlank(lang) && lang.length() < 1000) {
                if (Constants.ALL_LANGUAGES.equalsIgnoreCase(lang)) {
                    langSet.add(Constants.ALL_LANGUAGES);
                } else {
                    final String normalizeLang = systemHelper.normalizeLang(lang);
                    if (normalizeLang != null) {
                        langSet.add(normalizeLang);
                    }
                }
            }
        }
        if (langSet.size() > 1 && langSet.contains(Constants.ALL_LANGUAGES)) {
            langSet.clear();
            indexForm.lang = new String[] { Constants.ALL_LANGUAGES };
        } else {
            langSet.remove(Constants.ALL_LANGUAGES);
        }
        appendLangQuery(queryBuf, langSet);
    } else if (Constants.TRUE.equals(
            crawlerProperties.getProperty(Constants.USE_BROWSER_LOCALE_FOR_SEARCH_PROPERTY, Constants.FALSE))) {
        final Set<String> langSet = new HashSet<>();
        final Enumeration<Locale> locales = request.getLocales();
        if (locales != null) {
            while (locales.hasMoreElements()) {
                final Locale locale = locales.nextElement();
                final String normalizeLang = systemHelper.normalizeLang(locale.toString());
                if (normalizeLang != null) {
                    langSet.add(normalizeLang);
                }
            }
            if (!langSet.isEmpty()) {
                appendLangQuery(queryBuf, langSet);
            }
        }
    }

    final String query = queryBuf.toString().trim();

    // init pager
    if (StringUtil.isBlank(indexForm.start)) {
        indexForm.start = String.valueOf(DEFAULT_START_COUNT);
    } else {
        try {
            Long.parseLong(indexForm.start);
        } catch (final NumberFormatException e) {
            indexForm.start = String.valueOf(DEFAULT_START_COUNT);
        }
    }
    if (StringUtil.isBlank(indexForm.num)) {
        indexForm.num = String.valueOf(getDefaultPageSize());
    }
    normalizePageNum();

    final int pageStart = Integer.parseInt(indexForm.start);
    final int pageNum = Integer.parseInt(indexForm.num);
    try {
        documentItems = searchService.getDocumentList(query, pageStart, pageNum, indexForm.facet, indexForm.geo,
                indexForm.mlt, queryHelper.getResponseFields(), queryHelper.getResponseDocValuesFields());
    } catch (final SolrLibQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.invalid_query_unknown");
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, e.getMessageCode());
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw new SSCActionMessagesException(e, "errors.result_size_exceeded");
    }
    // search
    final QueryResponseList queryResponseList = (QueryResponseList) documentItems;
    facetResponse = queryResponseList.getFacetResponse();
    moreLikeThisResponse = queryResponseList.getMoreLikeThisResponse();
    final NumberFormat nf = NumberFormat.getInstance(RequestUtil.getRequest().getLocale());
    nf.setMaximumIntegerDigits(2);
    nf.setMaximumFractionDigits(2);
    try {
        execTime = nf.format((double) queryResponseList.getExecTime() / 1000);
    } catch (final Exception e) {
        // ignore
    }

    final Clock clock = Clock.systemDefaultZone();
    indexForm.rt = Long.toString(clock.millis());

    // favorite
    if (favoriteSupport || screenShotManager != null) {
        indexForm.queryId = userInfoHelper.generateQueryId(query, documentItems);
        if (screenShotManager != null) {
            screenShotManager.storeRequest(indexForm.queryId, documentItems);
            screenShotSupport = true;
        }
    }

    // search log
    if (searchLogSupport) {
        final LocalDateTime now = systemHelper.getCurrentTime();

        final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
        final SearchLog searchLog = new SearchLog();

        String userCode = null;
        if (Constants.TRUE
                .equals(crawlerProperties.getProperty(Constants.USER_INFO_PROPERTY, Constants.TRUE))) {
            userCode = userInfoHelper.getUserCode();
            if (StringUtil.isNotBlank(userCode)) {
                final UserInfo userInfo = new UserInfo();
                userInfo.setCode(userCode);
                userInfo.setCreatedTime(now);
                userInfo.setUpdatedTime(now);
                searchLog.setUserInfo(OptionalEntity.of(userInfo));
            }
        }

        searchLog.setHitCount(queryResponseList.getAllRecordCount());
        searchLog.setResponseTime(Integer.valueOf((int) queryResponseList.getExecTime()));
        searchLog.setSearchWord(StringUtils.abbreviate(query, 1000));
        searchLog.setSearchQuery(StringUtils.abbreviate(queryResponseList.getSearchQuery(), 1000));
        searchLog.setSolrQuery(StringUtils.abbreviate(queryResponseList.getSolrQuery(), 1000));
        searchLog.setRequestedTime(now);
        searchLog.setQueryOffset(pageStart);
        searchLog.setQueryPageSize(pageNum);

        searchLog.setClientIp(StringUtils.abbreviate(request.getRemoteAddr(), 50));
        searchLog.setReferer(StringUtils.abbreviate(request.getHeader("referer"), 1000));
        searchLog.setUserAgent(StringUtils.abbreviate(request.getHeader("user-agent"), 255));
        if (userCode != null) {
            searchLog.setUserSessionId(userCode);
        }
        final Object accessType = request.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
        if (accessType instanceof CDef.AccessType) {
            switch ((CDef.AccessType) accessType) {
            case Json:
                searchLog.setAccessType_Json();
                searchLog.setAccessType_Others();
                searchLog.setAccessType_Xml();
                break;
            case Xml:
                searchLog.setAccessType_Xml();
                break;
            case Others:
                searchLog.setAccessType_Others();
                break;
            default:
                searchLog.setAccessType_Web();
                break;
            }
        } else {
            searchLog.setAccessType_Web();
        }

        @SuppressWarnings("unchecked")
        final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) request
                .getAttribute(Constants.FIELD_LOGS);
        if (fieldLogMap != null) {
            for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
                for (final String value : logEntry.getValue()) {
                    searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, 1000));
                }
            }
        }

        searchLogHelper.addSearchLog(searchLog);
    }

    final String[] highlightQueries = (String[]) request.getAttribute(Constants.HIGHLIGHT_QUERIES);
    if (highlightQueries != null) {
        final StringBuilder buf = new StringBuilder(100);
        for (final String q : highlightQueries) {
            buf.append("&hq=").append(q);
        }
        appendHighlightQueries = buf.toString();
    }

    Beans.copy(documentItems, this)
            .includes("pageSize", "currentPageNumber", "allRecordCount", "allPageCount", "existNextPage",
                    "existPrevPage", "currentStartRecordNumber", "currentEndRecordNumber", "pageNumberList",
                    "partialResults", "queryTime", "searchTime")
            .execute();

    return query;
}

From source file:org.efaps.esjp.common.uiform.Create_Base.java

private void insertFieldSetsOld(final Parameter _parameter, final Instance _instance,
        final List<FieldSet> _fieldsets) throws EFapsException {
    final Map<?, ?> others = (HashMap<?, ?>) _parameter.get(ParameterValues.OTHERS);
    // to find out if new values where added for a field set, first it is checked
    // if it exists in this map
    if (others != null) {

        final NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);/*from w w w .  ja  va 2  s .c  o  m*/
        nf.setMaximumIntegerDigits(2);

        for (final FieldSet fieldset : _fieldsets) {
            final String[] yCoords = (String[]) others.get(fieldset.getName() + "_eFapsNew");
            if (yCoords != null) {
                final String setName = fieldset.getAttribute();
                final AttributeSet set = AttributeSet.find(_instance.getType().getName(), setName);

                for (final String yCoord : yCoords) {
                    final Insert insert = new Insert(set);
                    insert.add(set.getAttribute(setName), ((Long) _instance.getId()).toString());
                    int xCoord = 0;
                    for (final String attrName : fieldset.getOrder()) {
                        final Attribute child = set.getAttribute(attrName);
                        final String fieldName = fieldset.getName() + "_eFapsNew_"
                                + nf.format(Integer.parseInt(yCoord)) + nf.format(xCoord);
                        if (_parameter.getParameters().containsKey(fieldName)) {
                            add2Insert(_parameter, insert, child, fieldName, 0);
                        }
                        xCoord++;
                    }
                    insert.execute();
                }
            }
        }
    }
}

From source file:org.efaps.esjp.common.uiform.Edit_Base.java

private void updateFieldSetsOld(final Parameter _parameter, final Instance _instance,
        final List<FieldSet> _fieldsets) throws EFapsException {
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(2);/*from  w  w w. j  a  v a  2s .  c om*/
    nf.setMaximumIntegerDigits(2);

    for (final FieldSet fieldset : _fieldsets) {
        final String setName = fieldset.getAttribute();
        final AttributeSet set = AttributeSet.find(_instance.getType().getName(), setName);

        // first already existing values must be updated, if they were
        // altered
        boolean updateExisting = true;
        int yCoord = 0;
        while (updateExisting) {
            // check in the context if already existing values might have
            // been altered, by
            // using the hidden field that is added when existing values for
            // a fieldset are shown
            final String idfield = "hiddenId_" + fieldset.getName() + "_" + nf.format(yCoord);
            if (_parameter.getParameters().containsKey(idfield)) {
                final String id = _parameter.getParameterValue(idfield);
                // check the values in the database
                final PrintQuery printQuery = new PrintQuery(set, id);
                for (final Attribute attr : set.getAttributes().values()) {
                    printQuery.addAttribute(attr);
                }
                printQuery.execute();

                final Update setupdate = new Update(set, id);
                int xCoord = 0;
                boolean update = false;
                for (final String attrName : fieldset.getOrder()) {
                    final Attribute child = set.getAttribute(attrName);
                    final String fieldName = fieldset.getName() + "_" + nf.format(yCoord) + nf.format(xCoord);
                    if (_parameter.getParameters().containsKey(fieldName)) {
                        final Object object = printQuery.getAttribute(attrName);
                        final String oldValue = object != null ? object.toString() : null;
                        final String newValue = _parameter.getParameterValue(fieldName);
                        if (!newValue.equals(oldValue)) {
                            add2Update(_parameter, setupdate, child, fieldName);
                            update = true;
                        }
                    }
                    xCoord++;
                }
                if (update) {
                    setupdate.execute();
                }
            } else {
                updateExisting = false;
            }
            yCoord++;
        }

        // add new values
        final Map<?, ?> others = (HashMap<?, ?>) _parameter.get(ParameterValues.OTHERS);
        if (others != null) {
            // add new Values
            final String[] yCoords = (String[]) others.get(fieldset.getName() + "_eFapsNew");
            if (yCoords != null) {

                for (final String ayCoord : yCoords) {
                    final Insert insert = new Insert(set);
                    insert.add(set.getAttribute(setName), ((Long) _instance.getId()).toString());
                    int xCoord = 0;
                    for (final String attrName : fieldset.getOrder()) {
                        final Attribute child = set.getAttribute(attrName);
                        final String fieldName = fieldset.getName() + "_eFapsNew_"
                                + nf.format(Integer.parseInt(ayCoord)) + nf.format(xCoord);
                        if (_parameter.getParameters().containsKey(fieldName)) {
                            add2Update(_parameter, insert, child, fieldName);
                        }
                        xCoord++;
                    }
                    insert.execute();
                }
            }

            // remove deleted Values
            final String[] removeOnes = (String[]) others.get(fieldset.getName() + "eFapsRemove");
            if (removeOnes != null) {
                for (final String removeOne : removeOnes) {
                    final Delete delete = new Delete(set, removeOne);
                    delete.execute();
                }
            }
        }
    }
}

From source file:org.hoteia.qalingo.core.domain.CurrencyReferential.java

public NumberFormat getEcoCurrencyformat() {
    NumberFormat formatter = getStandardCurrencyformat();
    formatter.setGroupingUsed(true);/*from  w ww .  j a  v  a  2s . c om*/
    formatter.setParseIntegerOnly(false);
    formatter.setRoundingMode(RoundingMode.HALF_EVEN);

    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(2);

    formatter.setMaximumIntegerDigits(1000000);
    formatter.setMinimumIntegerDigits(1);
    return formatter;
}

From source file:org.kuali.kfs.gl.batch.service.impl.ScrubberProcessImpl.java

/**
 * Generate the flag for the end of specific descriptions. This will be used in the demerger step
 *//*w  ww.  j  a va 2s  .c  om*/
protected void setOffsetString() {

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMaximumIntegerDigits(2);
    nf.setMinimumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);

    offsetString = COST_SHARE_TRANSFER_ENTRY_IND + nf.format(runCal.get(Calendar.MONTH) + 1)
            + nf.format(runCal.get(Calendar.DAY_OF_MONTH));
}

From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborScrubberProcess.java

/**
 * Generate the flag for the end of specific descriptions. This will be used in the demerger step
 *//*from   w ww  .j a  v  a 2 s  .com*/
protected void setOffsetString() {

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMaximumIntegerDigits(2);
    nf.setMinimumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);

    offsetString = "***" + nf.format(runCal.get(Calendar.MONTH) + 1)
            + nf.format(runCal.get(Calendar.DAY_OF_MONTH));
}