format a number with given mask

@param number
@param mask
@return formatted number as string
@throws InvalidMaskException
427152
public String formatX(Locale locale, double number, String mask) throws InvalidMaskException {
	return format(locale, number, convertMask(mask));
    }
781149
private void calculate(String mask) {
        Matcher matcher = cidrPattern.matcher(mask);

        if (matcher.matches()) {
            address = matchAddress(matcher);

            /* Create a binary netmask from the number of bits specification /x */
            int cidrPart = rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
            for (int j = 0; j < cidrPart; ++j) {
                netmask |= (1 << 31 - j);
            }

        } else {
            throw new IllegalArgumentException("Could not parse [" + mask + "]");
        }
    }
571968
def normalize_mask(mask, is_micro):
    
    if mask is None:
        return None
    try:
        mask = int(mask)
    except ValueError:
        raise MaskError('Invalid data mask "{0}". Must be an integer or a string which represents an integer value.'.format(mask))
    if is_micro:
        if not 0 <= mask < 4:
            raise MaskError('Invalid data mask "{0}" for Micro QR Code. Must be in range 0 .. 3'.format(mask))
    else:
        if not 0 <= mask < 8:
            raise MaskError('Invalid data mask "{0}". Must be in range 0 .. 7'.format(mask))
    return mask
1187291
public String normalizeNumber(final String number) {
        try {
            final BigDecimal normalizedNumber = parseNumber(new NumberBuffer(
                    number));
            if (normalizedNumber == null) {
                return number;
            }
            return normalizedNumber.toBigIntegerExact().toString();

        } catch (NumberFormatException | ArithmeticException e) {
            // Return the source number in case of error, i.e. malformed input
            return number;
        }
    }
801309
public void setValue(Number number) {
		String txt = null;
		if (number != null) {
			txt = this.format.format(number);
		}
		setText(txt);
	}
490886
public String format(Locale locale, double number) {
	DecimalFormat df = getDecimalFormat(locale);
	df.applyPattern(",0");
	df.setGroupingSize(3);
	return df.format(number);
    }
1219348
public static PrettyPrint indentWithSpaces(int number) {
    if (number < 0) {
      throw new IllegalArgumentException("number is negative");
    }
    char[] chars = new char[number];
    Arrays.fill(chars, ' ');
    return new PrettyPrint(chars);
  }
297418
def str_to_ipmask(ipmask):
    '''
    
    '''
    v = ipmask.split("/")
    if len(v) > 2: raise Exception("bad mask format")
    mask_ip = ip2hex(v[0])
    if mask_ip is None: raise Exception("bad mask format")
    mask = v[1] if len(v) == 2 else 32
    try:
        mask = (0xffffffff00000000 >> int(mask)) & 0xffffffff
    except:
        mask = ip2hex(v[1])
    
    if mask is None: raise Exception("bad mask format")
    return mask_ip, mask
126346
def format_phone_number(number):
    
    if not isinstance(number, phonenumbers.PhoneNumber):
        number = phonenumbers.parse(number)
    return phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
177062
@Override
    public String format(Date date, String mask) {
	return format(date, mask, null);
    }
295142
function getMaskTemplate(mask) {
                if (opts.numericInput) {
                    mask = mask.split('').reverse().join('');
                }
                var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
                if (repeat == "*") greedy = false;
                //if (greedy == true && opts.placeholder == "") opts.placeholder = " ";
                if (mask.length == 1 && greedy == false && repeat != 0) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                var singleMask = $.map(mask.split(""), function (element, index) {
                    var outElem = [];
                    if (element == opts.escapeChar) {
                        escaped = true;
                    }
                    else if ((element != opts.optionalmarker.start && element != opts.optionalmarker.end) || escaped) {
                        var maskdef = opts.definitions[element];
                        if (maskdef && !escaped) {
                            for (var i = 0; i < maskdef.cardinality; i++) {
                                outElem.push(opts.placeholder.charAt((outCount + i) % opts.placeholder.length));
                            }
                        } else {
                            outElem.push(element);
                            escaped = false;
                        }
                        outCount += outElem.length;
                        return outElem;
                    }
                });

                //allocate repetitions
                var repeatedMask = singleMask.slice();
                for (var i = 1; i < repeat && greedy; i++) {
                    repeatedMask = repeatedMask.concat(singleMask.slice());
                }

                return { "mask": repeatedMask, "repeat": repeat, "greedy": greedy };
            }
