001/** 002 * Copyright (C) 2007 - 2016, 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 */ 019package org.dllearner.utilities.statistics; 020 021import java.io.File; 022import java.io.Serializable; 023import java.util.ArrayList; 024import java.util.Arrays; 025import java.util.List; 026 027import org.dllearner.utilities.Files; 028 029public class TableColumn implements Serializable { 030 031 private static final long serialVersionUID = 1L; 032 private String header; 033 private List<String> entries = new ArrayList<>(); 034 035public TableColumn() { 036 super(); 037 038} 039 040public TableColumn(String header) { 041 super(); 042 this.header = header; 043} 044 045public TableColumn( String[] entries) { 046 this.entries = Arrays.asList(entries); 047} 048 049 050public TableColumn(String header, String[] entries) { 051 this(header); 052 this.entries = Arrays.asList(entries); 053} 054 055public TableColumn( List<String> entries) { 056 this.entries = entries; 057} 058 059public String getHeader() { 060 return header; 061} 062 063public void setHeader(String header) { 064 this.header = header; 065} 066 067/** 068 * entires should be in Latex, if the target is latex 069 * @param entry 070 */ 071public void addEntry(String entry){ 072 entries.add(entry); 073} 074 075public int getSize(){ 076 return entries.size(); 077} 078 079public String getEntry(int index){ 080 return entries.get(index); 081} 082 083public void serialize(File file){ 084 String content = header+System.getProperty("line.separator"); 085 for (String entry : entries) { 086 content += entry+System.getProperty("line.separator"); 087 } 088 Files.createFile(file, content); 089} 090 091public static TableColumn deSerialize(File f){ 092 TableColumn ret = null; 093 try{ 094 String[] c = Files.readFileAsArray(f); 095 ret = new TableColumn(); 096 boolean first = true; 097 for (String line : c) { 098 if(first){ 099 first = false; 100 ret.setHeader(line); 101 102 }else{ 103 ret.addEntry(line); 104 } 105 106 } 107 }catch (Exception e) { 108 e.printStackTrace(); 109 } 110 111 return ret; 112} 113 114}