List of usage examples for java.lang Character getNumericValue
public static int getNumericValue(int codePoint)
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
public int checkForYear(CharSequence cs) { int year = 0; if (cs.length() == 4) { for (int i = 0; i < 4; i++) { if (Character.isDigit(cs.charAt(i))) { year = year * 10;//from w w w .j av a 2s . co m year = year + Character.getNumericValue(cs.charAt(i)); } else { return -1; } } } return year; }
From source file:com.prowidesoftware.swift.model.IBAN.java
/** * Translate letters to numbers, also ignoring non alphanumeric characters * * @param bban//from w w w. j a v a 2 s.c om * @return the translated value */ public String translateChars(final StringBuilder bban) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < bban.length(); i++) { char c = bban.charAt(i); if (Character.isLetter(c)) { result.append(Character.getNumericValue(c)); } else { result.append((char) c); } } return result.toString(); }
From source file:br.com.nordestefomento.jrimum.vallia.digitoverificador.Modulo.java
/** * <p>//from w w w . j a v a 2s .c om * Realiza o clculo da soma na forma do mdulo 11. * </p> * <p> * O mdulo 11 funciona da seguinte maneira: * </p> * <p> * Cada dgito do nmero, comeando da direita para a esquerda (menos * significativo para o mais significativo), multiplicado pelo nmeros * limite mnimo, limite mnimo + 1, limite mnimo + 2 e assim * sucessivamente at o limite mxmio definido, ento inicia-se novamente a * contagem. * </p> * <p> * Exemplo para o nmero <tt>654321</tt>: * * <pre> * +---+---+---+---+---+---+ * | 6 | 5 | 4 | 3 | 2 | 1 | * +---+---+---+---+---+---+ * | | | | | | * x7 x6 x5 x4 x3 x2 * | | | | | | * =42 =30 =20 =12 =6 =2 * +---+---+---+---+---+-> * </pre * * </p> * * @param numero * @param limiteMin * @param limiteMax * @return * @throws IllegalArgumentException * * @since 0.2 */ public static int calculeSomaSequencialMod11(String numero, int limiteMin, int limiteMax) throws IllegalArgumentException { int peso = 0; int soma = 0; if (StringUtils.isNotBlank(numero) && StringUtils.isNumeric(numero)) { StringBuilder sb = new StringBuilder(numero); sb.reverse(); peso = limiteMin; for (char c : sb.toString().toCharArray()) { soma += peso * Character.getNumericValue(c); peso++; if (peso > limiteMax) peso = limiteMin; } } else throw new IllegalArgumentException(O_ARGUMENTO_DEVE_CONTER_APENAS_NUMEROS); return soma; }
From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java
static void determineJSR77Case(String url, MBeanServerConnection mServer) { try {/*from w w w.j av a 2s . c o m*/ ObjectName server = new ObjectName(ServerQuery.SERVER_NAME); String version = (String) mServer.getAttribute(server, ServerQuery.ATTR_VERSION); if (version.length() < 5) { return; } boolean lc; int majorVersion = Character.getNumericValue(version.charAt(0)); if (majorVersion >= 4) { //4.x, 5.x lc = true; } else if (Character.getNumericValue(version.charAt(4)) >= 8) { //3.2.8 lc = true; } else { //<= 3.2.7 lc = false; } synchronized (lowerCaseURLMappings) { lowerCaseURLMappings.put(url, lc ? Boolean.TRUE : Boolean.FALSE); } if (log.isDebugEnabled()) { log.debug(url + " " + version + " jsr77LowerCase=" + lc); } } catch (Exception e) { //unlikely, but in this case, leave it to the server type to determine the case } }
From source file:org.opencms.loader.CmsDefaultFileNameGenerator.java
/** * Internal method for file name generation, decoupled for testing.<p> * //w ww .j a v a 2 s.c o m * @param fileNames the list of file names already existing in the folder * @param checkPattern the pattern to be used when generating the new resource name * @param defaultDigits the default number of digits to use for numbering the created file names * * @return a new resource name based on the provided OpenCms user context and name pattern */ protected String getNewFileNameFromList(List<String> fileNames, String checkPattern, int defaultDigits) { String checkFileName, checkTempFileName; CmsMacroResolver resolver = CmsMacroResolver.newInstance(); String macro = I_CmsFileNameGenerator.MACRO_NUMBER; int useDigits = defaultDigits; int prefixIndex = checkPattern.indexOf(MACRO_NUMBER_START); if (prefixIndex >= 0) { // this macro contains an individual digit setting char n = checkPattern.charAt(prefixIndex + MACRO_NUMBER_START.length()); macro = macro + ':' + n; useDigits = Character.getNumericValue(n); } CmsNumberFactory numberFactory = new CmsNumberFactory(useDigits); resolver.addDynamicMacro(macro, numberFactory); int j = 0; do { numberFactory.setNumber(++j); // resolve macros in file name checkFileName = resolver.resolveMacros(checkPattern); // get name of the resolved temp file checkTempFileName = CmsWorkplace.getTemporaryFileName(checkFileName); } while (fileNames.contains(checkFileName) || fileNames.contains(checkTempFileName)); return checkFileName; }
From source file:com.salesmanager.core.util.CreditCardUtil.java
private void luhnValidate(String numberString) throws CreditCardUtilException { 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]); }/*from w ww .j a v a 2 s . c om*/ 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) throw new CreditCardUtilException(LabelUtil.getInstance().getText("errors.creditcard.invalidnumber")); }
From source file:org.alfresco.extension.deployment.reports.impl.DeploymentReportCleanupServiceImpl.java
/** * Helpful utility method for debugging when strings that appear equal aren't. * @param array/*from w w w . jav a 2 s. c o m*/ * @return */ private String charArrayToString(final char[] array) { StringBuffer result = null; if (array != null) { result = new StringBuffer(array.length * 2 + 2); result.append('['); for (int i = 0; i < array.length; i++) { if (i > 0) { result.append(','); } result.append(Character.getNumericValue(array[i])); } result.append(']'); } return (result == null ? null : result.toString()); }
From source file:org.apache.axis2.jaxws.util.WSToolingUtils.java
/** * Parse the input string and return an integer value based on it. It will look for the first numeric value * in the string then use all digits up to the next non-numeric value or end of the string as the basis for * the value. For example "JAX-WS RI 27" will return the value 27. * @param s - String containing the integer to be returned. * @return a value or -1 if not integer value was found in the token. *//* w w w . j a v a 2 s . c om*/ private static int getIntegerValue(String s) { int returnValue = -1; // Build up a buffer containing any digits up to the first non-numeric character. StringBuffer valueString = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (Character.isDigit(ch)) { valueString.append(Character.getNumericValue(ch)); } else if (valueString.length() > 0) { // We've found some numbers then encountered the first non-numeric value, so // exit the loop and use those numbers as the value break; } } // If there were any numeric values found in the string, convert them to the integer return value if (valueString.length() > 0) { returnValue = Integer.valueOf(valueString.toString()); } return returnValue; }
From source file:br.com.nordestefomento.jrimum.vallia.digitoverificador.Modulo.java
/** * <p>//w ww.j ava 2 s . c om * Realiza o clculo da soma na forma do mdulo 10. * </p> * <p> * O mdulo 10 funciona da seguinte maneira: * </p> * <p> * Cada dgito do nmero, comeando da direita para a esquerda (menos * significativo para o mais significativo), multiplicado pelo nmeros * limite mnimo, limite mnimo + 1, limite mnimo + 2 e assim * sucessivamente at o limite mxmio definido, ento inicia-se novamente a * contagem. * </p> * <p> * Exemplo para o nmero <tt>123456</tt>: * * <pre> * +---+---+---+---+---+---+ * | 1 | 2 | 3 | 4 | 5 | 6 | * +---+---+---+---+---+---+ * | | | | | | * x1 x2 x1 x2 x1 x2 * | | | | | | * =1 =4 =3 =8 =5 =[ 3 <= ( 1 + 2 <==12 ) ] = 24 * +---+---+---+---+---+-> = (24 / 10) = 3, resto 3; Ento o mdulo igual a 3. * </pre> * * </p> * * <p> * Geralmente os limites para o mdulo 10 so mnimo 1 e mximo 2 apenas. * </p> * * @param numero * @param limiteMin * @param limiteMax * @return soma sequencial usada no clculo do mdulo * @throws IllegalArgumentException * * @since 0.2 */ public static int calculeSomaSequencialMod10(String numero, int limiteMin, int limiteMax) throws IllegalArgumentException { int produto = 0; int peso = 0; int soma = 0; if (StringUtils.isNotBlank(numero) && StringUtils.isNumeric(numero)) { StringBuilder sb = new StringBuilder(numero); sb.reverse(); peso = limiteMax; for (char c : sb.toString().toCharArray()) { produto = peso * Character.getNumericValue(c); if (produto > 9) { soma += produto / 10; soma += produto % 10; } else soma += produto; peso = (peso == limiteMax) ? limiteMin : limiteMax; } } else throw new IllegalArgumentException(O_ARGUMENTO_DEVE_CONTER_APENAS_NUMEROS); return soma; }
From source file:de.jfachwert.math.PackedDecimal.java
/** * Liefert den uebergebenen String als {@link PackedDecimal} zurueck. * Diese Methode ist dem Konstruktor vorzuziehen, da fuer gaengige Zahlen * wie "0" oder "1" immer das gleiche Objekt zurueckgegeben wird. * <p>// ww w . j ava 2s.c o m * Im Gegensatz zum String-Konstruktor darf man hier auch 'null' als Wert * uebergeben. In diesem Fall wird dies in {@link #EMPTY} uebersetzt. * </p> * <p> * Die erzeugten PackedDecimals werden intern in einem "weak" Cache * abgelegt, damit bei gleichen Zahlen auch die gleichen PackedDecimals * zurueckgegeben werden. Dies dient vor allem zur Reduktion des * Speicherverbrauchs. * </p> * * @param zahl String aus Zahlen * @return Zahl als {@link PackedDecimal} */ public static PackedDecimal valueOf(String zahl) { String trimmed = StringUtils.trimToEmpty(zahl); if (StringUtils.isEmpty(trimmed)) { return EMPTY; } if ((trimmed.length() == 1 && Character.isDigit(trimmed.charAt(0)))) { return CACHE[Character.getNumericValue(trimmed.charAt(0))]; } else { return WEAK_CACHE.computeIfAbsent(zahl, PackedDecimal::new); } }