Java implementation of line intersection