001package gudusoft.gsqlparser.sqlcmds; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005 006/** 007 * List of SQL command definitions with optimized lookup by first token. 008 * This class was extracted from TSqlCmds inner class to support the modular 009 * vendor-specific command architecture. 010 * 011 * @since 3.1.0.9 012 */ 013public class TSqlCmdList extends ArrayList<TSqlCmd> { 014 private HashMap<Integer, Integer> startIndexMap; 015 016 public TSqlCmdList() { 017 super(); 018 startIndexMap = new HashMap<Integer, Integer>(); 019 } 020 021 @Override 022 public boolean add(TSqlCmd o) { 023 boolean ret = super.add(o); 024 025 // add first occurrence of a token to a hash that gives index of 026 // first entry that matches that first token 027 if (!startIndexMap.containsKey(o.token1)) { 028 startIndexMap.put(o.token1, size() - 1); 029 } 030 031 return ret; 032 } 033 034 int getStartIndex(int token1) { 035 Integer startIndex = startIndexMap.get(token1); 036 if (startIndex == null) 037 return -1; 038 else 039 return startIndex.intValue(); 040 } 041}