PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Prototipo/MemoriaUtils/src/memoria/utils/coordinate/LatZones.java

http://prototipomemoria.googlecode.com/
Java | 123 lines | 97 code | 18 blank | 8 comment | 19 complexity | 3c4028c2ac97a97e500a5f4a5bf3f433 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6package memoria.utils.coordinate;
  7
  8/**
  9 *
 10 * @author diego
 11 */
 12public class LatZones {
 13    private static char[] letters = { 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
 14        'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z' };
 15
 16    private static int[] degrees = { -90, -84, -72, -64, -56, -48, -40, -32, -24, -16,
 17        -8, 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84 };
 18
 19    private static char[] negLetters = { 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
 20        'L', 'M' };
 21
 22    private static int[] negDegrees = { -90, -84, -72, -64, -56, -48, -40, -32, -24,
 23        -16, -8 };
 24
 25    private static char[] posLetters = { 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
 26        'X', 'Z' };
 27
 28    private static int[] posDegrees = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 84 };
 29
 30    private static int arrayLength = 22;
 31
 32    public LatZones()
 33    {
 34    }
 35
 36    public static int getLatZoneDegree(String letter)
 37    {
 38      char ltr = letter.charAt(0);
 39      for (int i = 0; i < arrayLength; i++)
 40      {
 41        if (letters[i] == ltr)
 42        {
 43          return degrees[i];
 44        }
 45      }
 46      return -100;
 47    }
 48
 49    public static String getLatZone(double latitude)
 50    {
 51      int latIndex = -2;
 52      int lat = (int) latitude;
 53
 54      if (lat >= 0)
 55      {
 56        int len = posLetters.length;
 57        for (int i = 0; i < len; i++)
 58        {
 59          if (lat == posDegrees[i])
 60          {
 61            latIndex = i;
 62            break;
 63          }
 64
 65          if (lat > posDegrees[i])
 66          {
 67            continue;
 68          }
 69          else
 70          {
 71            latIndex = i - 1;
 72            break;
 73          }
 74        }
 75      }
 76      else
 77      {
 78        int len = negLetters.length;
 79        for (int i = 0; i < len; i++)
 80        {
 81          if (lat == negDegrees[i])
 82          {
 83            latIndex = i;
 84            break;
 85          }
 86
 87          if (lat < negDegrees[i])
 88          {
 89            latIndex = i - 1;
 90            break;
 91          }
 92          else
 93          {
 94            continue;
 95          }
 96
 97        }
 98
 99      }
100
101      if (latIndex == -1)
102      {
103        latIndex = 0;
104      }
105      if (lat >= 0)
106      {
107        if (latIndex == -2)
108        {
109          latIndex = posLetters.length - 1;
110        }
111        return String.valueOf(posLetters[latIndex]);
112      }
113      else
114      {
115        if (latIndex == -2)
116        {
117          latIndex = negLetters.length - 1;
118        }
119        return String.valueOf(negLetters[latIndex]);
120
121      }
122    }
123}