001    package railo.runtime.sql.old;
002    
003    import java.util.Hashtable;
004    import java.util.StringTokenizer;
005    import java.util.Vector;
006    
007    public final class ZTuple
008    {
009    
010        public ZTuple()
011        {
012            attributes_ = new Vector();
013            values_ = new Vector();
014            searchTable_ = new Hashtable();
015        }
016    
017        public ZTuple(String s)
018        {
019            this();
020            for(StringTokenizer stringtokenizer = new StringTokenizer(s, ","); stringtokenizer.hasMoreTokens(); setAtt(stringtokenizer.nextToken().trim(), null));
021        }
022    
023        public void setRow(String s)
024        {
025            StringTokenizer stringtokenizer = new StringTokenizer(s, ",");
026            for(int i = 0; stringtokenizer.hasMoreTokens(); i++)
027            {
028                String s1 = stringtokenizer.nextToken().trim();
029                try
030                {
031                    Double double1 = new Double(s1);
032                    setAtt(getAttName(i), double1);
033                }
034                catch(Exception exception)
035                {
036                    setAtt(getAttName(i), s1);
037                }
038            }
039    
040        }
041    
042        public void setRow(Vector vector)
043        {
044            for(int i = 0; i < vector.size(); i++)
045                setAtt(getAttName(i), vector.elementAt(i));
046    
047        }
048    
049        public void setAtt(String s, Object obj)
050        {
051            if(s != null)
052            {
053                boolean flag = searchTable_.containsKey(s);
054                if(flag)
055                {
056                    int i = ((Integer)searchTable_.get(s)).intValue();
057                    values_.setElementAt(obj, i);
058                } else
059                {
060                    int j = attributes_.size();
061                    attributes_.addElement(s);
062                    values_.addElement(obj);
063                    searchTable_.put(s, Integer.valueOf(j));
064                }
065            }
066        }
067    
068        public String getAttName(int i)
069        {
070            try
071            {
072                return (String)attributes_.elementAt(i);
073            }
074            catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception)
075            {
076                return null;
077            }
078        }
079    
080        public int getAttIndex(String s)
081        {
082            if(s == null)
083                return -1;
084            Integer integer = (Integer)searchTable_.get(s);
085            if(integer != null)
086                return integer.intValue();
087            return -1;
088        }
089    
090        public Object getAttValue(int i)
091        {
092            try
093            {
094                return values_.elementAt(i);
095            }
096            catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception)
097            {
098                return null;
099            }
100        }
101    
102        public Object getAttValue(String s)
103        {
104            boolean flag = false;
105            if(s != null)
106                flag = searchTable_.containsKey(s);
107            if(flag)
108            {
109                int i = ((Integer)searchTable_.get(s)).intValue();
110                return values_.elementAt(i);
111            }
112            return null;
113            
114        }
115    
116        public boolean isAttribute(String s)
117        {
118            if(s != null)
119                return searchTable_.containsKey(s);
120            return false;
121        }
122    
123        public int getNumAtt()
124        {
125            return values_.size();
126        }
127    
128        public String toString()
129        {
130            StringBuffer stringbuffer = new StringBuffer();
131            stringbuffer.append("[");
132            if(attributes_.size() > 0)
133            {
134                Object obj = attributes_.elementAt(0);
135                String s;
136                if(obj == null)
137                    s = "(null)";
138                else
139                    s = obj.toString();
140                Object obj2 = values_.elementAt(0);
141                String s2;
142                if(obj2 == null)
143                    s2 = "(null)";
144                else
145                    s2 = obj2.toString();
146                stringbuffer.append(s + " = " + s2);
147            }
148            for(int i = 1; i < attributes_.size(); i++)
149            {
150                Object obj1 = attributes_.elementAt(i);
151                String s1;
152                if(obj1 == null)
153                    s1 = "(null)";
154                else
155                    s1 = obj1.toString();
156                Object obj3 = values_.elementAt(i);
157                String s3;
158                if(obj3 == null)
159                    s3 = "(null)";
160                else
161                    s3 = obj3.toString();
162                stringbuffer.append(", " + s1 + " = " + s3);
163            }
164    
165            stringbuffer.append("]");
166            return stringbuffer.toString();
167        }
168    
169        private Vector attributes_;
170        private Vector values_;
171        private Hashtable searchTable_;
172    }