1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.scripting.table;
12
13 import java.io.IOException;
14 import java.util.Iterator;
15
16 import uk.ac.starlink.table.ColumnInfo;
17 import uk.ac.starlink.table.ColumnPermutedStarTable;
18 import uk.ac.starlink.table.RowPermutedStarTable;
19 import uk.ac.starlink.table.StarTable;
20
21 /*** wrapper that hides a column in a table.
22 * @author Noel Winstanley nw@jb.man.ac.uk 07-Dec-2004
23 *
24 */
25 class RemoveColumnWrapperTable extends ColumnPermutedStarTable implements
26 ScriptStarTable {
27
28 /*** Construct a new RemoveColumnWrapperTable
29 * @param table
30 * @param arg1
31 */
32 public RemoveColumnWrapperTable(StarTable table, int colToRemove) {
33 super(table, calcArray(table.getColumnCount(),colToRemove));
34 }
35
36 /***
37 * @param columnCount
38 * @param colToRemove
39 * @return
40 */
41 private static int[] calcArray(int columnCount, int colToRemove) {
42 if (colToRemove > columnCount -1) {
43 throw new IllegalArgumentException("no column #" + colToRemove + "in table - only has " + columnCount );
44 }
45 int[] arr = new int[columnCount - 1];
46 for (int i = 0; i < colToRemove; i++) {
47 arr[i] =i;
48 }
49 for (int i = colToRemove + 1; i < columnCount; i++) {
50 arr[i-1] =i;
51 }
52 return arr;
53 }
54
55 protected final ExtraTableMethods methods = new ExtraTableMethodsImpl() {
56
57 protected StarTable getTable() {
58 return RemoveColumnWrapperTable.this;
59 }
60 };
61 public ScriptStarTable addColumn(ColumnInfo meta, Object colValue) {
62 return this.methods.addColumn(meta, colValue);
63 }
64 public MutableScriptStarTable asMutableTable() throws IOException {
65 return this.methods.asMutableTable();
66 }
67 public Iterator columnIterator(int col) throws IOException {
68 return this.methods.columnIterator(col);
69 }
70 public Iterator iterator() throws IOException {
71 return this.methods.iterator();
72 }
73 public ScriptStarTable removeColumn(int index) {
74 return this.methods.removeColumn(index);
75 }
76 }
77
78
79
80
81
82
83
84
85
86
87