Is Smaller
by Isai Damier, Android Engineer @ Google

/*******************************************************************
 * Author: Isai Damier
 * Title: LargeInteger.java
 * Project: geekviewpoint
 * Package: datastructure
 *
 * Description: Normally modern computers cannot handle very large
 *    numbers. So the task here is to create a datastructure that
 *    can handle numbers of perhaps infinite size. And to prove that
 *    the datastructure works, included are arithmetic operators.
 *
 *    Naturally the numbers are represented as Strings. And to
 *    perform addition and subtraction, stacks are used as the media.
 *    Finally, as any trusty calculator, this datastructure returns
 *    erroneous values for erroneous inputs and correct values for
 *    correct inputs. This is to say, if an input string does not
 *    represent a valid decimal integer, then the output string
 *    will be bogus.
 ******************************************************************/ 
 import java.util.Stack;

public class LargeInteger {

  private String number;

  public LargeInteger(String number) {
    this.number = number;
  }//constructor

  /***************************************************************
   * Function: isSmaller
   * Inputs: @param n
   *         The value to compare against this LargeInteger
   * Output: boolean
   *
   * Description: Indicate whether this LargeInteger is smaller
   *    than n.
   *
   * Technical Details: Brute force.
   *
   **************************************************************/
  public boolean isSmaller(String n) {
    if (this.number.length() < n.length()) {
      return true;
    }
    if (this.number.length() == n.length()) {
      for (int i = 0; i < n.length(); i++) {
        if (this.number.charAt(i) < n.charAt(i)) {
          return true;
        } else if (this.number.charAt(i) > n.charAt(i)) {
          return false;
        }
      }
    }
    return false;
  }
}
import org.junit.Test;
import static org.junit.Assert.*;

public class LargeIntegerTest {

  /**
   * Test of isSmaller method, of class LargeInteger.
   */
  @Test
  public void testIsSmaller() {
    System.out.println("isSmaller");

    String a = "8787284297498234897287345";
    String b = "7971813897918381831891879249579839712938";
    LargeInteger bigA = new LargeInteger(a);
    assertTrue(bigA.isSmaller(b));
  }
}