001    /**
002     * Copyright (C) 2007-2011, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     *
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     */
019    
020    package org.dllearner.utilities.statistics;
021    
022    import java.io.File;
023    import java.io.Serializable;
024    import java.util.ArrayList;
025    import java.util.Arrays;
026    import java.util.List;
027    
028    import org.dllearner.utilities.Files;
029    
030    
031    public class TableColumn implements Serializable {
032    
033            private static final long serialVersionUID = 1l;
034            private String header;
035            private List<String> entries = new ArrayList<String>();
036    
037    public TableColumn() {
038            super();
039            
040    }       
041    
042    public TableColumn(String header) {
043            super();
044            this.header = header;
045    }
046    
047    
048    public TableColumn( String[] entries) {
049            this.entries = Arrays.asList(entries);
050    }
051    
052            
053    public TableColumn(String header, String[] entries) {
054            this(header);
055            this.entries = Arrays.asList(entries);
056    }
057    
058    public TableColumn( List<String> entries) {
059            this.entries = entries;
060    }
061    
062    
063    public String getHeader() {
064            return header;
065    }
066    
067    public void setHeader(String header) {
068            this.header = header;
069    }
070    
071    /**
072     * entires should be in Latex, if the target is latex
073     * @param entry
074     */
075    public void addEntry(String entry){
076            entries.add(entry);
077    }
078    
079    public int getSize(){
080            return entries.size();
081    }
082    
083    public String getEntry(int index){
084            return entries.get(index);
085    }
086    
087    public void serialize(File file){
088            String content = header+System.getProperty("line.separator");
089            for (String entry : entries) {
090                    content += entry+System.getProperty("line.separator");
091            }
092            Files.createFile(file, content);
093    }
094    
095    public static TableColumn deSerialize(File f){
096            TableColumn ret = null;
097            try{
098                    String[] c = Files.readFileAsArray(f);
099                    ret =  new TableColumn();
100                    boolean first = true;
101                    for (String line : c) {
102                            if(first){
103                                    first = false;
104                                    ret.setHeader(line);
105                                    
106                            }else{
107                                    ret.addEntry(line);
108                            }
109                            
110                    }
111            }catch (Exception e) {
112                     e.printStackTrace();
113            }
114            
115            return ret;
116    }
117    
118    
119    }