java.lang.Character.getNumericValue()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(218)

本文整理了Java中java.lang.Character.getNumericValue()方法的一些代码示例,展示了Character.getNumericValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.getNumericValue()方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:getNumericValue

Character.getNumericValue介绍

[英]Returns the numeric value of the specified Unicode character. See #getNumericValue(int).
[中]

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override
  public void write(int b) throws IOException {
    if(last==-1) {
      last = b;
      return;
    }

    out.write( Character.getNumericValue(last)*16 + Character.getNumericValue(b) );
    last = -1;
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the numeric value of the specified Unicode character.
 * See {@link #getNumericValue(int)}.
 *
 * @param c the character
 * @return a non-negative numeric integer value if a numeric value for
 *         {@code c} exists, -1 if there is no numeric value for {@code c},
 *         -2 if the numeric value can not be represented as an integer.
 */
public static int getNumericValue(char c) {
  return getNumericValue((int) c);
}

代码示例来源:origin: stackoverflow.com

String element = "el5";
int x = Character.getNumericValue(element.charAt(2));
System.out.println("x=" + x);

代码示例来源:origin: stanfordnlp/CoreNLP

public static boolean isForeign(String s) {
 for (int i = 0; i < s.length(); i++) {
  int num = Character.getNumericValue(s.charAt(i));
  if (num < 10 || num > 35) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static Symbol cannonicalSymbol(char ch) {
 if (Character.isDigit(ch)) {
  return DIGIT; //{ Digits.add(new Character(ch)); return DIGIT; }
 }
 if (Character.getNumericValue(ch) >= 10 && Character.getNumericValue(ch) <= 35) {
  return LETTER; //{ Letters.add(new Character(ch)); return LETTER; }
 }
 return new Symbol(ch);
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Formats each number properly. Special thanks to Roman Gromov
 * (https://github.com/romangromov) for this piece of code.
 */
private String makePretty(double number) {
  String r = mFormat.format(number);
  int numericValue1 = Character.getNumericValue(r.charAt(r.length() - 1));
  int numericValue2 = Character.getNumericValue(r.charAt(r.length() - 2));
  int combined = Integer.valueOf(numericValue2 + "" + numericValue1);
  r = r.replaceAll("E[0-9][0-9]", mSuffix[combined / 3]);
  while (r.length() > mMaxLength || r.matches("[0-9]+\\.[a-z]")) {
    r = r.substring(0, r.length() - 2) + r.substring(r.length() - 1);
  }
  return r;
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Convert the column indicator in Excel like A, B, C, AE, CX and so on to a 1-based column number.
 * @param columnIndicator The indicator to convert
 * @return The 1-based column number
 */
public static final int parseColumnNumber( String columnIndicator ) {
 int col = 0;
 for ( int i = columnIndicator.length() - 1; i >= 0; i-- ) {
  char c = columnIndicator.charAt( i );
  int offset = 1 + Character.getNumericValue( c ) - Character.getNumericValue( 'A' );
  col += Math.pow( 26, columnIndicator.length() - i - 1 ) * offset;
 }
 return col;
}

代码示例来源:origin: spotbugs/spotbugs

static int getValue(char c) {
  int x = Character.getNumericValue(c);
  if (x == -2)
    throw new IllegalArgumentException(c + " is not a nonnegative integer");
  if (x == -2)
    throw new IllegalArgumentException(c + " does not represent a number");
  return x;
}

代码示例来源:origin: redisson/redisson

/**
 * Very efficient method for parsing a {@link Long} from the given {@literal Buffer}. Much faster than {@link
 * Long#parseLong(String)}.
 *
 * @param b The {@literal Buffer} to slice.
 * @return The long value or {@literal null} if the {@literal Buffer} could not be read.
 */
public static Long parseLong(Buffer b) {
  if (b.remaining() == 0) {
    return null;
  }
  ByteBuffer bb = b.buffer;
  int origPos = bb.position();
  int len = bb.remaining();
  long num = 0;
  int dec = 1;
  for (int i = len; i > 0; ) {
    char c = (char) bb.get(--i);
    num += Character.getNumericValue(c) * dec;
    dec *= 10;
  }
  bb.position(origPos);
  return num;
}

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) {
  long[] numbers = new long[]{7, 12, 856, 1000, 5821, 10500, 101800, 2000000, 7800000, 92150000, 123200000, 9999999};
  for(long number : numbers) {
    System.out.println(number + " = " + format(number));
  }
}

private static String[] suffix = new String[]{"","k", "m", "b", "t"};
private static int MAX_LENGTH = 4;

private static String format(double number) {
  String r = new DecimalFormat("##0E0").format(number);
  r = r.replaceAll("E[0-9]", suffix[Character.getNumericValue(r.charAt(r.length() - 1)) / 3]);
  while(r.length() > MAX_LENGTH || r.matches("[0-9]+\\.[a-z]")){
    r = r.substring(0, r.length()-2) + r.substring(r.length() - 1);
  }
  return r;
}

代码示例来源:origin: oracle/opengrok

char ch = line.charAt(i);
if (Character.isDigit(ch)) {
  value = value * 10 + Character.getNumericValue(ch);
} else if (ch == ';') {
  out.append((char) value);

代码示例来源:origin: shopizer-ecommerce/shopizer

@Deprecated
private void luhnValidate(String numberString)
    throws ServiceException {
  char[] charArray = numberString.toCharArray();
  int[] number = new int[charArray.length];
  int total = 0;

  for (int i = 0; i < charArray.length; i++) {
    number[i] = Character.getNumericValue(charArray[i]);
  }

  for (int i = number.length - 2; i > -1; i -= 2) {
    number[i] *= 2;

    if (number[i] > 9)
      number[i] -= 9;
  }

  for (int i = 0; i < number.length; i++)
    total += number[i];

  if (total % 10 != 0) {
    ServiceException ex = new ServiceException(ServiceException.EXCEPTION_VALIDATION,"Invalid card number","messages.error.creditcard.number");
    throw ex;
  }

}

代码示例来源:origin: commons-validator/commons-validator

/**
 * Convert a character at a specified position to an integer value.
 *
 * @param character The character to convert
 * @param leftPos The position of the character in the code, counting from left to right
 * @param rightPos The positionof the character in the code, counting from right to left
 * @return The integer value of the character
 * @throws CheckDigitException if character is not alphanumeric
 */
@Override
protected int toInt(char character, int leftPos, int rightPos)
    throws CheckDigitException {
  int charValue = Character.getNumericValue(character);
  // the check digit is only allowed to reach 9
  final int charMax = rightPos == 1 ? 9 : MAX_ALPHANUMERIC_VALUE; // CHECKSTYLE IGNORE MagicNumber
  if (charValue < 0 || charValue > charMax) {
    throw new CheckDigitException("Invalid Character[" +
        leftPos + "," + rightPos + "] = '" + charValue + "' out of range 0 to " + charMax);
  }
  return charValue;
}

代码示例来源:origin: commons-validator/commons-validator

/**
 * Convert a character at a specified position to an integer value.
 *
 * @param character The character to convert
 * @param leftPos The position of the character in the code, counting from left to right
 * @param rightPos The position of the character in the code, counting from right to left
 * @return The integer value of the character
 * @throws CheckDigitException if character is not alphanumeric
 */
@Override
protected int toInt(char character, int leftPos, int rightPos)
    throws CheckDigitException {
  int charValue = Character.getNumericValue(character);
  // the final character is only allowed to reach 9
  final int charMax = rightPos == 1 ? 9 : 35;  // CHECKSTYLE IGNORE MagicNumber
  if (charValue < 0 || charValue > charMax) {
    throw new CheckDigitException("Invalid Character[" +
        leftPos + "," + rightPos + "] = '" + charValue + "' out of range 0 to " + charMax);
  }
  return charValue;
}

代码示例来源:origin: commons-validator/commons-validator

/**
 * Convert a character at a specified position to an integer value.
 * <p>
 * <b>Note:</b> this implementation only handlers numeric values
 * For non-numeric characters, override this method to provide
 * character--&gt;integer conversion.
 *
 * @param character The character to convert
 * @param leftPos The position of the character in the code, counting from left to right (for identifiying the position in the string)
 * @param rightPos The position of the character in the code, counting from right to left (not used here)
 * @return The integer value of the character
 * @throws CheckDigitException if character is non-numeric
 */
protected int toInt(char character, int leftPos, int rightPos)
    throws CheckDigitException {
  if (Character.isDigit(character)) {
    return Character.getNumericValue(character);
  }
  throw new CheckDigitException("Invalid Character[" +
      leftPos + "] = '" + character + "'");
}

代码示例来源:origin: commons-validator/commons-validator

/**
 * Calculate the checksum.
 *
 * @param code The code to calculate the checksum for.
 * @param includesCheckDigit Whether the code includes the Check Digit or not.
 * @return The checksum value
 * @throws CheckDigitException if the code contains an invalid character (i.e. not numeric)
 */
private int calculateChecksum(String code, boolean includesCheckDigit) throws CheckDigitException {
  int checksum = 0;
  for (int i = 0; i < code.length(); i++) {
    int idx = code.length() - (i + 1);
    int num = Character.getNumericValue(code.charAt(idx));
    if (num < 0 || num > 9) { // CHECKSTYLE IGNORE MagicNumber
      throw new CheckDigitException("Invalid Character[" +
          i + "] = '" + ((int)code.charAt(idx)) + "'");
    }
    int pos = includesCheckDigit ? i : i + 1;
    checksum = D_TABLE[checksum][P_TABLE[pos % 8][num]]; // CHECKSTYLE IGNORE MagicNumber
  }
  return checksum;
}

代码示例来源:origin: DiUS/java-faker

public String gtin8() {
  char[] values = faker.regexify("\\d{7}").toCharArray();
  int sum = 0;
  for (int i = 0; i < values.length; i++) {
    sum += Character.getNumericValue(values[i]) * GTIN_8_CHECK_DIGITS[i];
  }
  int checkDigit = 10 - sum % 10;
  if (checkDigit == 10) {
    return new String(ArrayUtils.add(values, Character.forDigit(0, 10)));
  } else {
    return new String(ArrayUtils.add(values, Character.forDigit(checkDigit, 10)));
  }
}

代码示例来源:origin: DiUS/java-faker

public String gtin13() {
  char[] values = faker.regexify("\\d{12}").toCharArray();
  int sum = 0;
  for (int i = 0; i < values.length; i++) {
    sum += Character.getNumericValue(values[i]) * GTIN_13_CHECK_DIGITS[i];
  }
  int checkDigit = 10 - sum % 10;
  if (checkDigit == 10) {
    return new String(ArrayUtils.add(values, Character.forDigit(0, 10)));
  } else {
    return new String(ArrayUtils.add(values, Character.forDigit(checkDigit, 10)));
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Very efficient method for parsing an {@link Integer} from the given {@literal Buffer}. Much faster than {@link
 * Integer#parseInt(String)}.
 *
 * @param b The {@literal Buffer} to slice.
 * @return The int value or {@literal null} if the {@literal Buffer} could not be read.
 */
public static Integer parseInt(Buffer b) {
  if (b.remaining() == 0) {
    return null;
  }
  b.snapshot();
  int len = b.remaining();
  int num = 0;
  int dec = 1;
  for (int i = (b.position + len); i > b.position; ) {
    char c = (char) b.buffer.get(--i);
    num += Character.getNumericValue(c) * dec;
    dec *= 10;
  }
  b.reset();
  return num;
}

代码示例来源:origin: jphp-group/jphp

@FastMethod
  @Signature(@Arg("char"))
  public static Memory number(Environment env, Memory... args) {
    return LongMemory.valueOf(Character.getNumericValue(chr(args[0])));
  }
}

相关文章

Character类方法