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