001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program 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 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.dialect; 019 020import java.util.Collection; 021import java.util.LinkedList; 022 023import net.sf.hajdbc.IdentifierNormalizer; 024 025/** 026 * Custom list implementation that normalizes the element entries as they are added. 027 * @author Paul Ferraro 028 */ 029public class IdentifierList extends LinkedList<String> 030{ 031 private static final long serialVersionUID = -3743137491103447812L; 032 033 private final IdentifierNormalizer normalizer; 034 035 public IdentifierList(IdentifierNormalizer normalizer) 036 { 037 this.normalizer = normalizer; 038 } 039 040 @Override 041 public boolean add(String id) 042 { 043 this.add(this.size(), id); 044 return true; 045 } 046 047 @Override 048 public void add(int index, String id) 049 { 050 super.add(index, this.normalizer.normalize(id)); 051 } 052 053 @Override 054 public void addFirst(String id) 055 { 056 this.add(0, id); 057 } 058 059 @Override 060 public void addLast(String id) 061 { 062 this.add(id); 063 } 064 065 @Override 066 public boolean addAll(Collection<? extends String> ids) 067 { 068 return this.addAll(this.size(), ids); 069 } 070 071 @Override 072 public boolean addAll(int index, Collection<? extends String> ids) 073 { 074 int i = index; 075 for (String id: ids) 076 { 077 this.add(i++, id); 078 } 079 return (i != index); 080 } 081}