/*
 * Copyright (c) 2009-2013 Topi Nieminen
 */
package fi.tnie.db.meta.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import fi.tnie.db.meta.ColumnMap;
import fi.tnie.db.meta.Table;

public class DefaultColumnMap
	extends DefaultElementMap<DefaultMutableColumn>
	implements ColumnMap, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6715516216855716542L;
	private Table table;
	private List<DefaultMutableColumn> columnList;
	
	public DefaultColumnMap(DefaultMutableTable table) {
		super(table.getEnvironment());
		this.table = table;
	}
	
	@Override
	public boolean add(DefaultMutableColumn c) {
		if (c.getTable() != this.table) {
			new IllegalArgumentException(
					"table of the column: " + c.getTable() + ", expected: " + this.table);
		}
		
		boolean added = super.add(c);
		
		if (added) {
			getColumnList().add(c);
		}
		
		return added;
	}

	List<DefaultMutableColumn> getColumnList() {
		if (columnList == null) {
			columnList = new ArrayList<DefaultMutableColumn>();			
		}

		return columnList;
	}
	
	public DefaultMutableColumn getColumn(int ordinal) {		
		return getColumnList().get(ordinal - 1);
	}
}

@@ -658,16 +658,21 @@
 Column c
+olumn
 ) %7B%0A%09%09if
@@ -674,16 +674,97 @@
 %0A%09%09if (c
+olumn == null) %7B%0A%09%09%09throw new NullPointerException(%22column%22);%0A%09%09%7D%0A%09%09%0A%09%09if (column
 .getTabl
@@ -849,16 +849,21 @@
 n: %22 + c
+olumn
 .getTabl
@@ -930,24 +930,29 @@
  super.add(c
+olumn
 );%0A%09%09%0A%09%09if (
@@ -984,16 +984,21 @@
 ().add(c
+olumn
 );%0A%09%09%7D%0A%09

Add npe precondition check