/** * This represents an Integer Patricia Tree instance. * Each Tree has at least the zeroth node or the root * which may have zero or more (< 10) child nodes * Each node is represented by an object of type Element * The presence of Element at the index indicates that * the value equal to the index is present in the tree */ public class DATree { private Element zerothNode = new Element(); private int depth; /** * This would insert a number in the tree. * This works by tokenizing the number into separate * characters and then inserting them one by one in * the tree. If the number already exists at that depth * then the next character is taken and the tree is * further traversed. This is done until the entire * number is entered in the tree.The maximum depth of * the tree is the size of the number as returned by * the length() method on the String form of that number */ public void insert (String number) { try { char[] numberArray = number.toCharArray(); Element currentElement = zerothNode; Element tempElement = null; for(int i=0; i * DATree ipt; * ipt.insert("2345"); * ipt.stripPatternFromNumber("234567"); // returns 67 * ipt.stripPatternFromNumber("23456"); // returns 6 * ipt.stripPatternFromNumber("2345"); // returns null * ipt.stripPatternFromNumber("234"); // returns null * ipt.stripPatternFromNumber("877"); // returns null * */ public String stripPatternFromNumber(String number) { try { char[] numberArray = number.toCharArray(); Element currentElement = zerothNode; Element tempElement = null; for(int i=0; i= '0') & (numberArray[i] <= '9')) { if ((tempElement=currentElement.getElementAt(numberArray[i]-'0')) == null){ if((currentElement.isLeaf())&(currentElement != zerothNode)){ return number.substring(i); } else { return null; } } else { currentElement = tempElement; } } else { return null; } } return null; } catch (Exception e) { e.printStackTrace(); System.out.println("Error in searching number "+number+" "+ e.getMessage()); return null; } } }