001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.sql.old; 020 021import java.util.Hashtable; 022import java.util.StringTokenizer; 023import java.util.Vector; 024 025public final class ZTuple 026{ 027 028 public ZTuple() 029 { 030 attributes_ = new Vector(); 031 values_ = new Vector(); 032 searchTable_ = new Hashtable(); 033 } 034 035 public ZTuple(String s) 036 { 037 this(); 038 for(StringTokenizer stringtokenizer = new StringTokenizer(s, ","); stringtokenizer.hasMoreTokens(); setAtt(stringtokenizer.nextToken().trim(), null)); 039 } 040 041 public void setRow(String s) 042 { 043 StringTokenizer stringtokenizer = new StringTokenizer(s, ","); 044 for(int i = 0; stringtokenizer.hasMoreTokens(); i++) 045 { 046 String s1 = stringtokenizer.nextToken().trim(); 047 try 048 { 049 Double double1 = new Double(s1); 050 setAtt(getAttName(i), double1); 051 } 052 catch(Exception exception) 053 { 054 setAtt(getAttName(i), s1); 055 } 056 } 057 058 } 059 060 public void setRow(Vector vector) 061 { 062 for(int i = 0; i < vector.size(); i++) 063 setAtt(getAttName(i), vector.elementAt(i)); 064 065 } 066 067 public void setAtt(String s, Object obj) 068 { 069 if(s != null) 070 { 071 boolean flag = searchTable_.containsKey(s); 072 if(flag) 073 { 074 int i = ((Integer)searchTable_.get(s)).intValue(); 075 values_.setElementAt(obj, i); 076 } else 077 { 078 int j = attributes_.size(); 079 attributes_.addElement(s); 080 values_.addElement(obj); 081 searchTable_.put(s, Integer.valueOf(j)); 082 } 083 } 084 } 085 086 public String getAttName(int i) 087 { 088 try 089 { 090 return (String)attributes_.elementAt(i); 091 } 092 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) 093 { 094 return null; 095 } 096 } 097 098 public int getAttIndex(String s) 099 { 100 if(s == null) 101 return -1; 102 Integer integer = (Integer)searchTable_.get(s); 103 if(integer != null) 104 return integer.intValue(); 105 return -1; 106 } 107 108 public Object getAttValue(int i) 109 { 110 try 111 { 112 return values_.elementAt(i); 113 } 114 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) 115 { 116 return null; 117 } 118 } 119 120 public Object getAttValue(String s) 121 { 122 boolean flag = false; 123 if(s != null) 124 flag = searchTable_.containsKey(s); 125 if(flag) 126 { 127 int i = ((Integer)searchTable_.get(s)).intValue(); 128 return values_.elementAt(i); 129 } 130 return null; 131 132 } 133 134 public boolean isAttribute(String s) 135 { 136 if(s != null) 137 return searchTable_.containsKey(s); 138 return false; 139 } 140 141 public int getNumAtt() 142 { 143 return values_.size(); 144 } 145 146 public String toString() 147 { 148 StringBuffer stringbuffer = new StringBuffer(); 149 stringbuffer.append("["); 150 if(attributes_.size() > 0) 151 { 152 Object obj = attributes_.elementAt(0); 153 String s; 154 if(obj == null) 155 s = "(null)"; 156 else 157 s = obj.toString(); 158 Object obj2 = values_.elementAt(0); 159 String s2; 160 if(obj2 == null) 161 s2 = "(null)"; 162 else 163 s2 = obj2.toString(); 164 stringbuffer.append(s + " = " + s2); 165 } 166 for(int i = 1; i < attributes_.size(); i++) 167 { 168 Object obj1 = attributes_.elementAt(i); 169 String s1; 170 if(obj1 == null) 171 s1 = "(null)"; 172 else 173 s1 = obj1.toString(); 174 Object obj3 = values_.elementAt(i); 175 String s3; 176 if(obj3 == null) 177 s3 = "(null)"; 178 else 179 s3 = obj3.toString(); 180 stringbuffer.append(", " + s1 + " = " + s3); 181 } 182 183 stringbuffer.append("]"); 184 return stringbuffer.toString(); 185 } 186 187 private Vector attributes_; 188 private Vector values_; 189 private Hashtable searchTable_; 190}