Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Snake / Nibbles clone in C and Ncurses
Please improve
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Active Record getting unique records
Simple Particle Engine for a shooter game
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
ISIN check digit
<pre class='prettyprint' language='java'>package net.alessandropetrozzelli; class InvalidISINCharacterException extends Exception { InvalidISINCharacterException() { super(); } InvalidISINCharacterException(String s) { super(s); } } public class Isin { static final int numberTableOffset = '0'; static final int numberTableEndOffset = '9'; static final int charTableOffset = 'A'; static final int charTableEndOffset = 'Z'; private static int getIntValueForISINChar(final char c) throws InvalidISINCharacterException { int value = 0; if ( (c >= numberTableOffset) && (c <= numberTableEndOffset)) { value = c - numberTableOffset; } else if ( (c >= charTableOffset) && (c <= charTableEndOffset)) { value = 10 + (c - charTableOffset); } else { throw new InvalidISINCharacterException("Unsupported character: " + c); } return value; } private static int getSumOfDigits(final int number) { int sumOfDigits=0; if (number<=9) { sumOfDigits = number; } else { String s = String.valueOf(number); try { for (int i = 0; i < s.length(); i++) { sumOfDigits += getIntValueForISINChar(s.charAt(i)); } } catch (InvalidISINCharacterException ex) { System.out.println(ex); return -1; } } return sumOfDigits; } public static int getCheckDigit(final String isin) { int checkDigit = 0; if ( (isin == null) || (isin.length() != 11)) { return -1; } String incompleteISINcode = isin.toUpperCase(); StringBuffer buffer = new StringBuffer(); // convert every single character into number as specified try { for (int i = 0; i < incompleteISINcode.length(); i++) { buffer.append(getIntValueForISINChar(isin.charAt(i))); } } catch (InvalidISINCharacterException ex) { System.out.println(ex); return -1; } // sum all digits (multiplying odd digits by 2) try { for (int i = buffer.length() - 1; i >= 0; i--) { if ( (buffer.length() - i) % 2 == 1) { checkDigit += getSumOfDigits(getIntValueForISINChar(buffer.charAt(i)) * 2); } else { checkDigit += getIntValueForISINChar(buffer.charAt(i)); } } } catch (InvalidISINCharacterException ex) { // this should never happen System.out.println(ex); return -1; } // end result checkDigit = (10 - (checkDigit % 10)) % 10; return checkDigit; }</pre> <a href="http://www.refactormycode.com/codes/142-isin-check-digit" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>