1087236
public static function formatScore($value, $mask)
    {
        $parse = self::parseChartMask($mask);

        if ($value === null) {
            return '';
        }

        $result     = '';
        $localValue = $value;
        $nbElement  = count($parse) - 1;
        for ($k = $nbElement; $k >= 0; --$k) {
            $size             = $parse[$k]['size'];
            $suffixe          = $parse[$k]['suffixe'];
            $lengthLocalValue = strlen($localValue);

            if ($lengthLocalValue > $size) {
                $tmpValue   = substr($localValue, $lengthLocalValue - $size, $size);
                $localValue = substr($localValue, 0, $lengthLocalValue - $size);
            } elseif ($k !== 0) {
                $tmpValue   = str_pad($localValue, $size, '0', STR_PAD_LEFT);
                $localValue = '';
            } elseif ($lengthLocalValue === 0) {
                $tmpValue = '0';
            } elseif ($size === 30) {
                $tmpValue = number_format($localValue);
            } else {
                $tmpValue = $localValue;
            }

            $result = $tmpValue . $suffixe . $result;
        }

        return $result;
    }
826170
public static int evenHash(final long value, final int mask)
    {
        int hash = (int)value ^ (int)(value >>> 32);
        hash = (hash << 1) - (hash << 8);

        return hash & mask;
    }
589207
public <N extends Number> CellFormatResult format(final String formatPattern, final N value, final Locale locale) {
        return format(new NumberCell<N>(value, formatPattern), locale);
    }
659865
public static String formatNum(
      ULocale uLocale,
      double number,
      String formatType,
      String numbersKeyword,
      @Nullable Integer minFractionDigits,
      @Nullable Integer maxFractionDigits) {
    uLocale = uLocale.setKeywordValue("numbers", numbersKeyword);
    NumberFormat numberFormat;
    switch (formatType) {
      case "decimal":
        numberFormat = NumberFormat.getInstance(uLocale);
        break;
      case "percent":
        numberFormat = NumberFormat.getPercentInstance(uLocale);
        break;
      case "currency":
        numberFormat = NumberFormat.getCurrencyInstance(uLocale);
        break;
      case "scientific":
        numberFormat = NumberFormat.getScientificInstance(uLocale);
        break;
      case "compact_short":
        {
          CompactDecimalFormat compactNumberFormat =
              CompactDecimalFormat.getInstance(uLocale, CompactStyle.SHORT);
          compactNumberFormat.setMaximumSignificantDigits(3);
          numberFormat = compactNumberFormat;
          break;
        }
      case "compact_long":
        {
          CompactDecimalFormat compactNumberFormat =
              CompactDecimalFormat.getInstance(uLocale, CompactStyle.LONG);
          compactNumberFormat.setMaximumSignificantDigits(3);
          numberFormat = compactNumberFormat;
          break;
        }
      default:
        throw new IllegalArgumentException(
            "First argument to formatNum must be "
                + "constant, and one of: 'decimal', 'currency', 'percent', 'scientific', "
                + "'compact_short', or 'compact_long'.");
    }

    if (minFractionDigits != null) {
      numberFormat.setMinimumFractionDigits(minFractionDigits);
    }
    if (maxFractionDigits != null) {
      numberFormat.setMaximumFractionDigits(maxFractionDigits);
    }
    return numberFormat.format(number);
  }
811590
public static String format(double number, String pattern) {
		DecimalFormat df = null;
		if (StringUtils.isEmpty(pattern)) {
			df = PRETTY_FORMAT.get();
		} else {
			df = (DecimalFormat) DecimalFormat.getInstance();
			df.applyPattern(pattern);
		}

		return df.format(number);
	}
1075800
public static int hash(final long value, final int mask)
    {
        long hash = value * 31;
        hash = (int)hash ^ (int)(hash >>> 32);

        return (int)hash & mask;
    }