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        }
076    
077    
078    
079        /** Returns the primary name of this, or "" if this does not have
080         * a primary name.  Right now the name contains the Primary
081         * Feature PrefixDirection, Name, Type, and SuffixDirection.
082         */
083        public String primaryName() { return feature.fullName(); }
084    
085        public boolean hasAddress(int a) {
086            if (lftRange != null && lftRange.contains(a))
087                return true;
088            if (rgtRange != null && rgtRange.contains(a))
089                return true;
090            return false;
091        }
092    
093        /**
094         * @return the CFC of this, whatever that is.
095         */
096        public String getCfc() {
097            return cfc;
098        }
099    
100        /**
101         * @return the start of this RT1
102         */
103        public GeoPoint getStart() {
104            return from;
105        }
106    
107        /**
108         * @return the end of this RT1
109         */
110        public GeoPoint getEnd() {
111            return to;
112        }
113    
114        /**
115         * @return the feature assocated with this RT1
116         */
117        public Feature getFeature() {
118            return feature;
119        }
120    
121        /**
122         * @return the left zipcode associated with this RT1
123         */
124    
125        public String getLeftZip() {
126            return lftZip;
127        }
128    
129    
130        /**
131         * @return the right zipcode associated with this RT1
132         */
133    
134        public String getRightZip() {
135            return rgtZip;
136        }
137    
138        /**
139         * @return the left street number range associated with this RT1
140         */
141        public DirectedStreetNumberRange getLeftRange() {
142            return lftRange;
143        }
144    
145    
146        /**
147         * @return the right street number range associated with this RT1
148         */
149        public DirectedStreetNumberRange getRightRange() {
150            return rgtRange;
151        }
152    
153    
154    } // TigerRT1