Formatter Class

package javaxt.geospatial.coordinate;


//******************************************************************************
//**  Coordinate Formatter - By Peter Borissow
//******************************************************************************
/**
 *   Used to format coordinates
 *
 ******************************************************************************/

public class Formatter {
    
    private Formatter(){}
    
    
  //****************************************************************************
  //** Convert DMS (DD:MM:SS.SS) to Decimal Degress (DD.DDDDDD)
  //****************************************************************************
  /**  */

    public static double ConvertDMStoDD(String str){

       if (instr(ucase(str),"S")>0 || instr(ucase(str),"W")>0) str = "-" + str;


       String[] chars = ("N,n,E,e,S,s,W,s").split(",");
       for (int i=0; i<chars.length; i++){
           str = str.replace((CharSequence) chars[i], (CharSequence) "");
       }

       if (instr(str,":") == 0) { 
           return cdbl(str);
       }

       double Degrees = 0;
       double Minutes = 0;
       double Seconds = 0;

       String[] seg = str.split(":"); //split(str,":");
       for (int i=0; i<seg.length; i++){
           double inum = cdbl(seg[i]);

           if (i==0) { //Degrees
              Degrees = inum;
           }

           if (i==1) { //Minutes
              Minutes = inum;
           }

           if (i==2) { //Seconds
              Seconds = inum;
           }

       }
       
       if (Degrees<0){
           Minutes = -Minutes;
           Seconds = -Seconds;
       }
       

       return Degrees + ((Minutes+(Seconds/60))/60);

    /*   
       'response.write "========================<br>"
       'response.write "Degrees: " & Degrees & "<br>"
       'response.write "Minutes: " & Minutes & "<br>"
       'response.write "Seconds: " & Seconds & "<br>"
       'response.write "========================<br>"
    */

    }


  //**************************************************************************
  //** String Utils - Artifacts from VB Port
  //**************************************************************************
    
    private static int instr(String str, String ch){ return str.indexOf(ch)+1; }
    private static String ucase(String str){ return str.toUpperCase(); }
    private static double cdbl(String str){return Double.valueOf(str).doubleValue(); }

}