List of usage examples for java.lang Character getNumericValue
public static int getNumericValue(int codePoint)
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.FiskInfoUtility.java
public boolean validateIMO(String imo) { boolean success = false; if (imo != null && ((imo.length() == 7 && imo.substring(0, 1).matches("[0-9]") && imo.matches("^[0-9]*$")))) { int[] imoCheckArray = new int[6]; int checkSum = 0; for (int i = 0; i < 6; i++) { imoCheckArray[i] = Character.getNumericValue(imo.charAt(i)); }//from w w w . ja va2 s . c om for (int i = 0; i < 6; i++) { checkSum += imoCheckArray[i] * (7 - i); } success = Character.getNumericValue(imo.charAt(imo.length() - 1)) == checkSum % 10; } return success; }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Replace instances of "^1", "^2", etc. in the * <code>template</code> CharSequence with the corresponding * <code>values</code>. "^^" is used to produce a single caret in * the output. Only up to 9 replacement values are supported, * "^10" will be produce the first replacement value followed by a * '0'./*from ww w . j a v a2s. c o m*/ * * @param template the input text containing "^1"-style * placeholder values. This object is not modified; a copy is * returned. * * @param values CharSequences substituted into the template. The * first is substituted for "^1", the second for "^2", and so on. * * @return the new CharSequence produced by doing the replacement * * @throws IllegalArgumentException if the template requests a * value that was not provided, or if more than 9 values are * provided. */ public static CharSequence expandTemplate(CharSequence template, CharSequence... values) { if (values.length > 9) { throw new IllegalArgumentException("max of 9 values are supported"); } SpannableStringBuilder ssb = new SpannableStringBuilder(template); try { int i = 0; while (i < ssb.length()) { if (ssb.charAt(i) == '^') { char next = ssb.charAt(i + 1); if (next == '^') { ssb.delete(i + 1, i + 2); ++i; continue; } else if (Character.isDigit(next)) { int which = Character.getNumericValue(next) - 1; if (which < 0) { throw new IllegalArgumentException("template requests value ^" + (which + 1)); } if (which >= values.length) { throw new IllegalArgumentException("template requests value ^" + (which + 1) + "; only " + values.length + " provided"); } ssb.replace(i, i + 2, values[which]); i += values[which].length(); continue; } } ++i; } } catch (IndexOutOfBoundsException ignore) { // happens when ^ is the last character in the string. } return ssb; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.impl.DeIdentifiedExportServiceImpl.java
public List<PersonAttributeType> getSavedPersonAttributeList(Integer pid) { PersonService ps = Context.getPersonService(); DeIdentifiedExportService d = Context.getService(DeIdentifiedExportService.class); List<String> list = d.getConceptsByCategoryByPid("PersonAttribute", pid); List<PersonAttributeType> attributeTypeList = new Vector<PersonAttributeType>(); for (int i = 0; i < list.size(); i++) { char retval[] = list.get(i).toCharArray(); for (int j = 0; j < retval.length; j += 2) { Integer t = Character.getNumericValue(retval[j]); attributeTypeList.add(ps.getPersonAttributeType(t)); }/*from w w w . j a v a2 s .c om*/ } return attributeTypeList; }
From source file:example.rest.ApiREST.java
public String checkIfExistsAndReturnValidFolder(String fileName, String name) { //System.out.println("Check if folder exists: " + fileName); //System.out.println("File name : " + name); nombreFinal = name;// w ww . j a v a2 s . co m File f = new File(fileName); if (f.exists() && f.isDirectory()) { //System.out.println("SI EXISTE : " + name); if (name.length() > 3) { String prueba = name.substring(name.length() - 3, name.length()); //System.out.println("prueba : " + prueba); if (prueba.charAt(0) == '(' && Character.isDigit(prueba.charAt(1)) && prueba.charAt(2) == ')') { //System.out.println("Estamos en lo correctop"); int i = Character.getNumericValue(prueba.charAt(1)); i++; String nuevo = name.substring(0, name.length() - 3) + "(" + i + ")"; String ruta = fileName.substring(0, fileName.lastIndexOf(name)); ruta = ruta + nuevo; return checkIfExistsAndReturnValidFolder(ruta, nuevo); } } else { } num++; String nameASumar = name; String ruta = fileName.substring(0, fileName.lastIndexOf(name)); //System.out.println("nombreOriginal : " + nombreOriginal); ruta = ruta + nombreOriginal + "(" + num + ")"; //System.out.println("ruta final antes de mandar:" + ruta); return checkIfExistsAndReturnValidFolder(ruta, nombreOriginal + "(" + num + ")"); } else { return fileName; } }
From source file:org.apache.hadoop.mapred.split.TestGroupedSplits.java
private void verifySplitsFortestAllowSmallSplitsEarly(InputSplit[] groupedSplits) throws IOException { Map<String, MutableInt> matchedLocations = new HashMap<>(); for (int i = 0; i < 8; i++) { TezGroupedSplit group = (TezGroupedSplit) groupedSplits[i]; assertEquals(1, group.getLocations().length); assertEquals(3, group.getGroupedSplits().size()); String matchedLoc = group.getLocations()[0]; MutableInt count = matchedLocations.get(matchedLoc); if (count == null) { count = new MutableInt(0); matchedLocations.put(matchedLoc, count); }//from w ww .j a v a2 s .c o m count.increment(); } for (Map.Entry<String, MutableInt> entry : matchedLocations.entrySet()) { String loc = entry.getKey(); int nodeId = Character.getNumericValue(loc.charAt(loc.length() - 1)); assertTrue(nodeId < 4); assertTrue(loc.startsWith("node") && loc.length() == 5); assertEquals(2, entry.getValue().getValue()); } }
From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java
/** * ?????????????//from w ww . ja v a 2 s . com * * @param date * @param ptn * @param startDate * @param limitDate * @return */ public static boolean isView(ALDateTimeField date, String ptn, Date startDate, Date limitDate) { int count = 0; boolean result = false; Calendar cal = Calendar.getInstance(); cal.setTime(date.getValue()); // if (ptn.charAt(0) == 'D') { result = true; count = 1; // , } else if (ptn.charAt(0) == 'W') { int dow = cal.get(Calendar.DAY_OF_WEEK); // ?? int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH); if (ptn.charAt(8) == 'N' || ptn.charAt(8) == 'L' || dowim == Character.getNumericValue(ptn.charAt(8))) { switch (dow) { // case Calendar.SUNDAY: result = ptn.charAt(1) != '0'; break; // case Calendar.MONDAY: result = ptn.charAt(2) != '0'; break; // ? case Calendar.TUESDAY: result = ptn.charAt(3) != '0'; break; // case Calendar.WEDNESDAY: result = ptn.charAt(4) != '0'; break; // case Calendar.THURSDAY: result = ptn.charAt(5) != '0'; break; // case Calendar.FRIDAY: result = ptn.charAt(6) != '0'; break; // case Calendar.SATURDAY: result = ptn.charAt(7) != '0'; break; default: result = false; break; } if (ptn.length() == 9) { count = 8; } else { count = 9; } } // } else if (ptn.charAt(0) == 'M') { int mday; if (ptn.substring(1, 3).equals("XX")) { mday = cal.getActualMaximum(Calendar.DATE); } else { mday = Integer.parseInt(ptn.substring(1, 3)); } result = Integer.parseInt(date.getDay()) == mday; count = 3; } else if (ptn.charAt(0) == 'Y') { int ymonth = Integer.parseInt(ptn.substring(1, 3)); int yday = Integer.parseInt(ptn.substring(3, 5)); int month = Integer.parseInt(date.getMonth()); int day = Integer.parseInt(date.getDay()); if (ymonth == month && yday == day) { result = true; count = 5; } else { result = false; } } else { return true; } if (result) { if (ptn.charAt(count) == 'L') { // ???? if (equalsToDate(startDate, date.getValue(), false) || equalsToDate(limitDate, date.getValue(), false)) { // ??? result = true; } else { // ???????????? result = result && startDate.before(cal.getTime()) && limitDate.after(cal.getTime()); } } } return result; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.hl7.HL7MapToLexGrid.java
public String getIntValue(String code) { char[] chars = code.toCharArray(); StringBuffer buffer = new StringBuffer(); for (char c : chars) { int integer = Character.getNumericValue(c); buffer.append(String.valueOf(integer)); }//from ww w . j ava 2 s . c o m return buffer.toString(); }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
public static int hashcode(GPOMutable gpo) { int hashCode = 0; {//from w w w. j a v a2s . c o m String[] stringArray = gpo.getFieldsString(); if (stringArray != null) { for (int index = 0; index < stringArray.length; index++) { hashCode ^= stringArray[index].hashCode(); } } } { boolean[] booleanArray = gpo.getFieldsBoolean(); if (booleanArray != null) { for (int index = 0; index < booleanArray.length; index++) { hashCode ^= booleanArray[index] ? 1 : 0; } } } { char[] charArray = gpo.getFieldsCharacter(); if (charArray != null) { for (int index = 0; index < charArray.length; index++) { hashCode ^= Character.getNumericValue(charArray[index]); } } } { byte[] byteArray = gpo.getFieldsByte(); if (byteArray != null) { for (int index = 0; index < byteArray.length; index++) { hashCode ^= byteArray[index]; } } } { short[] shortArray = gpo.getFieldsShort(); if (shortArray != null) { for (int index = 0; index < shortArray.length; index++) { hashCode ^= shortArray[index]; } } } { int[] integerArray = gpo.getFieldsInteger(); if (integerArray != null) { for (int index = 0; index < integerArray.length; index++) { hashCode ^= integerArray[index]; } } } { long[] longArray = gpo.getFieldsLong(); if (longArray != null) { for (int index = 0; index < longArray.length; index++) { hashCode ^= longArray[index]; } } } { float[] floatArray = gpo.getFieldsFloat(); if (floatArray != null) { for (int index = 0; index < floatArray.length; index++) { hashCode ^= Float.floatToIntBits(floatArray[index]); } } } { double[] doubleArray = gpo.getFieldsDouble(); if (doubleArray != null) { for (int index = 0; index < doubleArray.length; index++) { hashCode ^= Double.doubleToLongBits(doubleArray[index]); } } } { Object[] objectArray = gpo.getFieldsObject(); if (objectArray != null) { for (int index = 0; index < objectArray.length; index++) { hashCode ^= objectArray[index].hashCode(); } } } return hashCode; }
From source file:com.datatorrent.lib.appdata.gpo.GPOUtils.java
/** * This function computes the hashcode of a {@link GPOMutable} based on a specified subset of its data. * <br/>/*from ww w. j av a2s . c o m*/ * <br/> * <b>Note:</b> In some cases a {@link GPOMutable} object contains a field which is bucketed. In the case of * bucketed fields, you may want to preserve the original value of the field, but only use the bucketed value * of the field for computing a hashcode. In order to do this you can store the original value of {@link GPOMutable}'s * field before calling this function, and replace it with the bucketed value. Then after the hashcode is computed, the * original value of the field can be restored. * * @param gpo The {@link GPOMutable} to compute a hashcode for. * @param indexSubset The subset of the {@link GPOMutable} used to compute the hashcode. * @return The hashcode for the given {@link GPOMutable} computed from the specified subset of its data. */ public static int indirectHashcode(GPOMutable gpo, IndexSubset indexSubset) { int hashCode = 7; final int hashMultiplier = 23; { String[] stringArray = gpo.getFieldsString(); int[] srcIndex = indexSubset.fieldsStringIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + stringArray[srcIndex[index]].hashCode(); } } } { boolean[] booleanArray = gpo.getFieldsBoolean(); int[] srcIndex = indexSubset.fieldsBooleanIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + (booleanArray[srcIndex[index]] ? 1 : 0); } } } { char[] charArray = gpo.getFieldsCharacter(); int[] srcIndex = indexSubset.fieldsCharacterIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + Character.getNumericValue(charArray[srcIndex[index]]); } } } { byte[] byteArray = gpo.getFieldsByte(); int[] srcIndex = indexSubset.fieldsByteIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + byteArray[srcIndex[index]]; } } } { short[] shortArray = gpo.getFieldsShort(); int[] srcIndex = indexSubset.fieldsShortIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + shortArray[srcIndex[index]]; } } } { int[] integerArray = gpo.getFieldsInteger(); int[] srcIndex = indexSubset.fieldsIntegerIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + integerArray[srcIndex[index]]; } } } { long[] longArray = gpo.getFieldsLong(); int[] srcIndex = indexSubset.fieldsLongIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } long element = longArray[srcIndex[index]]; int elementHash = (int) (element ^ (element >>> 32)); hashCode = hashMultiplier * hashCode + elementHash; } } } { float[] floatArray = gpo.getFieldsFloat(); int[] srcIndex = indexSubset.fieldsFloatIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + Float.floatToIntBits(floatArray[srcIndex[index]]); } } } { double[] doubleArray = gpo.getFieldsDouble(); int[] srcIndex = indexSubset.fieldsDoubleIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } long element = Double.doubleToLongBits(doubleArray[srcIndex[index]]); int elementHash = (int) (element ^ (element >>> 32)); hashCode = hashMultiplier * hashCode + elementHash; } } } { Object[] objectArray = gpo.getFieldsObject(); int[] srcIndex = indexSubset.fieldsObjectIndexSubset; if (srcIndex != null) { for (int index = 0; index < srcIndex.length; index++) { if (srcIndex[index] == -1) { continue; } hashCode = hashMultiplier * hashCode + objectArray[srcIndex[index]].hashCode(); } } } return hashCode; }
From source file:net.sf.firemox.xml.magic.Oracle2Xml.java
/** * Expected mana structure is [X]*[0-9]+([U][B][G][R][W])* * /* w w w . jav a 2s . c om*/ * @param line * The string containing ONLY the manacost. * @return an integer array {colorless, black, blue, green, red, white, x * occurrences} */ private int[] extractManaCost(String line) { final int[] res = new int[7]; for (int i = 0; i < line.length(); i++) { final char mana = line.charAt(i); switch (mana) { case 'b': res[1]++; break; case 'u': res[2]++; break; case 'g': res[3]++; break; case 'r': res[4]++; break; case 'w': res[5]++; break; case 'x': res[6]++; break; default: // colorless mana int a = Character.getNumericValue(mana); if (a > 0 && a < 10) res[0] += a; } } return res; }