001 package ps6.tigerdb;
002
003 import ps2.GeoPoint;
004
005 /**
006 * TigerRT1 represents a Complete-Chain Basic Data Record.
007 *
008 * @author Felix S. Klock II
009 */
010 public class TigerRT1 extends TigerRwTLID {
011
012
013 public static final long serialVersionUID = 4534;
014 private GeoPoint from, to;
015 private Feature feature;
016
017 private DirectedStreetNumberRange lftRange;
018 private DirectedStreetNumberRange rgtRange;
019
020 private String cfc;
021
022 private String lftZip;
023 private String rgtZip;
024
025 public String toString() {
026 return "TigerRT1< "+from+", "+to+
027 ", "+feature+
028 ", "+lftRange+", "+rgtRange+
029 ", "+lftZip+", "+rgtZip+
030 " >";
031 }
032
033 /** Constructs a TigerRT1 from a line of Record Type 1 as specified
034 * in the Data Dictionary for the Tiger/Line files.
035 */
036 public TigerRT1(String s) throws BadRecordException {
037 super(s, 228);
038 if (s.charAt(0) != '1')
039 die("RT1 record type must be 1, not "+s.charAt(0));
040
041 int lat1, lng1, lat2, lng2;
042 lat1 = lng1 = lat2 = lng2 = 0;
043 try {
044 lat1 = toInt(s.substring(190,200));
045 lng1 = toInt(s.substring(200,209));
046 lat2 = toInt(s.substring(209,219));
047 lng2 = toInt(s.substring(219,228));
048 // from = new GeoPoint(div1M(toInt(s.substring(190,200))),
049 // div1M(toInt(s.substring(200,209)))).intern();
050 // to = new GeoPoint(div1M(toInt(s.substring(209,219))),
051 // div1M(toInt(s.substring(219,228)))).intern();
052 if (lat1 == lat2 && lng1 == lng2) {
053 // System.out.println("XXX "+s + "\nXXX is zero length");
054 throw new BadRecordException(s, "zero length geosegment!");
055 }
056 } catch (NoInt e) {
057 throw new RuntimeException
058 (s.substring(190,228)+ " should contain two Points");
059 }
060 from = makeGP(lat1, lng1);
061 to = makeGP(lat2, lng2);
062
063 // Do not call Feature.intern(), since Feature is short-lived,
064 // and doesn't intern well
065 feature = new Feature(s.substring(17, 55));
066
067 cfc = s.substring(55,58);
068
069 lftRange = parseAddrRange(s.substring(58, 69), s.substring(69, 80));
070 rgtRange = parseAddrRange(s.substring(80, 91), s.substring(91, 102));
071
072 lftZip = s.substring(106, 111).intern();
073 rgtZip = s.substring(111, 116).intern();
074 }
075
076
077
078 /** Returns the primary name of this, or "" if this does not have
079 * a primary name. Right now the name contains the Primary
080 * Feature PrefixDirection, Name, Type, and SuffixDirection.
081 */
082 public String primaryName() { return feature.fullName(); }
083
084 public boolean hasAddress(int a) {
085 if (lftRange != null && lftRange.contains(a))
086 return true;
087 if (rgtRange != null && rgtRange.contains(a))
088 return true;
089 return false;
090 }
091
092 /**
093 * @return the CFC of this, whatever that is.
094 */
095 public String getCfc() {
096 return cfc;
097 }
098
099 /**
100 * @return the start of this RT1
101 */
102 public GeoPoint getStart() {
103 return from;
104 }
105
106 /**
107 * @return the end of this RT1
108 */
109 public GeoPoint getEnd() {
110 return to;
111 }
112
113 /**
114 * @return the feature assocated with this RT1
115 */
116 public Feature getFeature() {
117 return feature;
118 }
119
120 /**
121 * @return the left zipcode associated with this RT1
122 */
123
124 public String getLeftZip() {
125 return lftZip;
126 }
127
128
129 /**
130 * @return the right zipcode associated with this RT1
131 */
132
133 public String getRightZip() {
134 return rgtZip;
135 }
136
137 /**
138 * @return the left street number range associated with this RT1
139 */
140 public DirectedStreetNumberRange getLeftRange() {
141 return lftRange;
142 }
143
144
145 /**
146 * @return the right street number range associated with this RT1
147 */
148 public DirectedStreetNumberRange getRightRange() {
149 return rgtRange;
150 }
151
152
153 } // TigerRT1