View Javadoc

1   /*$Id: RemoveColumnWrapperTable.java,v 1.2 2004/12/07 16:50:33 jdt Exp $
2    * Created on 07-Dec-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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  $Log: RemoveColumnWrapperTable.java,v $
81  Revision 1.2  2004/12/07 16:50:33  jdt
82  merges from scripting-nww-805
83  
84  Revision 1.1.2.1  2004/12/07 14:47:58  nw
85  got table manipulation working.
86   
87  */